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

            LapsBySession[cSess].Add(cLap);
        }
Example #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);
        }
Example #3
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);
        }