Пример #1
0
        public static ArgumentValue[] Calculate(double[] data, int count)
        {
            double minX = data.Min();
            double maxX = data.Max();
            double step = (maxX - minX) / count;

            minX = ((int)(minX / step)) * step;
            maxX = ((int)(maxX / step + 0.5)) * step;

            count = (int)((maxX - minX) / step);
            ArgumentValue[] res = new ArgumentValue[count + 1];
            for (int i = 0; i < count + 1; i++)
            {
                res[i] = new ArgumentValue()
                {
                    X = minX + i * step
                };
            }
            for (int i = 0; i < data.Length; i++)
            {
                if (double.IsNaN(data[i]))
                {
                    continue;
                }
                int index = (int)((data[i] - minX) / step + 0.5);
                res[index].Y += 1.0;
            }
            double del = 100.0 / data.Length;

            for (int i = 0; i < count; i++)
            {
                res[i].Y *= del;
            }
            return(res);
        }
Пример #2
0
        public static ResizeableArray <ArgumentValue> Calculate(ResizeableArray <object> data, string valueField, int count)
        {
            if (data.Count == 0)
            {
                return(null);
            }
            double minX = GetMin(data, valueField);
            double maxX = GetMax(data, valueField);
            double step = (maxX - minX) / count;

            minX = ((int)(minX / step)) * step;
            maxX = ((int)(maxX / step + 0.5)) * step;

            count = (int)((maxX - minX) / step);
            ResizeableArray <ArgumentValue> res = new ResizeableArray <ArgumentValue>(count + 1);

            for (int i = 0; i < count + 1; i++)
            {
                res[i] = new ArgumentValue()
                {
                    X = minX + i * step
                };
            }
            PropertyInfo pi = data[0].GetType().GetProperty(valueField, BindingFlags.Instance | BindingFlags.Public);

            foreach (var item in data)
            {
                double val = (double)pi.GetValue(item);
                if (double.IsNaN(val))
                {
                    continue;
                }
                int index = (int)((val - minX) / step + 0.5);
                if (index >= res.Count)
                {
                    continue;
                }
                res[index].Y += 1.0;
            }
            double del = 100.0 / data.Count;

            for (int i = 0; i < count; i++)
            {
                res[i].Y *= del;
            }
            return(res);
        }
Пример #3
0
        public static ResizeableArray <ArgumentValue> Calculate(ResizeableArray <TimeBaseValue> data, int count)
        {
            double minX = GetMin(data);
            double maxX = GetMax(data);

            if (double.IsNaN(minX) || double.IsNaN(maxX))
            {
                return(new ResizeableArray <ArgumentValue>());
            }
            double step = (maxX - minX) / count;

            minX = ((int)(minX / step)) * step;
            maxX = ((int)(maxX / step + 0.5)) * step;

            count = (int)((maxX - minX) / step);
            ResizeableArray <ArgumentValue> res = new ResizeableArray <ArgumentValue>(count + 1);

            for (int i = 0; i < count + 1; i++)
            {
                res[i] = new ArgumentValue()
                {
                    X = minX + i * step
                };
            }
            foreach (var item in data)
            {
                if (double.IsNaN(item.Value))
                {
                    continue;
                }
                int index = (int)((item.Value - minX) / step + 0.5);
                res[index].Y += 1.0;
            }
            double del = 100.0 / data.Count;

            for (int i = 0; i < count; i++)
            {
                res[i].Y *= del;
            }
            return(res);
        }