Пример #1
0
        private HistogramData GetValleysHistogram(string columnId)
        {
            var    histogram       = new HistogramData();
            var    histogramFields = new Dictionary <double, List <int> >();
            double lastValue       = 0;
            bool   increasing      = true;

            foreach (var field in Data.Fields)
            {
                if (field.Invalid)
                {
                    continue;
                }

                double?value = field.GetValue(columnId);
                if (!value.HasValue)
                {
                    continue;
                }

                if (value < lastValue)
                {
                    increasing = false;
                }
                else if (value > lastValue)
                {
                    if (!increasing)
                    {
                        histogram.Add(lastValue);

                        List <int> fields;
                        histogramFields.TryGetValue(lastValue, out fields);
                        if (fields == null)
                        {
                            fields = new List <int>();
                        }
                        fields.Add(field.FieldNumber);
                        histogramFields[lastValue] = fields;
                    }
                    increasing = true;
                }
                lastValue = value.Value;
            }
            return(histogram);
        }
Пример #2
0
        private int DetectThreshold(string columnId, out HistogramData histogram)
        {
            histogram = GetValleysHistogram(columnId);
            PrintHistogram(columnId + " Valleys Histogram", histogram);

            for (int i = 1; i < 256; i++)
            {
                int current  = histogram[i];
                int previous = histogram[i - 1];
                if (current < previous)
                {
                    i--;
                    Log(columnId + " threshold detected: " + i.ToString());
                    return(i);
                }
            }

            return(0);
        }
Пример #3
0
        private void PrintHistogram(string title, HistogramData histogram)
        {
            Log("");
            Log(title);
            int firstI = -1;

            for (int i = 0; i < 100; i++)
            {
                int count = histogram[i];
                if ((firstI == -1) && (count > 0))
                {
                    firstI = i;
                }
                if (i > firstI + 20)
                {
                    break;
                }
                int percentage = 100 * count / histogram.MaximumValue;
                Log(i.ToString().PadLeft(3) + ", " + count.ToString().PadLeft(histogram.MaximumValue.ToString().Length) + " : " + "".PadRight(percentage, '*'));
            }
        }
Пример #4
0
        private HistogramData GetValuesHistogram(string columnId)
        {
            var histogram = new HistogramData();

            foreach (var field in Data.Fields)
            {
                if (field.Invalid)
                {
                    continue;
                }

                double?value = field.GetValue(columnId);
                if (!value.HasValue)
                {
                    continue;
                }

                histogram.Add(value.Value);
            }
            return(histogram);
        }