Example #1
0
        private void CheckAndOverrideBestLap(double layoutLength)
        {
            if (DriverInfo.Timing.BestLapTime == TimeSpan.Zero)
            {
                return;
            }

            if (BestLap == null)
            {
                ILapInfo newBestLap = new StaticLapInfo(Laps.Count + 1, DriverInfo.Timing.BestLapTime, false, Laps.LastOrDefault(), layoutLength, this);
                _lapsInfo.Insert(0, newBestLap);
                BestLap = newBestLap;
                LapCompleted?.Invoke(this, new LapEventArgs(newBestLap));
                return;
            }

            if (BestLap.LapTime == DriverInfo.Timing.BestLapTime)
            {
                return;
            }

            ILapInfo oldBestLap = BestLap;

            oldBestLap.OverrideTime(DriverInfo.Timing.BestLapTime);
            BestLap = Laps.Where(x => x.Completed && x.Valid && x.LapTime != TimeSpan.Zero).OrderBy(x => x.LapTime).FirstOrDefault();
            LapTimeReevaluated?.Invoke(this, new LapEventArgs(oldBestLap));
        }
Example #2
0
        private void analyseLaps()
        {
            var lDist = Laps.Sum(l => l.DistanceMeters);
            var lapsWithTrackPoints = Laps.Where(l => l.TrackPoints != null && l.TrackPoints.Any()).ToList();

            if (lapsWithTrackPoints.Any())
            {
                var tDist = lapsWithTrackPoints.SelectMany(l => l.TrackPoints).Max(t => t.DistanceMeters);
                if (lDist != tDist)
                {
                    Debugger.Log(1, "", $"Laps inconsistent: trackpoints cover {100.0 * tDist / lDist}% of lap distance ({tDist} vs {lDist})\r\n");
                }
            }
            TrackPoint lastTrackPoint = null;
            var        totalDistance  = 0.0;

            foreach (var lap in Laps)
            {
                totalDistance += lap.DistanceMeters;
                foreach (var trackpoint in lap.TrackPoints)
                {
                    if (lastTrackPoint != null)
                    {
                        var interval        = trackpoint.Time - lastTrackPoint.Time;
                        var intervalS       = interval.TotalSeconds;
                        var distanceCovered = trackpoint.DistanceMeters - lastTrackPoint.DistanceMeters;
                        lastTrackPoint.Interval          = interval;
                        trackpoint.DistanceCoveredMeters = distanceCovered;
                    }
                    lastTrackPoint = trackpoint;
                }
            }
            if (lastTrackPoint != null)
            {
                lastTrackPoint.Interval = EndTime - lastTrackPoint.Time;
            }
        }
Example #3
0
 private SectorTiming FindBestSector(Func <LapInfo, SectorTiming> sectorPickerFunc)
 {
     return(Laps.Where(l => l.Valid).Select(sectorPickerFunc).Where(s => s != null && s.Duration != TimeSpan.Zero)
            .OrderBy(s => s.Duration).FirstOrDefault());
 }
Example #4
0
 private void PurgeLapsTelemetry()
 {
     Laps.Where(x => x.Completed && x.LapTelemetryInfo != null && !x.LapTelemetryInfo.IsPurged && x != BestLap && x.LapNumber != 1 && x != x.Driver.LastCompletedLap).Skip(MaxLapsWithTelemetry).ForEach(x => x.LapTelemetryInfo.Purge());
 }