Esempio n. 1
0
        private void btnLoadRaceData_Click(object sender, RoutedEventArgs e)
        {
            if (m_ofdRaceData.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            if (Path.GetExtension(m_ofdRaceData.FileName) == ".json")
            {
                RawClientRaceData rawClientData = JsonConvert.DeserializeObject <RawClientRaceData>(File.ReadAllText(m_ofdRaceData.FileName));
                RaceSessionData = RaceData.ParseRawJSONData(rawClientData);
            }
            else if (Path.GetExtension(m_ofdRaceData.FileName) == ".tsv")
            {
                RaceSessionData = RaceData.ParseRawTSVData(File.ReadAllLines(m_ofdRaceData.FileName));
            }
            else
            {
                MessageBox.Show("Error: Invalid race data extension.", "Error", MessageBoxButtons.OK);
                return;
            }

            lblDriverCount.Content = $"Drivers: {RaceSessionData.Drivers.Count}";

            if (RaceSessionData.AllSessions.Count > 0)
            {
                cbSessions.IsEnabled     = true;
                cbSessions.ItemsSource   = RaceSessionData.AllSessions;
                cbSessions.SelectedIndex = 0;

                btnUpdateEntry.IsEnabled = true;
            }
            else
            {
                cbSessions.IsEnabled     = false;
                cbSessions.SelectedIndex = -1;
                cbSessions.ItemsSource   = null;

                btnUpdateEntry.IsEnabled = false;
            }
        }
Esempio n. 2
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);
        }