Example #1
0
        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();
        }
Example #2
0
        /// <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();
        }