internal void ParseYaml(YamlQuery query, int position)
 {
     this.Position = position + 1;
     this.ClassPosition = Parser.ParseInt(query["ClassPosition"].GetValue()) + 1;
     this.Lap = new Laptime(Parser.ParseFloat(query["FastestTime"].GetValue()));
     this.Lap.LapNumber = Parser.ParseInt(query["FastestLap"].GetValue());
 }
 internal void ParseYaml(YamlQuery query, int position)
 {
     this.Position      = position + 1;
     this.ClassPosition = Parser.ParseInt(query["ClassPosition"].GetValue()) + 1;
     this.Lap           = new Laptime(Parser.ParseFloat(query["FastestTime"].GetValue()));
     this.Lap.LapNumber = Parser.ParseInt(query["FastestLap"].GetValue());
 }
        public BestLap UpdateFastestLap(Laptime lap, Driver driver)
        {
            var classId = driver.Car.CarClassId;
            if (!this.ClassBestLaps.ContainsKey(classId))
            {
                this.ClassBestLaps.Add(classId, BestLap.Default);
            }

            if (lap.Value > 0 && this.ClassBestLaps[classId].Laptime.Value > lap.Value)
            {
                var bestlap = new BestLap(lap, driver);
                this.ClassBestLaps[classId] = bestlap;

                this.OverallBestLap =
                    this.ClassBestLaps.Values.Where(l => l.Laptime.Value > 0)
                        .OrderBy(l => l.Laptime.Value)
                        .FirstOrDefault();

                return bestlap;
            }
            return null;
        }
Example #4
0
        public async Task <Laptime> StartRaceAsync(uint totalLaps)
        {
            Laptime fastestLaptime = null;

            await foreach (var laptime in this.laptimeFeed.ReadLaptimesAsync().ConfigureAwait(false))
            {
                if (fastestLaptime == null)
                {
                    fastestLaptime = laptime;
                }
                else if (laptime.Time < fastestLaptime.Time)
                {
                    fastestLaptime = laptime;
                }

                // First kart to complete all laps finishes the race
                if (laptime.Lap == totalLaps)
                {
                    return(fastestLaptime);
                }
            }

            throw new InvalidOperationException("The laptime feed doesn't provide enough laptimes");
        }
 public static string DeltaToString(TimeSpan delta)
 {
     var seconds = delta.TotalSeconds;
     var laptime = new Laptime((float)seconds);
     return laptime.DisplayShort;
 }
        internal void ParseYaml(YamlQuery query, int position)
        {
            this.IsEmpty = false;

            this.Position = position;
            this.ClassPosition = Parser.ParseInt(query["ClassPosition"].GetValue()) + 1;

            this.Lap = Parser.ParseInt(query["Lap"].GetValue());
            this.Time = new Laptime(Parser.ParseFloat(query["Time"].GetValue()));
            this.FastestLap = Parser.ParseInt(query["FastestLap"].GetValue());
            this.FastestTime = new Laptime(Parser.ParseFloat(query["FastestTime"].GetValue()));
            this.LastTime = new Laptime(Parser.ParseFloat(query["LastTime"].GetValue()));
            this.LapsLed = Parser.ParseInt(query["LapsLed"].GetValue());

            var previousLaps = this.LapsComplete;
            this.LapsComplete = Parser.ParseInt(query["LapsComplete"].GetValue());
            this.LapsDriven = Parser.ParseInt(query["LapsDriven"].GetValue());

            this.FastestTime.LapNumber = this.FastestLap;
            this.LastTime.LapNumber = this.LapsComplete;

            // Check if a new lap is completed, and add it to Laps
            if (this.LapsComplete > previousLaps)
            {
                this.Laps.Add(this.LastTime);
                this.AverageTime = this.Laps.Average();
            }

            this.Incidents = Parser.ParseInt(query["Incidents"].GetValue());;
            this.OutReasonId = Parser.ParseInt(query["ReasonOutId"].GetValue());
            this.OutReason = query["ReasonOutStr"].GetValue();
        }
        private async Task ProcessLaptimes()
        {
            int colRaceId   = 0;
            int coldriverId = 1;
            int colLapnr    = 2;
            int colPos      = 3;
            int colMil      = 5;

            string filename = @"D:\git\blazoring\lap_times2.csv";

            using (StreamReader reader = new StreamReader(filename))
            {
                //eerste regel is zooi
                await reader.ReadLineAsync();

                // key: driverId uit geval, driverEntryId
                // dus: als we in het bestand een driverId vinden.
                // gaan we naar _drivers[driverId] om DRIVERID database te krijgen
                // met dat nummer zoeken we in de database naar het DriverEntryId dat bij deze rijder en dit event hoort
                // dat nummer stoppen in de de entries database.
                // daarna, als een op een regel dus een DriverId tegenkomen, weten we het juiste driverentryid nummer
                // man, man, man.
                var entries       = new Dictionary <int, int>();
                int currentRaceId = -1;
                int counter       = 1;
                //eerste regel is zooi
                await reader.ReadLineAsync();

                while (!reader.EndOfStream)
                {
                    var line = await reader.ReadLineAsync();

                    var splitted = Split(line);

                    int raceId   = Convert.ToInt32(splitted[colRaceId]);
                    int driverId = Convert.ToInt32(splitted[coldriverId]);
                    int lap      = Convert.ToInt32(splitted[colLapnr]);
                    int position = Convert.ToInt32(splitted[colPos]);
                    int milli    = Convert.ToInt32(splitted[colMil]);

                    if (raceId == 1034)
                    {
                        Console.WriteLine("ik stop");
                    }

                    if (raceId != currentRaceId)
                    {
                        Console.WriteLine($"New race!: {raceId}");
                        var convertedRaceId = _raceEvents[raceId].RaceEventId;
                        currentRaceId = raceId;
                        var entriesTemp = await _context.EventResults
                                          .AsNoTracking()
                                          .Include(er => er.DriverEntry)
                                          .AsNoTracking()
                                          .Where(er => er.RaceEventId == convertedRaceId)
                                          .Select(x => x.DriverEntry)
                                          .ToListAsync();

                        entries = new Dictionary <int, int>();

                        foreach (var et in entriesTemp)
                        {
                            var mappedDriverId = _drivers[et.DriverId];
                            entries.Add(mappedDriverId, et.DriverEntryId);
                        }
                    }

                    var raceEvent = _raceEvents[raceId].RaceEventId;
                    if (!entries.ContainsKey(driverId))
                    {
                        Console.WriteLine("possible race not run!");
                        counter++;
                        continue;
                    }
                    var driverToUse = entries[driverId];

                    var laptime = new Laptime
                    {
                        RaceEventId     = raceEvent,
                        DriverEntryId   = driverToUse,
                        LapNumber       = lap,
                        CurrentPosition = position,
                        Milliseconds    = milli
                    };

                    Console.WriteLine($"adding lap nr {counter}: {milli}ms");
                    _context.Laptimes.Add(laptime);

                    //elke 1000 committen
                    //if (counter % 1000 == 0)
                    //{
                    //await _context.SaveChangesAsync();
                    //}

                    counter++;
                }
            }

            await _context.SaveChangesAsync();
        }