예제 #1
0
        public static RaceResult FromCsv(string line, F1EncyclopediaContext db)
        {
            var values = line.Split(',');

            var raceWeekendId = RaceWeekend.RaceWeekendIdCorrection(values[1]);
            var driverId      = Person.DriverIdCorrection(values[2]);
            var constructorId = Constructor.ConstructorIdCorrection(values[3]);
            var statusId      = RaceStatus.StatusIdCorrection(values[17]);

            var raceWeekend = db.RaceWeekends.FirstOrDefault(x => x.Id == raceWeekendId);
            var driver      = db.Persons.FirstOrDefault(x => x.Id == driverId);
            var constructor = db.Constructors.FirstOrDefault(x => x.Id == constructorId);
            var status      = db.RaceStatuses.FirstOrDefault(x => x.Id == statusId);

            LogUnmatchedProperties(raceWeekend, raceWeekendId);
            LogUnmatchedProperties(driver, driverId);
            LogUnmatchedProperties(constructor, constructorId);
            LogUnmatchedProperties(status, statusId);

            var raceResult = new RaceResult()
            {
                GridPosition  = Convert.ToInt32(values[5]),
                Position      = Convert.ToInt32(values[8]),
                Points        = Convert.ToInt32(values[9]),
                Laps          = Convert.ToInt32(values[10]),
                Time          = GetTimeSpan(values[12]),
                RaceWeekendId = raceWeekend != null ? raceWeekend.Id : 1,
                DriverId      = driver != null ? driver.Id : 1,
                ConstructorId = constructor != null ? constructor.Id : 1,
                StatusId      = status != null ? status.Id : 1
            };

            return(raceResult);
        }
예제 #2
0
        public static LapTime FromCsv(string line, F1EncyclopediaContext context)
        {
            var values        = line.Split(',');
            var raceWeekendId = RaceWeekend.RaceWeekendIdCorrection(values[0]);
            var driverId      = Person.DriverIdCorrection(values[1]);

            var raceWeekend = context.RaceWeekends.FirstOrDefault(x => x.Id == raceWeekendId);
            var driver      = context.Persons.FirstOrDefault(x => x.Id == driverId);

            LogUnmatchedProperties(driver, driverId);
            LogUnmatchedProperties(raceWeekend, raceWeekendId);

            return(new LapTime()
            {
                RaceWeekendId = raceWeekend != null ? raceWeekend.Id : 1,
                DriverId = driver != null ? driver.Id : 1,
                Lap = Convert.ToInt32(values[2]),
                Position = Convert.ToInt32(values[3]),
                Time = GetTimeSpan(values[5])
            });
        }
예제 #3
0
        public static Qualifying FromCsv(string line)
        {
            var values = line.Split(',');

            using (var db = new F1EncyclopediaContext())
            {
                var correctedRaceWeekendId = RaceWeekend.RaceWeekendIdCorrection(values[1]);
                var correctedDriverId      = Person.DriverIdCorrection(values[2]);
                var correctedConstructorId = Constructor.ConstructorIdCorrection(values[3]);

                var raceWeekend = db.RaceWeekends.FirstOrDefault(x =>
                                                                 x.Id == Convert.ToInt32(values[1]));

                var driver = db.Persons.FirstOrDefault(x =>
                                                       x.Id == Convert.ToInt32(values[2]));

                var constructor = db.Constructors.FirstOrDefault(x =>
                                                                 x.Id == Convert.ToInt32(values[3]));

                LogUnmatchedProperties(raceWeekend, correctedRaceWeekendId);
                LogUnmatchedProperties(driver, correctedDriverId);
                LogUnmatchedProperties(constructor, correctedConstructorId);

                var quali = new Qualifying()
                {
                    RaceWeekendId = raceWeekend != null ? raceWeekend.Id : 1,
                    DriverId      = driver != null ? driver.Id : 1,
                    ConstructorId = constructor != null ? constructor.Id : 1,
                    Position      = Convert.ToInt32(values[4]),
                    Q1            = GetTimeSpan(values[5]),
                    Q2            = GetTimeSpan(values[6]),
                    Q3            = GetTimeSpan(values[7])
                };

                return(quali);
            }
        }