Пример #1
0
        public MainViewModel(IWayRepository wayRepository, ILiftFinder liftFinder,
                             IActivityRepository activityRepository, ISlopeNodeChecker slopeNodeChecker,
                             IStatsService statsService)
        {
            _wayRepository    = wayRepository;
            _slopeNodeChecker = slopeNodeChecker;
            _statsService     = statsService;
            _liftFinder       = liftFinder;

            PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case nameof(SelectedLift):
                    ShowSelectedLift();
                    break;

                case nameof(SelectedLap):
                    ShowSelectedLap();
                    break;
                }
            };

            // Changed displayOptions -> Update views accordingly
            DisplayOptions.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName != null && args.PropertyName.StartsWith("Show"))
                {
                    TakenLifts = new ObservableCollection <Way>();

                    MapItems.Reset();

                    Laps       = new ObservableCollection <Lap>();
                    Statistics = new Statistics();


                    var allActivities = new List <Lap>();
                    if (DisplayOptions.ShowTuesday)
                    {
                        allActivities.AddRange(activityRepository.GetSingleDay(Day.Tuesday));
                    }

                    if (DisplayOptions.ShowWednesday)
                    {
                        allActivities.AddRange(activityRepository.GetSingleDay(Day.Wednesday));
                    }

                    if (DisplayOptions.ShowThursday)
                    {
                        allActivities.AddRange(activityRepository.GetSingleDay(Day.Thursday));
                    }

                    if (DisplayOptions.ShowFriday)
                    {
                        allActivities.AddRange(activityRepository.GetSingleDay(Day.Friday));
                    }

                    if (DisplayOptions.ShowSaturday)
                    {
                        allActivities.AddRange(activityRepository.GetSingleDay(Day.Saturday));
                    }

                    var allTrackingPoints = allActivities.SelectMany(a => a.TrackingPoints);

                    CalculateStats(allTrackingPoints);

                    foreach (var lap in allActivities)
                    {
                        Laps.Add(lap);
                        var firstPoint = lap.TrackingPoints.FirstOrDefault();
                        ShowLapStartFlags(firstPoint, lap.Number);

                        CheckTakenLifts(firstPoint);
                        ShowTrackingPoints(lap);
                        ShowSpeedLine(lap);
                        ShowHeartRateLine(lap);
                    }
                }

                LiftStatistics = _statsService.CalculateLiftStatistics(TakenLifts);
                ShowLiftNamePins();
            };

            DrawMadeSlopes();
            DrawSlopes();
            DrawLifts();
        }