Exemplo n.º 1
0
 private void ResetZoomOnClick(object sender, RoutedEventArgs e)
 {
     if (_values.Count() > 0)
     {
         From = _values.First().StartPoint;
         To   = _values.Last().EndPoint;
     }
 }
Exemplo n.º 2
0
        private void AddSpeedMeasurement(SpeedMeasurement measurement)
        {
            CHART_VALUES.Add(measurement);
            if (TIMER.IsEnabled)
            {
                SetAxisLimits(measurement.DateTime);
            }

            if (DateTime.Now.Subtract(CHART_VALUES.Last().DateTime).TotalSeconds > 60)
            {
                CHART_VALUES.RemoveAt(0);
            }
        }
Exemplo n.º 3
0
        public async Task Inicializar()
        {
            if (Obra != null)
            {
                Tareas = new ObservableCollection <TareaDto>(await ApiProcessor.GetApi <TareaDto[]>($"Tarea/GetByObra/{Obra.Id}"));
                var now = DateTime.Now;
                _values = new ChartValues <GanttPoint>();
                if (Tareas.Count > 0)
                {
                    var labels = new List <string>();
                    foreach (var item in Tareas)
                    {
                        labels.Add($"{item.NumeroOrden}: {item.DescripcionTarea.Descripcion}");
                        if (_values.Count > 0)
                        {
                            var ultimo = _values.Last();
                            if (!item.Precede)
                            {
                                _values.Add(new GanttPoint(ultimo.StartPoint, ultimo.StartPoint + item.TiempoEmpleado.Ticks));
                            }
                            else
                            {
                                _values.Add(new GanttPoint(ultimo.EndPoint, ultimo.EndPoint + item.TiempoEmpleado.Ticks));
                            }
                        }
                        else
                        {
                            _values.Add(new GanttPoint(new TimeSpan(0, 0, 0).Ticks, item.TiempoEmpleado.Ticks));
                        }
                    }
                    Labels = labels.ToArray();
                    Series = new SeriesCollection
                    {
                        new RowSeries
                        {
                            Values     = _values,
                            DataLabels = true
                        }
                    };
                }

                Formatter = value => new DateTime((long)value).ToString("H:mm");

                ResetZoomOnClick(null, null);
            }
        }
Exemplo n.º 4
0
        public ChartValues <ObservablePoint> Grafik(double dt)
        {
            ChartValues <ObservablePoint> list = new ChartValues <ObservablePoint>();
            double y;
            double x;

            for (double i = 0; i <= Time(); i = i + dt)
            {
                y = Round(Speed * i * Sin(Angle * PI / 180) - 9.81 * Pow(i, 2) / 2, 1);
                x = Round(Speed * i * Cos(Angle * PI / 180), 1);
                list.Add(new ObservablePoint(x, y));
            }
            if (list.Last().Y != 0)
            {
                x = Round(Speed * Time() * Cos(Angle * PI / 180), 1);
                list.Add(new ObservablePoint(x, 0));
            }
            return(list);
        }
Exemplo n.º 5
0
 public static void Add()
 {
     Values.Add(Values.Last() + 10 + _rnd.Next(-5, 3));
 }
        public RealTimeTrending()
        {
            InitializeComponent();

            var dayConfig = Mappers.Xy <DateTimePoint>()
                            .X(dayModel => (double)dayModel.DateTime.Ticks / TimeSpan.FromMilliseconds(1000).Ticks)
                            .Y(dayModel => dayModel.Value);

            _connection.Connect("5XQ6Y6JJKEOQ7JRU");
            _args = new FetchArgs {
                DefaultCurrency = "RSD", Symbol = "MSFT", RefreshRate = 5
            };
            LastHourSeries = new SeriesCollection
            {
                new LineSeries
                {
                    Configuration = dayConfig,
                    AreaLimit     = -10,
                    //Values = GetData(),
                    Values = new ChartValues <DateTimePoint>
                    {
                        new DateTimePoint {
                            Value = 1, DateTime = DateTime.Now
                        },
                        new DateTimePoint {
                            Value = 5, DateTime = DateTime.Now.AddSeconds(1)
                        },
                        new DateTimePoint {
                            Value = 3, DateTime = DateTime.Now.AddSeconds(2)
                        },
                        new DateTimePoint {
                            Value = 4, DateTime = DateTime.Now.AddSeconds(3)
                        },
                        new DateTimePoint {
                            Value = 7, DateTime = DateTime.Now.AddSeconds(4)
                        },
                        new DateTimePoint {
                            Value = 2, DateTime = DateTime.Now.AddSeconds(5)
                        },
                        new DateTimePoint {
                            Value = 11, DateTime = DateTime.Now.AddSeconds(6)
                        },
                        new DateTimePoint {
                            Value = 6, DateTime = DateTime.Now.AddSeconds(7)
                        },
                        new DateTimePoint {
                            Value = 9, DateTime = DateTime.Now.AddSeconds(8)
                        },
                        new DateTimePoint {
                            Value = 1, DateTime = DateTime.Now.AddSeconds(9)
                        },
                        new DateTimePoint {
                            Value = 3, DateTime = DateTime.Now.AddSeconds(10)
                        },
                        new DateTimePoint {
                            Value = 9, DateTime = DateTime.Now.AddSeconds(11)
                        },
                    }
                },
            };
            Step        = 0;
            LastLecture = 0;

            //timer = new DispatcherTimer();
            //timer.Tick += new EventHandler(SetValues);
            //timer.Interval = new TimeSpan(0, 0, _args.RefreshRate);
            //timer.Start();

            Task.Run(() =>
            {
                ChartValues <DateTimePoint> values = new ChartValues <DateTimePoint>();
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
                while (true)
                {
                    Thread.Sleep(4000);
                    _backgroindWork = Task.Factory.StartNew(() =>
                    {
                        values = GetData();
                    }, TaskCreationOptions.LongRunning);

                    //Dispatcher.Invoke(() => {
                    //    if (values.Count != 0)
                    //    {
                    //        LastHourSeries[0].Values = values;
                    //        Step = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value -
                    //                    ((ChartValues<DateModel>)LastHourSeries[0].Values).ElementAt(
                    //                        ((ChartValues<DateModel>)LastHourSeries[0].Values).Count - 2).Value;
                    //        if (Step > 0)
                    //            ForegroundColor = Brushes.Green;
                    //        else if (Step < 0)
                    //            ForegroundColor = Brushes.Red;
                    //        else
                    //            ForegroundColor = Brushes.Black;
                    //        LastLecture = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value;
                    //    }
                    //    MessageBox.Show("Refresh", "Refrash");
                    //});

                    _backgroindWork.ContinueWith(x =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            using (Dispatcher.DisableProcessing())
                            {
                                LastHourSeries[0].Values.Add(values.Last());
                                LastHourSeries[0].Values.RemoveAt(0);
                                //LastHourSeries[0].Values = values;
                            }
                        }, DispatcherPriority.ContextIdle);
                        Step = ((ChartValues <DateTimePoint>)LastHourSeries[0].Values).Last().Value -
                               ((ChartValues <DateTimePoint>)LastHourSeries[0].Values).ElementAt(
                            ((ChartValues <DateTimePoint>)LastHourSeries[0].Values).Count - 2).Value;
                        if (Step > 0)
                        {
                            ForegroundColor = Brushes.Green;
                        }
                        else if (Step < 0)
                        {
                            ForegroundColor = Brushes.Red;
                        }
                        else
                        {
                            ForegroundColor = Brushes.Black;
                        }
                        LastLecture = ((ChartValues <DateTimePoint>)LastHourSeries[0].Values).Last().Value;


                        //MessageBox.Show("Refresh", "Refrash");
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }



                //while (true)
                //{
                //    Thread.Sleep(5000);
                //    Dispatcher.BeginInvoke(new Action(()=> {
                //        values = GetData();
                //    }), DispatcherPriority.Background);

                //    Application.Current.Dispatcher.Invoke(() => {
                //        if(values.Count != 0)
                //        {
                //            LastHourSeries[0].Values = values;
                //            Step = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value -
                //                        ((ChartValues<DateModel>)LastHourSeries[0].Values).ElementAt(
                //                            ((ChartValues<DateModel>)LastHourSeries[0].Values).Count - 2).Value;
                //            if (Step > 0)
                //                ForegroundColor = Brushes.Green;
                //            else if (Step < 0)
                //                ForegroundColor = Brushes.Red;
                //            else
                //                ForegroundColor = Brushes.Black;
                //            LastLecture = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value;
                //        }

                //    });

                //}
            });

            //Task.Run(() =>
            //{
            //    var r = new Random();
            //    while (true)
            //    {
            //        Thread.Sleep(5000);
            //        //var values = GetData();
            //        //foreach (var temp in GetData())
            //        //{
            //        //    Console.WriteLine(temp.Value + "     " + temp.DateTime.ToLongTimeString());
            //        //}

            //        //foreach( var temp in values)
            //        //{
            //        //    Thread.Sleep(1000);
            //        //    _trend = temp.Value;
            //        //    Application.Current.Dispatcher.Invoke(() =>
            //        //    {
            //        //        if (_trend > ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value)
            //        //            ForegroundColor = Brushes.Green;
            //        //        else if (_trend < ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value)
            //        //            ForegroundColor = Brushes.Red;
            //        //        else
            //        //            ForegroundColor = Brushes.Black;
            //        //        LastHourSeries[0].Values.Add(temp);
            //        //        LastHourSeries[0].Values.RemoveAt(0);
            //        //        SetLecture();
            //        //    });
            //        //}
            //        //Thread.Sleep(1000);
            //        _trend += (r.NextDouble() > 0.3 ? 1 : -1) * r.Next(0, 5);

            //        Application.Current.Dispatcher.Invoke(() =>
            //        {


            //            //LastHourSeries[0].Values.Add(new DateModel { Value = _trend, DateTime = DateTime.Now });
            //            //LastHourSeries[0].Values.RemoveAt(0);
            //            LastHourSeries[0].Values = new ChartValues<DateModel>
            //            {
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 1 : -1) * r.Next(0, 5), DateTime = DateTime.Now},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 2 : -2) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(1)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 3 : -3) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(2)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 4 : -4) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(3)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 5 : -5) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(4)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 6 : -6) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(5)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 7 : -7) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(6)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 8 : -8) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(7)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 9 : -9) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(8)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 10 : -10) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(9)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 11 : -11) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(10)},
            //            new DateModel{Value = (r.NextDouble() > 0.3 ? 12 : -12) * r.Next(0, 5), DateTime = DateTime.Now.AddSeconds(11)},
            //            };
            //            Step = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value -
            //                        ((ChartValues<DateModel>)LastHourSeries[0].Values).ElementAt(
            //                            ((ChartValues<DateModel>)LastHourSeries[0].Values).Count - 2).Value;
            //            if (_trend > 0)
            //                ForegroundColor = Brushes.Green;
            //            else if (_trend < 0)
            //                ForegroundColor = Brushes.Red;
            //            else
            //                ForegroundColor = Brushes.Black;
            //            LastLecture = ((ChartValues<DateModel>)LastHourSeries[0].Values).Last().Value;
            //            //SetLecture();
            //        });
            //    }
            //});

            Formatter = value => new DateTime((long)(value * TimeSpan.FromMilliseconds(1000).Ticks)).ToString("T");
            //Formatter = value => new DateTime((long)value).ToString("T");
            DataContext = this;
        }
Exemplo n.º 7
0
 private void button1_Click(object sender, EventArgs e)
 {
     cartesianChart1.AxisX[0].MinValue = _values.First().StartPoint;
     cartesianChart1.AxisX[0].MaxValue = _values.Last().EndPoint;
 }
Exemplo n.º 8
0
        public static void UpdateTradesChart <T>(
            IEnumerable <ITrade> tradesUpdate,
            Func <ITrade, T> create,
            int tradesChartDisplayCount,
            ILoggerFacade logger,
            ref ChartValues <T> tradesChart) where T : TradeBase, new()
        {
            var sw = new Stopwatch();

            sw.Start();
            logger.Log($"Start UpdateTradesChart<{typeof(T).Name}>", Category.Info, Priority.Low);

            // Get the latest available trade - the last trade on the trade chart.
            var seed = tradesChart.Last();

            // Extract new trades where time and id is greater than latest available trade.
            // Order by oldest to newest (as it will appear in chart).
            var newTrades = (from t in tradesUpdate
                             where t.Time.ToLocalTime() > seed.Time && t.Id > seed.Id
                             orderby t.Time, t.Id
                             select create(t)).ToList();

            var newTradesCount   = newTrades.Count;
            var tradesChartCount = tradesChart.Count;

            if (tradesChartCount >= tradesChartDisplayCount)
            {
                // For each additional new trade remove the oldest then add the new trade
                for (int i = 0; i < newTradesCount; i++)
                {
                    tradesChart.RemoveAt(0);
                    tradesChart.Add(newTrades[i]);
                }
            }
            else
            {
                // Get the difference between the number of trades the chart can take and the number it currently holds.
                var chartDisplayTopUpTradesCount = tradesChartDisplayCount - tradesChartCount;

                if (newTradesCount > chartDisplayTopUpTradesCount)
                {
                    // There are more new trades than the chart can take.

                    if (chartDisplayTopUpTradesCount > 0)
                    {
                        // The top up trades can simply be added to the chart as it will take it to the total the chart can hold
                        var chartDisplayTopUpTrades = newTrades.Take(chartDisplayTopUpTradesCount).ToList();
                        tradesChart.AddRange(chartDisplayTopUpTrades);
                    }

                    for (int i = chartDisplayTopUpTradesCount; i < newTradesCount; i++)
                    {
                        // For each additional new trade remove the oldest then add the new trade
                        tradesChart.RemoveAt(0);
                        tradesChart.Add(newTrades[i]);
                    }
                }
                else
                {
                    // Simply add new trades to current list as it wont be more than the total the chart can take.
                    tradesChart.AddRange(newTrades);
                }
            }

            sw.Stop();
            logger.Log($"End UpdateTradesChart<{typeof(T).Name}> {sw.Elapsed}", Category.Info, Priority.Low);
        }