private void RemoveOldPrices(ChartValues <OrderBookPriceLevel> cv, List <OrderBookPriceLevel> pl)
        {
            var removePoints = cv.Where(v => !pl.Any(p => p.Price == v.Price)).ToList();

            foreach (var point in removePoints)
            {
                cv.Remove(point);
            }
        }
예제 #2
0
 public void RemoveSearch()
 {
     if (selectedPhonePos.Count != 0)
     {
         String          cleanSelectedMAC = selectedMAC.Replace(":", "");
         DatiDispositivo p = selectedPhonePos.First <DatiDispositivo>();
         selectedPhonePos.Remove(p);
         if (Pacchetto.CntrlGlobal(selectedMAC))
         {
             //hiddenPhone
             hiddenPhonePos.Add(p);
         }
         else
         {
             //visiblePhone
             phonePos.Add(p);
         }
     }
 }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dataList">Name, Addr, Value</param>
 public void Update(List <SectionData> dataList)
 {
     foreach (var data in dataList)
     {
         LineSeries series = (LineSeries)Series_Collection.Where((x) => (uint)((LineSeries)x).Tag == data.Addr).SingleOrDefault();
         if (series == null)
         {
             series = new LineSeries
             {
                 Name            = data.Name.Replace(".", "_"),
                 Tag             = data.Addr,
                 Values          = new ChartValues <ObservablePoint>(),
                 Stroke          = GetNextColor(),
                 Fill            = Brushes.Transparent,
                 StrokeThickness = .5,
                 PointGeometry   = null,
             };
             Series_Collection.Add(series);
         }
         ChartValues <ObservablePoint> Values = (ChartValues <ObservablePoint>)series.Values;
         if (Values.Count > MAX_COUNT - 1)
         {
             Values.Remove(Values.First());
         }
         else if (Values.Count < MAX_COUNT)
         {
             Values.Add(new ObservablePoint(
                            (DateTime.Now - LaunchTime).TotalSeconds,
                            data.Value
                            ));
         }
     }
     if (dataList.Count < Series_Collection.Count)
     {
         var UnfoundSeries = Series_Collection.Where((series) => !dataList.Any((data) => data.Addr == (uint)((LineSeries)series).Tag));
         foreach (var item in UnfoundSeries)
         {
             Series_Collection.Remove(item);
         }
     }
 }
예제 #4
0
        public void SearchMac(string selected)
        {
            String cleanSelectedMAC = selected.Replace(":", "");

            if (selected != "")
            {
                selectedMAC = selected;

                if (Pacchetto.CntrlGlobal(selectedMAC))
                {
                    //hiddenPhone
                    foreach (DatiDispositivo p in scatterChart.Series[2].Values)
                    {
                        if (p.MAC_Address.CompareTo(cleanSelectedMAC) == 0)
                        {
                            hiddenPhonePos.Remove(p);
                            selectedPhonePos.Add(p);
                            break;
                        }
                    }
                }
                else
                {
                    //visiblePhone
                    foreach (DatiDispositivo p in scatterChart.Series[1].Values)
                    {
                        if (p.MAC_Address.CompareTo(cleanSelectedMAC) == 0)
                        {
                            phonePos.Remove(p);
                            selectedPhonePos.Add(p);
                            break;
                        }
                    }
                }
            }
        }
예제 #5
0
        public void ChangeCustomLine(string title, ChartValues <ObservableValue> points)
        {
            var rand = new Random();

            SeriesCollection seriesCollection = Graphics;

            LineSeries Line = (LineSeries)seriesCollection.Where(x => x.Title == title).FirstOrDefault();

            ChartValues <ObservableValue> line = (ChartValues <ObservableValue>)Line.Values;

            try
            {
                //удаленные точки
                if (line.Count > points.Count)
                {
                    if (points.Count == 0)
                    {
                        if (App.Language == CultureInfo.GetCultureInfoByIetfLanguageTag("ru-RU"))
                        {
                            MessageBox.Show("Нельзя создать график без точек", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("You cannot create a graph without points", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    if (points.Count == 1)
                    {
                        if (App.Language == CultureInfo.GetCultureInfoByIetfLanguageTag("ru-RU"))
                        {
                            MessageBox.Show("График должен состоять хотя бы из 2 точек", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("The graph must contain at least 2 points", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    for (int i = line.Count; i > 0; i--)
                    {
                        if (points.Count <= i - 1)
                        {
                            line.Remove(line[i - 1]);
                        }
                        else
                        {
                            line[i - 1] = points[i - 1];
                        }
                    }
                }

                //перенос точек
                for (int i = line.Count; i > 0; i--)
                {
                    line[i - 1] = points[i - 1];
                }

                //добавление новых точек
                if (line.Count < points.Count)
                {
                    for (int i = line.Count; i < points.Count; i++)
                    {
                        line.Add(points[i]);
                    }
                }
            }
            //ошибка может возникнуть при закрытии окна
            catch (Exception ex) { }
        }
예제 #6
0
        public void UpdateChartValues(ChartValues <OrderBookPriceLevel> cv, List <OrderBookPriceLevel> pl, bool isAsk)
        {
            Func <OrderBookPriceLevel, OrderBookPriceLevel, OrderBookPriceLevel> f = ((p, n) =>
            {
                p.Quantity = n.Quantity;
                return(p);
            });

            var removePoints = cv.Where(v => !pl.Any(p => p.Price == v.Price)).ToList();

            foreach (var point in removePoints)
            {
                cv.Remove(point);
            }

            (from v in cv
             join p in pl
             on v.Price equals p.Price
             select f(v, p)).ToList();

            var addPoints   = pl.Where(p => !cv.Any(v => v.Price == p.Price)).ToList();
            var appendRange = new List <OrderBookPriceLevel>();

            foreach (var point in addPoints)
            {
                for (int i = 0; i < cv.Count; i++)
                {
                    if (isAsk)
                    {
                        if (point.Price < cv[i].Price)
                        {
                            cv.Insert(i, point);
                            break;
                        }
                    }
                    else
                    {
                        if (point.Price > cv[i].Price)
                        {
                            cv.Insert(i, point);
                            break;
                        }
                    }

                    if (i == cv.Count - 1)
                    {
                        appendRange.Add(point);
                    }
                }
            }

            if (appendRange.Any())
            {
                if (isAsk)
                {
                    cv.AddRange(appendRange.OrderBy(p => p.Price));
                }
                else
                {
                    cv.AddRange(appendRange.OrderByDescending(p => p.Price));
                }
            }
        }
예제 #7
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            // Removing and adding the new values of  the shop barChart

            foreach (var value in myShopValues)
            {
                myShopValues.Remove(value);
            }

            foreach (var shop in MyShops.Select(v => v.Building).Where(v => v is Shop).ToList())
            {
                myShopValues.Add(((Shop)shop).Stock);
            }

            //Removing and adding the new values for the PieChartWarehouses.

            foreach (var value in myPieChartsValues.ToList())
            {
                myPieChartsValues.Remove(value);
            }

            //foreach (Warehouse warehouse in MyWarehouses.Select(v => v.Building).Where(v => v is Warehouse).ToList())
            //{
            //    int sum = 0;
            //    warehouse.MakeStatistics(count).Vehicles.ForEach(vehicle => sum += vehicle.TotalDrivenTimeUnits);
            //    count++;
            //    myPieChartsValues.Add(new ChartValues<int> { sum });

            //}

            foreach (var warehouse in MyWarehouses)
            {
                int sum = 0;
                foreach (var warStatistic in map.Statistics.Where(x => x is StatisticsWarehouse))
                {
                    if (((StatisticsWarehouse)warStatistic).Warehouse == warehouse.Building)
                    {
                        ((StatisticsWarehouse)warStatistic).Vehicles.ForEach(vehicle => sum += vehicle.TotalGivenDeliveries);
                    }
                }
                myPieChartsValues.Add(new ChartValues <int> {
                    sum
                });
            }

            //Trying to update all the labels

            double AverageDeliveryWaitTime  = 0;
            double DrivingTimePercentage    = 0;
            double NonDrivingTimePercentage = 0;
            double TotalDeliveryWaitTime    = 0;
            double TotalDrivenTimeUnits     = 0;
            double TotalFinishedDeliveries  = 0;
            double TotalGivenDelivers       = 0;
            double TotalNonDrivenTimeUnits  = 0;

            foreach (var warehouse in MyWarehouses)
            {
                foreach (var warStatistic in map.Statistics.Where(x =>
                                                                  (x is StatisticsWarehouse) &&
                                                                  ((((StatisticsWarehouse)x).Time) == getLastTime())))
                {
                    ((StatisticsWarehouse)warStatistic).Vehicles.ForEach(vehicle =>
                    {
                        AverageDeliveryWaitTime += vehicle.AverageDeliveryWaitTime;
                        //   DrivingTimePercentage += vehicle.DrivingTimePercentage;
                        NonDrivingTimePercentage += vehicle.NonDrivingTimePercentage;
                        TotalDeliveryWaitTime    += vehicle.TotalDeliveryWaitTime;
                        TotalDrivenTimeUnits     += vehicle.TotalDrivenTimeUnits;
                        TotalFinishedDeliveries  += vehicle.TotalFinishedDeliveries;
                        TotalGivenDelivers       += vehicle.TotalGivenDeliveries;
                        TotalNonDrivenTimeUnits  += vehicle.TotalGivenDeliveries;
                    });
                }
            }

            lbAverageDeliveryWaitTime.Text = (AverageDeliveryWaitTime / numberOfVehiclesInTotal).ToString();
            //  lbDrivingTimePercentage.Text = (DrivingTimePercentage / numberOfVehiclesInTotal).ToString();
            lbNonDrivingTimePercentage.Text = (NonDrivingTimePercentage / numberOfVehiclesInTotal).ToString();
            lbTotalDeliveryWaitTime.Text    = (TotalNonDrivenTimeUnits / numberOfVehiclesInTotal).ToString();
            lbTotalDrivenTimeUnits.Text     = (TotalDrivenTimeUnits / numberOfVehiclesInTotal).ToString();
            lbTotalFinishedDeliveries.Text  = (TotalFinishedDeliveries / numberOfVehiclesInTotal).ToString();
            lbTotalGivenDeliveries.Text     = (TotalGivenDelivers / numberOfVehiclesInTotal).ToString();
            lbTotalNonDrivenTimeUnits.Text  = (TotalNonDrivenTimeUnits / numberOfVehiclesInTotal).ToString();
        }