Exemplo n.º 1
0
        public Distribution(IEnumerable <double> values, int binLength = 1)
        {
            if (binLength <= 0)
            {
                throw new ArgumentException();
            }

            Values    = values.Select(x => Math.Round(x, 5)).ToList();
            Average   = Values.Average();
            Mode      = Values.Mode();
            BinLength = binLength;

            var max = (int)Math.Ceiling(Values.Max());

            if (max == 0)
            {
                max = binLength;
            }
            else
            {
                binLength = binLength > max ? max : binLength;
            }

            var bins = Enumerable.Range(0, (int)Math.Ceiling(max / (double)binLength) + 1)
                       .Select(x => x * binLength)
                       .ToDictionary(x => x, _ => new List <double>());

            foreach (var value in Values)
            {
                var key = bins.Keys.ElementAt((int)Math.Floor(value / binLength));
                bins[key].Add(value);
            }

            Bins = bins;
        }
Exemplo n.º 2
0
        protected override void OnRender(DrawingContext dc)
        {
            if (Values == null || Values.Length == 0)
            {
                return;
            }
            double max     = Values.Max();
            var    pen     = new Pen(Stroke, StrokeThickness);
            var    barSize = ActualWidth / Values.Length;

            for (int i = 0; i < Values.Length; i++)
            {
                dc.DrawRectangle(
                    Fill,
                    pen,
                    new Rect(
                        new Point(i * barSize, ActualHeight - Values[i] * ActualHeight / max),
                        new Point((i + 1) * barSize, ActualHeight))
                    );
            }
            if (ShowAverage)
            {
                var avg = ActualHeight - Values.Average() * ActualHeight / max;
                dc.DrawLine(pen, new Point(0, avg),
                            new Point(ActualWidth, avg));
            }
        }
Exemplo n.º 3
0
 private void TestInternal()
 {
     Console.WriteLine(Counter);
     if (Counter < 100)
     {
         this.TestFunction((long val) => {
             Values[Counter++] = val;
             TestInternal();
         });
     }
     else
     {
         long   min  = Values.Min();
         long   max  = Values.Max();
         double avg  = Values.Average();
         var    list = Values.ToList();
         list.Sort();
         long med = list[50];
         Callback(new object[] {
             min, max, (long)avg, med, Name
         });
     }
 }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Values != null && Values.Count > 1)
            {
                while (Values.Count > MaxValues)
                {
                    Values.RemoveAt(0);
                }

                double horizontalSpacing = ActualWidth / (Values.Count - 1);

                if (ZeroLinePen != null)
                {
                    drawingContext.DrawLine(ZeroLinePen, new Point(0, TranslateValue(0)), new Point(ActualWidth, TranslateValue(0)));
                }

                if (AverageLinePen != null)
                {
                    drawingContext.DrawLine(AverageLinePen, new Point(0, TranslateValue(Values.Average())), new Point(ActualWidth, TranslateValue(Values.Average())));
                }

                for (int i = 1; i < Values.Count; ++i)
                {
                    drawingContext.DrawLine(LinePen,
                                            new Point((i - 1) * horizontalSpacing, TranslateValue(Values[i - 1])),
                                            new Point((i - 0) * horizontalSpacing, TranslateValue(Values[i - 0])));
                }
            }
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            var average = Values.Average();

            return($"{string.Format("{0,-20}", Operation.ToString())}:Time = {TimeSpent}ms, Count = {Values.Count}, Average = {Math.Round(average, 2)}ms");
        }