Beispiel #1
0
        private void BuildHistogram()
        {
            var max     = Math.Ceiling(ChartValues.Max(p => p.TotDouble));
            var min     = Math.Floor(ChartValues.Min(p => p.TotDouble));
            var binSize = max / 100;

            var histValues = new Dictionary <string, int>();

            for (var i = min; i < max; i += binSize)
            {
                histValues.Add(i + " - " + (i + binSize), ChartValues.Count(v => v.TotDouble > i && v.TotDouble <= i + binSize));
            }

            sizeChart.Series.Clear();
            sizeChart.AxisY.Clear();
            sizeChart.Series = new SeriesCollection
            {
                new RowSeries
                {
                    Values = new ChartValues <int>(histValues.Values)
                }
            };
            sizeChart.AxisY.Add(new Axis
            {
                Labels = histValues.Keys.ToList()
            });
        }
Beispiel #2
0
        private void CalculateRegression()
        {
            var x = Vector.Create(ChartValues.Select(v => v.NDouble).ToArray());
            var y = Vector.Create(ChartValues.Select(v => v.TotDouble).ToArray());

            _regression = new SimpleRegressionModel(y, x);
            _regression.Fit();

            UpperValues.Clear();
            LowerValues.Clear();
            RegressionValues.Clear();
            NToNValues.Clear();
            XAxis.Clear();
            YAxis.Clear();

            var max = ChartValues.Max(p => p.NDouble);

            XAxis.Add(new ObservablePoint(0, 0));
            XAxis.Add(new ObservablePoint(0, max));
            YAxis.Add(new ObservablePoint(0, 0));
            YAxis.Add(new ObservablePoint(max, 0));



            NToNValues.Add(new ObservablePoint(0, 0));
            NToNValues.Add(new ObservablePoint(max, max));

            var ci = _regression.GetPredictionInterval(0, .99);

            UpperValues.Add(new ObservablePoint(0, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(0, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(0, ci.Center));

            ci = _regression.GetPredictionInterval(max, .99);
            UpperValues.Add(new ObservablePoint(max, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(max, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(max, ci.Center));

            var above = 0.0;
            var below = 0.0;

            foreach (var point in ChartValues)
            {
                var interval = _regression.GetPredictionInterval(point.NDouble, .99);
                if (point.TotDouble <= interval.UpperBound && point.TotDouble > interval.Center)
                {
                    above++;
                }
                else if (point.TotDouble <= interval.Center && point.TotDouble >= interval.LowerBound)
                {
                    below++;
                }
            }
            Console.WriteLine("Above Center: " + above / ChartValues.Count);
            Console.WriteLine("Below Center: " + below / ChartValues.Count);
        }
Beispiel #3
0
        private async void AddButton_Click(object sender, EventArgs e)
        {
            addButton.Enabled = false;
            var data = await Task <List <XY> > .Factory.StartNew(() => Crypto.CompareNWithTotient(_size, _size, 100, false));

            var newMax = data.Max(p => p.NDouble) > ChartValues.Max(p => p.NDouble);

            ChartValues.AddRange(data);
            CalculateRegression();

            addButton.Enabled = true;
        }
Beispiel #4
0
 private void AddPoint(DateTime now, int connCount, long sendBytes, long recvBytes)
 {
     sendValues.Add(new MeasureModel
     {
         DateTime = now,
         Value    = sendBytes
     });
     recvValues.Add(new MeasureModel
     {
         DateTime = now,
         Value    = recvBytes
     });
     connValues.Add(new MeasureModel
     {
         DateTime = now,
         Value    = connCount
     });
     SetAxisLimits(now);
     if (sendValues.Count > displayTimeSpan)
     {
         sendValues.RemoveAt(0);
         recvValues.RemoveAt(0);
         connValues.RemoveAt(0);
     }
     if (sendValues.Max(p => p.Value) < defaultMax && recvValues.Max(p => p.Value) < defaultMax)
     {
         chartFlow.AxisY[0].MaxValue       = defaultMax;
         chartFlow.AxisY[0].Separator.Step = defaultStep;
     }
     else
     {
         chartFlow.AxisY[0].MaxValue       = double.NaN;
         chartFlow.AxisY[0].Separator.Step = double.NaN;
     }
     if (connValues.Max(p => p.Value) < defaultMax)
     {
         chartFlow.AxisY[1].MaxValue       = defaultMax;
         chartFlow.AxisY[1].Separator.Step = defaultStep;
     }
     else
     {
         chartFlow.AxisY[1].MaxValue       = double.NaN;
         chartFlow.AxisY[1].Separator.Step = double.NaN;
     }
 }
        public GoldGraph()
        {
            InitializeComponent();

            Timer.Interval = TimeSpan.FromMinutes(2);
            Timer.Tick    += TimerTick;

            Values = new ChartValues <double> {
                0, 0.5, 2, 0.8, 4, 3.6, 1, -2, 2, 1.4, -2.3, -4, -6, -7.5, -10.8
            };

            GoldDifference.Labels = new[] { $"{Values.Min()}", "0", $"{Values.Max()}" };

            Minutes.Labels = new[] { "0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36", "38", "40", "42", "44", "46", "48", "50" };

            DataContext = this;

            //Timer.Start();
            //TimerTick(null, null);
        }
Beispiel #6
0
        public void DrawingLiveChart(TargetMQC target, List <chartdatabyDate> chartdatabyDates, List <chartdatabyDate> chartdataDefect, ref CartesianChart chart)
        {
            //xu ly data de chon cac thong so cua chart
            double YmaxValue = 0;
            double YminValue = 0;
            Dictionary <string, double> ValueConvert       = new Dictionary <string, double>();
            Dictionary <string, double> ValueConvertDefect = new Dictionary <string, double>();

            if (chartdatabyDates != null && chartdatabyDates.Count > 0)
            {
                chart.Series.Clear();
                chart.AxisX.Clear();
                chart.AxisY.Clear();
                chart.Controls.Clear();
                //      chart.Base.Foreground = new SolidColorBrush(Color.FromRgb(66, 66, 66));

                //  chart.Background = System.Windows.Media.Brushes.BlanchedAlmond;

                ValueConvert       = DicChangeTime(chartdatabyDates);
                ValueConvertDefect = DicChangeTime(chartdataDefect);
                string[] TimeChanged         = ValueConvert.Keys.ToArray();
                double[] OutputChanged       = ValueConvert.Values.ToArray();
                double[] OutputChangedDefect = ValueConvertDefect.Values.ToArray();
                YmaxValue = OutputChanged.Max();

                YminValue = OutputChanged.Min();
                ChartValues <double> values          = new ChartValues <double>();
                ChartValues <double> valuesTarget    = new ChartValues <double>();
                ChartValues <double> valuesDefect    = new ChartValues <double>();
                ChartValues <double> PercentQuantity = new ChartValues <double>();
                ChartValues <double> Defecttarget    = new ChartValues <double>();
                double per = 0;
                for (int i = 0; i < OutputChanged.Count(); i++)
                {
                    values.Add(OutputChanged[i]);

                    //  valuesTarget.Add(100);
                    if ((OutputChangedDefect[i] + OutputChanged[i]) != 0)
                    {
                        valuesDefect.Add(OutputChangedDefect[i] / (OutputChangedDefect[i] + OutputChanged[i]));
                    }
                    else
                    {
                        valuesDefect.Add(0);
                    }
                    valuesTarget.Add(OutputChangedDefect[i]);
                    if (target.TargetOutput > 0)
                    {
                        per += OutputChanged[i] / target.TargetOutput;
                        PercentQuantity.Add(per);
                        Defecttarget.Add(target.TargetDefect / target.TargetOutput);
                    }
                }
                YmaxValue = values.Max();
                // YmaxValue = (values.Max() > valuesTarget.Max())? values.Max() : valuesTarget.Max();
                List <String> lables = new List <string>();
                for (int i = 0; i < TimeChanged.Count(); i++)
                {
                    lables.Add(TimeChanged[i]);
                }
                chart.Series = new SeriesCollection
                {
                    new ColumnSeries
                    {
                        Title      = "Output Quantity",
                        Values     = values,
                        DataLabels = true,
                        Fill       = System.Windows.Media.Brushes.Green,
                        ScalesYAt  = 0,
                        FontSize   = 15
                    }
                };
                chart.Series.Add(
                    new ColumnSeries
                {
                    Title      = "Defect Quantity",
                    Values     = valuesTarget,
                    DataLabels = true,
                    Fill       = System.Windows.Media.Brushes.Red,
                    ScalesYAt  = 0,
                    FontSize   = 15
                }
                    );
                chart.Series.Add(
                    new LineSeries
                {
                    Title           = "Defect Rate (%)",
                    Values          = valuesDefect,
                    DataLabels      = true,
                    Foreground      = System.Windows.Media.Brushes.Orange,
                    PointForeground = System.Windows.Media.Brushes.Red,
                    ScalesYAt       = 1,
                    FontSize        = 15
                });
                chart.Series.Add(
                    new LineSeries
                {
                    Title           = "Target Quantity(%)",
                    Values          = PercentQuantity,
                    DataLabels      = true,
                    Foreground      = System.Windows.Media.Brushes.BlueViolet,
                    PointForeground = System.Windows.Media.Brushes.BlueViolet,
                    ScalesYAt       = 1,
                    FontSize        = 15
                }
                    );
                chart.Series.Add(
                    new LineSeries
                {
                    Title           = "Defect target(%)",
                    Values          = Defecttarget,
                    DataLabels      = true,
                    Foreground      = System.Windows.Media.Brushes.DarkKhaki,
                    PointForeground = System.Windows.Media.Brushes.DarkKhaki,
                    ScalesYAt       = 1,
                    FontSize        = 15
                }
                    );
                chart.DefaultLegend.Margin   = new Thickness(30);
                chart.DefaultLegend.FontSize = 20;
                chart.LegendLocation         = LegendLocation.Top;


                //x axis labels
                chart.AxisX.Add(new Axis
                {
                    Title    = "Hours",
                    Labels   = lables,
                    Unit     = 1,
                    FontSize = 15,

                    FontFamily = new System.Windows.Media.FontFamily("Times New Roman"),
                    Foreground = System.Windows.Media.Brushes.Black,
                    Separator  = new LiveCharts.Wpf.Separator
                    {
                        Step      = 1,
                        IsEnabled = false //disable it to make it invisible.
                    },
                    LabelsRotation = 0,
                });


                //y axis label
                chart.AxisY.Add(new Axis
                {
                    Title          = "Quantity (pcs)",
                    LabelFormatter = value => value.ToString("N0"),
                    FontSize       = 15,

                    FontFamily = new System.Windows.Media.FontFamily("Times New Roman"),

                    Foreground = System.Windows.Media.Brushes.Black,
                    MaxValue   = YmaxValue * 1.2,
                    MinValue   = 0,
                    Position   = AxisPosition.LeftBottom
                });

                chart.AxisY.Add(new Axis
                {
                    Title          = "percent (%)",
                    LabelFormatter = value => value.ToString("P1"),
                    FontSize       = 15,
                    FontFamily     = new System.Windows.Media.FontFamily("Times New Roman"),
                    Foreground     = System.Windows.Media.Brushes.Black,
                    MaxValue       = 1,
                    MinValue       = 0,
                    Position       = AxisPosition.RightTop
                });
                // chart.Zoom = ZoomingOptions.Xy;
            }
        }