Esempio n. 1
0
        public void AddLap(CleanSession cSess, CleanLap cLap)
        {
            if (!LapsBySession.ContainsKey(cSess))
            {
                LapsBySession[cSess] = new List <CleanLap>();
            }

            LapsBySession[cSess].Add(cLap);
        }
Esempio n. 2
0
        public static RaceData ParseRawTSVData(string[] tsvLines)
        {
            RaceData data = new RaceData();

            CleanSession session = new CleanSession();

            data.AllSessions.Add(session);
            data.UnknownSessions.Add(session);

            session.Name = "Championship Position";

            foreach (string line in tsvLines)
            {
                if (line.StartsWith("ACRL") || line.StartsWith("POS"))
                {
                    continue;
                }

                Driver curDriver = new Driver();
                session.DriversInSession.Add(curDriver);
                data.Drivers.Add(curDriver);

                CleanLap lap = new CleanLap();
                lap.Driver    = curDriver;
                lap.LapNumber = 1;
                lap.Time      = TimeSpan.Zero;

                curDriver.BestLapBySession[session] = lap;

                string[] lineParts = line.Split('\t');

                curDriver.Name = lineParts[4];
                int position;
                session.Result[curDriver] = Int32.TryParse(lineParts[0], out position) ? position : 0;
            }

            return(data);
        }
Esempio n. 3
0
        public void UpdateSessionData(CleanSession ses, bool clearMissingDriverData)
        {
            Dictionary <Entry, Driver> entryListForSession = new Dictionary <Entry, Driver>();

            foreach (Driver sD in ses.DriversInSession)
            {
                Entry curEntry = Entries.FirstOrDefault(eD => eD.Name == sD.Name);
                if (curEntry != null)
                {
                    entryListForSession[curEntry] = sD;
                }
            }

            List <Entry> missingFromSession = Entries.Except(entryListForSession.Keys).ToList();

            foreach (var driver in entryListForSession)
            {
                driver.Key.LapTime = driver.Value.BestLapBySession[ses].Time;

                if (ses.Result.ContainsKey(driver.Value))
                {
                    driver.Key.RacePosition = ses.Result[driver.Value];
                }
                else if (clearMissingDriverData)
                {
                    driver.Key.RacePosition = 99;
                }
            }

            if (clearMissingDriverData)
            {
                foreach (Entry driver in missingFromSession)
                {
                    driver.LapTime      = TimeSpan.FromMinutes(59);
                    driver.RacePosition = 99;
                }
            }
        }
Esempio n. 4
0
        private void btnUpdateEntry_Click(object sender, RoutedEventArgs e)
        {
            CleanSession ses = cbSessions.SelectedItem as CleanSession;

            m_entryList.UpdateSessionData(ses, cbUpdateMissing.IsChecked.HasValue && cbUpdateMissing.IsChecked.Value);
        }
Esempio n. 5
0
        public static RaceData ParseRawJSONData(RawClientRaceData rawClientData)
        {
            RaceData rd = new RaceData();

            rd.TrackName = rawClientData.track;

            for (int i = 0; i < rawClientData.players.Length; i++)
            {
                RawClientPlayer rawDriver   = rawClientData.players[i];
                Driver          cleanDriver = new Driver();
                cleanDriver.Car  = rawDriver.car;
                cleanDriver.ID   = i;
                cleanDriver.Name = rawDriver.name;
                cleanDriver.Skin = rawDriver.skin;

                rd.Drivers.Add(cleanDriver);
            }

            for (int i = 0; i < rawClientData.sessions.Length; i++)
            {
                RawClientSession ses   = rawClientData.sessions[i];
                CleanSession     cSess = new CleanSession();

                rd.AllSessions.Add(cSess);

                cSess.ID            = i;
                cSess.Name          = $"{ses.name} {ses._event + 1}";
                cSess.Duration      = TimeSpan.FromMinutes(ses.duration);
                cSess.TotalLapCount = ses.laps.Length;

                switch (ses.type)
                {
                case 1:
                    cSess.Type = CleanSession.ESessionType.Practice;
                    rd.PracticeSessions.Add(cSess);
                    break;

                case 2:
                    cSess.Type = CleanSession.ESessionType.Qualifying;
                    rd.QualifySessions.Add(cSess);
                    break;

                case 3:
                    cSess.Type = CleanSession.ESessionType.Race;
                    rd.RaceSessions.Add(cSess);
                    break;

                default:
                    cSess.Type = CleanSession.ESessionType.Unknown;
                    rd.UnknownSessions.Add(cSess);
                    break;
                }

                foreach (RawClientLap rawLap in ses.laps)
                {
                    CleanLap cLap = new CleanLap();
                    cLap.LapNumber = rawLap.lap;
                    cLap.Time      = TimeSpan.FromMilliseconds(rawLap.time);

                    Driver driv = rd.Drivers[rawLap.car];
                    driv.AddLap(cSess, cLap);
                    cLap.Driver = driv;

                    cSess.AddDriver(driv);
                }

                foreach (RawClientBestlap rawLap in ses.bestLaps)
                {
                    Driver   driv = rd.Drivers[rawLap.car];
                    CleanLap cLap = driv.LapsBySession[cSess][rawLap.lap];
                    driv.BestLapBySession[cSess] = cLap;
                }

                if (ses.raceResult != null)
                {
                    for (int pos = 0; pos < ses.raceResult.Length; pos++)
                    {
                        int    id   = ses.raceResult[pos];
                        Driver driv = rd.Drivers[id];
                        cSess.Result[driv] = pos + 1;
                    }
                }
            }

            return(rd);
        }