/// <summary> /// Формирование массива данных для дня day /// </summary> /// <param name="data"></param> /// <param name="day"></param> private void Instance_DayRefreshed(DateTime day, List <CarStateModel> data) { var curentdata = data ?? new List <CarStateModel>(); var dt = new DateTime(day.Year, day.Month, day.Day); var first = curentdata.FirstOrDefault(); if (first == null || !first.DevID.Equals(CarSelector.SelectedCar.Car.Id) || !Vaiting || dt < DateStart || dt > DateStop) { return; } var el = HistoryRows.FirstOrDefault(o => o.Date.Equals(dt)); if (el == null) { DispatherThreadRun(() => { var item = new HistoryCarStateViewModel(curentdata, dt, _dispatcher); OnAddHistoryRow(item); HistoryRows.Add(item); }); } else { el.SortDataByDate(curentdata, dt); } //if(!_loadedObdData.Any(o => o.DT.ToDate.Equals(day))) }
private void DistanceSelectedDayChanged() { if (SelectedHistoryRow == null) { return; } if (VisCDStart) { _distanceStart = HistoryRows.IndexOf(SelectedHistoryRow); CDStartDay = SelectedHistoryRow.Date.ToString("dd.MM.yy"); } else { _distanceStop = HistoryRows.IndexOf(SelectedHistoryRow); CDStopDay = SelectedHistoryRow.Date.ToString("dd.MM.yy"); } VisCDStart = !VisCDStart; VisCDStop = !VisCDStop; if (_distanceStart <= -1 || _distanceStop <= -1 || _distanceStart >= HistoryRows.Count() || _distanceStop >= HistoryRows.Count()) { return; } double dist = 0; for (var i = _distanceStart; i <= _distanceStop; i++) { dist += HistoryRows[i].Mileage; } TotalDistance = Math.Round(dist, 1).ToString(); }
private void CarSelector_OnCarChanged(DISP_Car car) { CarNumber = car != null ? car.Car.CarNumber: ""; OnPropertyChanged("EnableButton"); OnClearHistory(); HistoryRows.Clear(); _loadedObdData.Clear(); }
private void StartLoadData() { HistoryRows.Clear(); Vaiting = true; if (CarSelector.SelectedCar == null) { return; } CarNumber = CarSelector.SelectedCar.Car.CarNumber; //ReportsHandler.Instance.GetCompilateReport(CarSelector.SelectedCar.Car.Id, DateStart, DateStop); _handler.StartLoadHistory(CarSelector.SelectedCar.Car.Id, DateStart, DateStop); }
private void CarSelector_OnCarChanged(DISP_Car car) { if (car == null) { return; } Position = new DISP_Car { Car = new SCarModel { CarNumber = car.Car.CarNumber, Id = car.Car.Id } }; HistoryRows.Clear(); LoadData(); }
/// <summary> /// Обновление навигационных данных /// </summary> /// <param name="data"></param> /// <param name="date"></param> private void BuildHistoryRow(List <CarStateModel> data, DateTime date) { var r = new LoadedHistoryRows { Date = date, Data = data }; var slowTask = new Task(delegate { try { var dc = new DistanceCalculator(); for (var i = 0; i < data.Count() - 1; i++) { r.Mileage += dc.Calculate(data[i], data[i + 1]); } } catch { } if (!data.Any()) { return; } try { r.MiddleSpeed = data.Sum(p => p.Spd) / 10 / data.Count(); var moving = data.Where(p => p.Spd > 10).ToList(); if (!moving.Any()) { return; } var hStart = moving.Min(p => p.hh); var minStart = moving.Where(p => p.hh == hStart).Min(p => p.mm); var hStop = moving.Max(p => p.hh); var mStop = moving.Where(p => p.hh == hStop).Max(p => p.mm); r.Start = hStart + ":" + minStart; r.Stop = hStop + ":" + mStop; } catch { } }); slowTask.ContinueWith(delegate { if (_dispatcher != null) { _dispatcher.BeginInvoke(new Action(() => { var item = HistoryRows.OrderBy(s => s.Date) .LastOrDefault(o => o.StringDate.Equals(r.StringDate) || o.Date < r.Date); if (item != null) { var indx = HistoryRows.IndexOf(item); _foundselected = HistoryRows[indx].Equals(SelectedHistoryRow); DistanceAll -= HistoryRows[indx].Mileage; HistoryRows[indx] = r; if (_foundselected) { SelectedHistoryRow = r; } _foundselected = false; DistanceAll += r.Mileage; } else { HistoryRows.Add(r); DistanceAll += r.Mileage; } })); } }); slowTask.Start(); }