private void AddLaps(IReadOnlyCollection <LapSummaryDto> lapsSummary)
        {
            foreach (LapSummaryDto lapSummaryDto in lapsSummary)
            {
                ILapSummaryViewModel newViewModel = _viewModelFactory.Create <ILapSummaryViewModel>();
                newViewModel.FromModel(lapSummaryDto);
                newViewModel.LapColor = _colorPaletteProvider.GetNext();
                _lapSelectionViewModel.AddLapSummaryViewModel(newViewModel);
                _allAvailableLaps.Add(lapSummaryDto);
            }

            LapSummaryDto bestLap = _allAvailableLaps.Where(x => x.LapTime != TimeSpan.Zero).OrderBy(x => x.LapTime).FirstOrDefault();

            if (bestLap != null)
            {
                _lapSelectionViewModel.BestLap = $"{bestLap?.CustomDisplayName} - {bestLap.LapTime.FormatToDefault()}";
            }

            LapSummaryDto bestSector1Lap = _allAvailableLaps.Where(x => x.Sector1Time > TimeSpan.Zero).OrderBy(x => x.Sector1Time).FirstOrDefault();

            _lapSelectionViewModel.BestSector1 = bestSector1Lap?.Sector1Time > TimeSpan.Zero ? $"{bestSector1Lap.CustomDisplayName} - {bestSector1Lap.Sector1Time.FormatToDefault()}" : string.Empty;

            LapSummaryDto bestSector2Lap = _allAvailableLaps.Where(x => x.Sector2Time > TimeSpan.Zero).OrderBy(x => x.Sector1Time).FirstOrDefault();

            _lapSelectionViewModel.BestSector2 = bestSector2Lap?.Sector2Time > TimeSpan.Zero ? $"{bestSector2Lap.CustomDisplayName} - {bestSector2Lap.Sector2Time.FormatToDefault()}" : string.Empty;

            LapSummaryDto bestSector3Lap = _allAvailableLaps.Where(x => x.Sector3Time > TimeSpan.Zero).OrderBy(x => x.Sector1Time).FirstOrDefault();

            _lapSelectionViewModel.BestSector3 = bestSector3Lap?.Sector3Time > TimeSpan.Zero ? $"{bestSector3Lap.CustomDisplayName} - {bestSector3Lap.Sector3Time.FormatToDefault()}" : string.Empty;
        }
        private bool TrySaveLap(ILapInfo lapInfo)
        {
            try
            {
                LapSummaryDto lapSummaryDto = CreateLapSummary(lapInfo);

                TimedTelemetrySnapshot fistSnapshotsByDistance = lapInfo.LapTelemetryInfo.TimedTelemetrySnapshots.Snapshots.First(x => x.PlayerData.LapDistance < _sessionInfoDto.LayoutLength * 0.5);

                LapTelemetryDto lapTelemetryDto = new LapTelemetryDto()
                {
                    LapSummary = lapSummaryDto,
                    DataPoints = lapInfo.LapTelemetryInfo.TimedTelemetrySnapshots.Snapshots.Skip(lapInfo.LapTelemetryInfo.TimedTelemetrySnapshots.Snapshots.ToList().IndexOf(fistSnapshotsByDistance)).ToList()
                };


                Interpolate(lapTelemetryDto, lapTelemetryDto.DataPoints.First().SimulatorSourceInfo.TelemetryInfo.RequiresDistanceInterpolation, lapTelemetryDto.DataPoints.First().SimulatorSourceInfo.TelemetryInfo.RequiresPositionInterpolation);

                LapSummaryDto previousLapInfo = _sessionInfoDto.LapsSummary.FirstOrDefault(x => x.LapNumber == lapSummaryDto.LapNumber);
                if (previousLapInfo != null)
                {
                    _sessionInfoDto.LapsSummary.Remove(previousLapInfo);
                }

                _sessionInfoDto.LapsSummary.Add(lapSummaryDto);

                _telemetryRepository.SaveRecentSessionInformation(_sessionInfoDto, SessionIdentifier);
                _telemetryRepository.SaveRecentSessionLap(lapTelemetryDto, SessionIdentifier);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Uanble to Save Telemetry");
                return(false);
            }
        }
        protected override List <LineSeries> GetLineSeries(LapSummaryDto lapSummary, List <TimedTelemetrySnapshot> dataPoints, OxyColor color)
        {
            var lineSeries = base.GetLineSeries(lapSummary, dataPoints, color);

            YMaximum = 0.5;
            YMinimum = -0.5;
            return(lineSeries);
        }
 private void ChangeReferenceLap([CanBeNull] LapSummaryDto lapSummaryDto)
 {
     if (lapSummaryDto == null || _loadedTelemetries.TryGetValue(lapSummaryDto.Id, out _referenceLap))
     {
         _referenceLap = null;
     }
     DataRefreshRequested?.Invoke(this, new EventArgs());
 }
        private LapTelemetryDto LoadLapTelemetryDto(string lapId, LapSummaryDto lapSummaryDto)
        {
            LapTelemetryDto lapTelemetryDto = _telemetryRepository.LoadLapTelemetryDtoFromAnySession(lapSummaryDto);

            _missingTelemetryFillers.ForEach(x => x.SetSimulator(lapSummaryDto.Simulator));
            lapTelemetryDto.Accept(_missingTelemetryFillers.OfType <ITimedTelemetrySnapshotVisitor>().ToArray());
            FillCustomDisplayName(lapTelemetryDto.LapSummary);
            return(lapTelemetryDto);
        }
Beispiel #6
0
        private LapSummaryDto CreateLapSummary(LapInfo lapInfo)
        {
            LapSummaryDto lapSummaryDto = new LapSummaryDto()
            {
                LapNumber         = lapInfo.LapNumber,
                LapTimeSeconds    = lapInfo.LapTime.TotalSeconds,
                Sector1Time       = lapInfo.Sector1?.Duration ?? TimeSpan.Zero,
                Sector2Time       = lapInfo.Sector2?.Duration ?? TimeSpan.Zero,
                Sector3Time       = lapInfo.Sector3?.Duration ?? TimeSpan.Zero,
                SessionIdentifier = SessionIdentifier,
                Simulator         = _sessionInfoDto.Simulator,
                TrackName         = _sessionInfoDto.TrackName,
                LayoutName        = _sessionInfoDto.LayoutName,
            };

            return(lapSummaryDto);
        }
Beispiel #7
0
        protected override List <LineSeries> GetLineSeries(LapSummaryDto lapSummary, List <TimedTelemetrySnapshot> dataPoints, OxyColor color)
        {
            LineSeries       newLineSeries = CreateLineSeries($"Lap {lapSummary.CustomDisplayName}", color);
            List <DataPoint> points        = new List <DataPoint>(dataPoints.Count);
            DataPoint        oldPoint      = new DataPoint();

            for (int i = 0; i < dataPoints.Count - 1; i++)
            {
                var dp1 = dataPoints[i];
                var dp2 = dataPoints[i + 1];

                DataPoint oxyPoint = new DataPoint((GetXValue(dp1) + GetXValue(dp2)) / 2, GetYValue(dp1, dp2));
                if (i != 0 && !IsValid(oldPoint, oxyPoint))
                {
                    continue;
                }

                oldPoint = oxyPoint;
                points.Add(oxyPoint);
            }

            newLineSeries.Points.AddRange(points);

            /*LineSeries newLineSeries2 = CreateLineSeries($"Lap {lapSummary.CustomDisplayName} Angle", OxyColors.Wheat);
             * List<DataPoint> points2 = new List<DataPoint>(dataPoints.Length - 1);
             * for (int i = 0; i < dataPoints.Length - 1; i++)
             * {
             *  var dp1 = dataPoints[i];
             *  var dp2 = dataPoints[i + 1];
             *
             *  double angle = (dp1.PlayerData.WorldPosition.X.InMeters - dp2.PlayerData.WorldPosition.X.InMeters);
             *  DataPoint oxyPoint = new DataPoint((GetXValue(dp1) + GetXValue(dp2)) / 2,  angle );
             *  points2.Add(oxyPoint);
             * }
             *
             * newLineSeries2.Points.AddRange(points2);*/

            List <LineSeries> series = new List <LineSeries>(1)
            {
                newLineSeries
            };

            return(series);
        }
        private LapSummaryDto CreateLapSummary(ILapInfo lapInfo)
        {
            int           stintNumber   = lapInfo.Driver.Laps.Count(x => x.PitLap);
            LapSummaryDto lapSummaryDto = new LapSummaryDto()
            {
                LapNumber         = lapInfo.LapNumber,
                LapTimeSeconds    = lapInfo.LapTime.TotalSeconds,
                Sector1Time       = lapInfo.Sector1?.Duration ?? TimeSpan.Zero,
                Sector2Time       = lapInfo.Sector2?.Duration ?? TimeSpan.Zero,
                Sector3Time       = lapInfo.Sector3?.Duration ?? TimeSpan.Zero,
                SessionIdentifier = SessionIdentifier,
                Simulator         = _sessionInfoDto.Simulator,
                TrackName         = _sessionInfoDto.TrackName,
                LayoutName        = _sessionInfoDto.LayoutName,
                Stint             = stintNumber,
            };

            return(lapSummaryDto);
        }
        public async Task <LapTelemetryDto> LoadLap(LapSummaryDto lapSummaryDto)
        {
            try
            {
                AddToActiveLapJob();
                LapTelemetryDto lapTelemetryDto = null;
                await Task.Run(() => lapTelemetryDto = _cachedTelemetries.GetOrAdd(lapSummaryDto.Id, LoadLapTelemetryDto, lapSummaryDto));

                _telemetryViewsSynchronization.NotifyLapLoaded(lapTelemetryDto);
                return(lapTelemetryDto);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error while loading lap telemetry");
                return(null);
            }
            finally
            {
                RemoveFromActiveLapJob();
            }
        }
Beispiel #10
0
        public async Task <LapTelemetryDto> LoadLap(LapSummaryDto lapSummaryDto)
        {
            try
            {
                AddToActiveLapJob();
                if (!_cachedTelemetries.TryGetValue(lapSummaryDto.Id, out LapTelemetryDto lapTelemetryDto))
                {
                    lapTelemetryDto = await Task.Run(() => _telemetryRepository.LoadLapTelemetryDtoFromAnySession(lapSummaryDto));

                    FillCustomDisplayName(lapTelemetryDto.LapSummary);
                    _cachedTelemetries[lapTelemetryDto.LapSummary.Id] = lapTelemetryDto;
                }
                _telemetryViewsSynchronization.NotifyLapLoaded(lapTelemetryDto);
                RemoveFromActiveLapJob();
                return(lapTelemetryDto);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error while loading lap telemetry");
                return(null);
            }
        }
        public void NotifyLapUnloaded(LapSummaryDto lapSummaryDto)
        {
            LapSummaryArgs args = new LapSummaryArgs(lapSummaryDto);

            LapUnloaded?.Invoke(this, args);
        }
Beispiel #12
0
 public LapSummaryArgs(LapSummaryDto lapSummary)
 {
     LapSummary = lapSummary;
 }
Beispiel #13
0
        private void FillCustomDisplayName(LapSummaryDto lapSummaryDto)
        {
            int sessionIndex = _loadedSessions.IndexOf(lapSummaryDto.SessionIdentifier);

            lapSummaryDto.CustomDisplayName = sessionIndex > 0 ? $"{sessionIndex}/{lapSummaryDto.LapNumber}" : lapSummaryDto.LapNumber.ToString();
        }
Beispiel #14
0
 public Task UnloadLap(LapSummaryDto lapSummaryDto)
 {
     _telemetryViewsSynchronization.NotifyLapUnloaded(lapSummaryDto);
     return(Task.CompletedTask);
 }
 private void ChangeReferenceLap([CanBeNull] LapSummaryDto lapSummaryDto)
 {
     _referenceLap = lapSummaryDto != null ? _loadedTelemetries[lapSummaryDto.Id] : null;
     DataRefreshRequested?.Invoke(this, new EventArgs());
 }
        public void NotifyReferenceLapSelected(LapSummaryDto referenceLap)
        {
            LapSummaryArgs args = new LapSummaryArgs(referenceLap);

            ReferenceLapSelected?.Invoke(this, args);
        }
 public TelemetryStoryboard(LapSummaryDto lapSummaryDto)
 {
     LapSummaryDto   = lapSummaryDto;
     TelemetryFrames = new List <TelemetryFrame>().AsReadOnly();
 }
 public bool TryPickLaps(IEnumerable <LapSummaryDto> laps, out IReadOnlyCollection <LapSummaryDto> selectedLaps, out LapSummaryDto referenceLap)
 {
     selectedLaps = null;
     referenceLap = null;
     return(false);
 }
 public TelemetrySnapshotArgs(TimedTelemetrySnapshot telemetrySnapshot, LapSummaryDto lapSummaryDto)
 {
     TelemetrySnapshot = telemetrySnapshot;
     LapSummaryDto     = lapSummaryDto;
 }
 private void TelemetryViewsSynchronizationOnReferenceLapSelected(object sender, LapSummaryArgs e)
 {
     ReferenceLap = e.LapSummary;
 }
 public bool ShowLapGraph(LapSummaryDto lapSummaryDto)
 {
     return(true);
 }
 public bool ShowLapGraph(LapSummaryDto lapSummaryDto)
 {
     return lapSummaryDto.Id != _referenceLap?.LapSummaryDto.Id;
 }
        public void NotifyLappAddedToSession(LapSummaryDto lapSummaryDto)
        {
            LapSummaryArgs args = new LapSummaryArgs(lapSummaryDto);

            LapAddedToSession?.Invoke(this, args);
        }
        public void NotifySynchronizeToSnapshot(TimedTelemetrySnapshot telemetrySnapshot, LapSummaryDto lapSummary)
        {
            TelemetrySnapshotArgs args = new TelemetrySnapshotArgs(telemetrySnapshot, lapSummary);

            SyncTelemetryView?.Invoke(this, args);
        }