void NoteNewFastestLap(DataSample data, TimeSpan relativeTime)
        {
            if (timeToNoteFastestLap == null)
                timeToNoteFastestLap = data.Telemetry.SessionTime + 20;

            lastFastestLap = data.Telemetry.FastestLap;

            TraceInfo.WriteLine("{0} Driver {1} recorded a new fast lap of {2:0.00}", data.Telemetry.SessionTimeSpan, lastFastestLap.Driver.UserName, lastFastestLap.Time.TotalSeconds);
        }
Exemplo n.º 2
0
        void NoteNewFastestLap(DataSample data, TimeSpan relativeTime)
        {
            if (timeToNoteFastestLap == null)
            {
                timeToNoteFastestLap = data.Telemetry.SessionTime + 20;
            }

            lastFastestLap = data.Telemetry.FastestLap;

            TraceInfo.WriteLine("{0} Driver {1} recorded a new fast lap of {2:0.00}", data.Telemetry.SessionTimeSpan, lastFastestLap.Driver.UserName, lastFastestLap.Time.TotalSeconds);
        }
Exemplo n.º 3
0
        public static IEnumerable <DataSample> WithFastestLaps(this IEnumerable <DataSample> samples)
        {
            FastLap lastFastLap        = null;
            var     lastDriverLaps     = new int[64];
            var     driverLapStartTime = new double[64];
            var     fastestLapTime     = double.MaxValue;

            foreach (var data in samples.ForwardOnly())
            {
                var carsAndLaps = data.Telemetry
                                  .CarIdxLap
                                  .Select((l, i) => new { CarIdx = i, Lap = l })
                                  .Skip(1)
                                  .Take(data.SessionData.DriverInfo.CompetingDrivers.Length - 1);

                foreach (var lap in carsAndLaps)
                {
                    if (lap.Lap == -1)
                    {
                        continue;
                    }

                    if (lap.Lap == lastDriverLaps[lap.CarIdx] + 1)
                    {
                        var lapTime = data.Telemetry.SessionTime - driverLapStartTime[lap.CarIdx];

                        driverLapStartTime[lap.CarIdx] = data.Telemetry.SessionTime;
                        lastDriverLaps[lap.CarIdx]     = lap.Lap;

                        if (lap.Lap > 1 && lapTime < fastestLapTime)
                        {
                            fastestLapTime = lapTime;

                            lastFastLap = new FastLap
                            {
                                Time   = TimeSpan.FromSeconds(lapTime),
                                Driver = data.SessionData.DriverInfo.CompetingDrivers[lap.CarIdx]
                            };
                        }
                    }
                }

                data.Telemetry.FastestLap = lastFastLap;

                yield return(data);
            }
        }
Exemplo n.º 4
0
        public static IEnumerable<DataSample> WithFastestLaps(this IEnumerable<DataSample> samples)
        {
            FastLap lastFastLap = null;
            var lastDriverLaps = new int[64];
            var driverLapStartTime = new double[64];
            var fastestLapTime = double.MaxValue;

			foreach (var data in samples.ForwardOnly())
            {
                var carsAndLaps = data.Telemetry
                    .CarIdxLap
                    .Select((l, i) => new { CarIdx = i, Lap = l })
                    .Skip(1)
                    .Take(data.SessionData.DriverInfo.CompetingDrivers.Length - 1);

                foreach (var lap in carsAndLaps)
                {
                    if (lap.Lap == -1)
                        continue;

                    if (lap.Lap == lastDriverLaps[lap.CarIdx] + 1)
                    {
                        var lapTime = data.Telemetry.SessionTime - driverLapStartTime[lap.CarIdx];

                        driverLapStartTime[lap.CarIdx] = data.Telemetry.SessionTime;
                        lastDriverLaps[lap.CarIdx] = lap.Lap;

                        if (lap.Lap > 1 && lapTime < fastestLapTime)
                        {
                            fastestLapTime = lapTime;

                            lastFastLap = new FastLap
                            {
                                Time = TimeSpan.FromSeconds(lapTime),
                                Driver = data.SessionData.DriverInfo.CompetingDrivers[lap.CarIdx]
                            };
                        }
                    }
                }

                data.Telemetry.FastestLap = lastFastLap;

                yield return data;
            }
        }
        public static void Sample()
        {
            FastLap lastFastestLap = null;
            var     iracing        = new iRacingConnection();

            Trace.WriteLine("Moving to start of race");
            iracing.Replay.MoveToStartOfRace();
            Trace.WriteLine("Watching for fastest laps");

            foreach (var data in iracing.GetDataFeed().AtSpeed(16).WithFastestLaps())
            {
                if (lastFastestLap != data.Telemetry.FastestLap)
                {
                    Trace.WriteLine(string.Format("{0} - {1}", data.Telemetry.FastestLap.Driver.UserName, data.Telemetry.FastestLap.Time));
                }

                lastFastestLap = data.Telemetry.FastestLap;
            }
        }