예제 #1
0
        public async Task CalculateCorrelationAsync()
        {
            Status = "calculating...";
            ChartSeries.Clear();

            var data = await Task.Run(Correlate);

            var series = new double[Math.Min(MaxSamplesInOutput, Impulse.SliceCount)];

            var skip = data.Length / series.Length - 1;

            if (skip < 0)
            {
                skip = 0;
            }

            for (int i = 0; i < series.Length; i++)
            {
                series[i] = data[i * (skip + 1)];
            }

            ChartSeries.Add(new StepLineSeries
            {
                PointGeometry   = null,
                StrokeThickness = 1,

                Title  = Path.GetFileName(Impulse.FileName),
                Values = new ChartValues <double>(series)
            });

            Status = $"{Path.GetFileName(Impulse.FileName)} done";
        }
예제 #2
0
        private void UpdateChart(DataSet dataSet)
        {
            if (dataSet.Enabled)
            {
                using (var _Db = _DbContextFactoryMethod.Invoke())
                {
                    var data = dataSet.QueryData(_Db, CurrentUsageHistorySettings.MinDate, CurrentUsageHistorySettings.MaxDate);
                    if (data.Count() > 0)
                    {
                        if (dataSet.Series == null)
                        {
                            var series = new LineSeries()
                            {
                                Title  = dataSet.Name,
                                Values = new ChartValues <DateModel>(data),
                            };
                            ChartSeries.Add(series);
                            dataSet.Series = series;
                        }
                        else
                        {
                            var currentValues = dataSet.Series.Values.Cast <DateModel>().ToList();

                            var toAddFront    = data.TakeWhile(x => x.DateTime < currentValues.First().DateTime);
                            var toRemoveFront = currentValues.TakeWhile(x => x.DateTime < data.First().DateTime);

                            var toAddBack    = data.Reverse().TakeWhile(x => x.DateTime > currentValues.Last().DateTime).Reverse();
                            var toRemoveBack = currentValues.Reverse <DateModel>().TakeWhile(x => x.DateTime > data.Last().DateTime).Reverse();

                            for (int i = 0; i < toRemoveFront.Count(); i++)
                            {
                                dataSet.Series.Values.RemoveAt(0);
                            }
                            for (int i = 0; i < toRemoveBack.Count(); i++)
                            {
                                dataSet.Series.Values.RemoveAt(dataSet.Series.Values.Count - 1);
                            }

                            foreach (var value in toAddFront.Reverse())
                            {
                                dataSet.Series.Values.Insert(0, value);
                            }
                            foreach (var value in toAddBack)
                            {
                                dataSet.Series.Values.Add(value);
                            }
                        }
                    }
                }
            }
            else
            {
                var series = dataSet.Series;
                if (series != null)
                {
                    ChartSeries.Remove(series);
                }
                dataSet.Series = null;
            }
        }
예제 #3
0
        public MainViewModel()
        {
            var startDateTime = DateTime.Now;

            ChartSeries.Add(GenerateSeries(startDateTime, 1, "analog bobo 1"));
            ChartSeries.Add(GenerateSeries(startDateTime, 1, "analog bobo 2"));

            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, 1, "discrete bobo 1"));
            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, -1, "discrete bobo3"));
            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, 1.5, "discrete bobo4"));
            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, -0.5, "discrete bobo5"));
            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, -0.3, "discrete bobo6"));
            DiscreteSeries.Add(GenerateDiscreteSeries(startDateTime, 0.3, "discrete bobo7"));

            Annotations.Add(new VerticalLineAnnotation()
            {
                X1     = startDateTime + TimeSpan.FromMilliseconds(60),
                Stroke = new SolidColorBrush(Colors.Aqua)
            });
        }