예제 #1
0
        void _tList_Tick(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(_tList_Tick), new object[2] {
                    sender, e
                });
                return;
            }

            // Update the list
            OleDbConnection con = DatabaseOleDbConnectionPool.GetOleDbConnection();

            using (OleDbCommand sLaps = new OleDbCommand("SELECT id, Simulator, Circuit, Series, Car, Laptime, S1, S2, S3, Driven, LapNo, FilePath FROM laptimes WHERE InvalidLapData = 0", con))
                using (OleDbDataReader rLaps = sLaps.ExecuteReader())
                {
                    while (rLaps.HasRows && rLaps.Read())
                    {
                        int  id     = rLaps.GetInt32(0);
                        bool exists = false;
                        foreach (ListViewItem lvi in _vldLaptimes.Items)
                        {
                            if (lvi.SubItems[0].Text == id.ToString())
                            {
                                exists = true;
                            }
                        }
                        if (!exists)
                        {
                            _vldLaptimes.Items.Add(new ListViewItem(new string[10] {
                                id.ToString(), rLaps.GetString(2),
                                rLaps.GetString(4),
                                rLaps.GetInt32(10).ToString(),
                                FormatTime(rLaps.GetDouble(6)),
                                FormatTime(rLaps.GetDouble(7)),
                                FormatTime(rLaps.GetDouble(8)),
                                FormatTime(rLaps.GetDouble(5)),
                                rLaps.GetDateTime(9).ToShortDateString() + " " + rLaps.GetDateTime(9).ToShortTimeString(),
                                rLaps.GetString(11)
                            }
                                                                    ))
                            ;
                        }
                    }
                }

            DatabaseOleDbConnectionPool.Freeup();
        }
예제 #2
0
        public Splits()
        {
            Telemetry.m.Driving_Start += m_Driving_Start;
            Telemetry.m.Driving_Stop  += m_Driving_Stop;
            Telemetry.m.Lap           += m_Lap;
            Telemetry.m.Track_Loaded  += m_Track_Loaded;

            UpdateSplitTime = new Timer {
                Interval = 50
            };
            UpdateSplitTime.Elapsed += (s, e) =>
            {
                if (Telemetry.m.Sim == null || Telemetry.m.Sim.Drivers == null || Telemetry.m.Sim.Drivers.Player == null || Telemetry.m.Sim.Modules.DistanceOnLap == false)
                {
                    return;
                }

                double MyMeters = Telemetry.m.Sim.Drivers.Player.MetersDriven;
                double MyDt     = Telemetry.m.Sim.Session.Time - Time_Start;
                double OldTime  = GetTimeFromTable(MyMeters);
                if (OldTime > 0)
                {
                    _Split.Add(MyDt - OldTime / 1000);
                }
            };

            // Trigger-once timer
            _mUpdateBestLap = new Timer {
                Interval = 2000
            };
            _mUpdateBestLap.AutoReset = true;

            // TODO: This is some quality helloween code right here.
            _mUpdateBestLap.Elapsed += (s, e) =>
            {
                bool       RemoveLapTelemetryPath = false;
                List <int> LapsToInvalidate       = new List <int>();
                if (Telemetry.m.Sim == null)
                {
                    return;
                }
                if (Telemetry.m.Sim.Drivers.Player == null)
                {
                    return;
                }
                if (Telemetry.m.Track == null)
                {
                    return;
                }
                if (Telemetry.m.Track.Name == null)
                {
                    return;
                }
                if (Telemetry.m.Net.IsClient)
                {
                    return;
                }
                try
                {
                    OleDbConnection con =
                        DatabaseOleDbConnectionPool.GetOleDbConnection();
                    using (
                        OleDbCommand times =
                            new OleDbCommand(
                                "SELECT Filepath, `ID` FROM Laptimes WHERE " +
                                "Car = '" +
                                Telemetry.m.Sim.Drivers.Player.CarModel.
                                Replace("'", "") + "' AND " +
                                "Series = '" +
                                Telemetry.m.Sim.Drivers.Player.CarClass.
                                Replace("'", "") + "' AND " +
                                "Circuit = '" +
                                Telemetry.m.Track.Name.
                                Replace("'", "") + "' AND " +
                                "Simulator = '" + Telemetry.m.Sim.Name + "' " +
                                "AND Laptime > 1 " +
                                "AND `InvalidLapData` = 0 " +
                                "ORDER BY Laptime ASC",
                                con))
                        using (OleDbDataReader times_Reader = times.ExecuteReader())
                        {
                            if (times_Reader.HasRows)
                            {
                                while (PreviousRecords == false && times_Reader.Read())
                                {
                                    int lapID = 0;
                                    try
                                    {
                                        lapID = times_Reader.GetInt32(1);
                                        _mReferenceLapReader =
                                            new TelemetryLogReader(times_Reader.GetString(0));
                                        _mReferenceLapReader.ReadPolling();
                                        PreviousRecords = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        LapsToInvalidate.Add(lapID);
                                        RemoveLapTelemetryPath = true;
                                        _mReferenceLapReader   = null;
                                    }
                                }
                            }
                        }
                    if (RemoveLapTelemetryPath)
                    {
                        while (LapsToInvalidate.Count > 0)
                        {
                            int          lapID = LapsToInvalidate[0];
                            OleDbCommand upd   =
                                new OleDbCommand(
                                    "UPDATE Laptimes SET InvalidLapData = 1 WHERE `ID` = " +
                                    lapID, con);
                            upd.ExecuteNonQuery();
                            LapsToInvalidate.RemoveAt(0);
                        }
                    }
                    DatabaseOleDbConnectionPool.Freeup();
                    Load_ExtractMetersTable();
                }catch (Exception ex)
                {
                }
            };
        }
예제 #3
0
        private void AnnotateDatabase(object o)
        {
            int LapNo = (int)o;

            Debug.WriteLine("ANNOTATING LAP " + LapNo);
            Thread.Sleep(500);
            List <ILap> AllLaps = Telemetry.m.Sim.Drivers.Player.GetLapTimes();

            if (AllLaps.Count != 0)
            {
                ILap LastLap = AllLaps.Find(delegate(ILap l) { return(l.LapNumber == LapNo); });
                if (LastLap == null)
                {
                    if (AllLaps.Count > LapNo)
                    {
                        LastLap = AllLaps[LapNo - 1];
                    }
                    else
                    {
                        LastLap = AllLaps[AllLaps.Count - 1];
                    }
                }

                try
                {
                    // TODO: This really needs a database object manager..
                    string query    = "";
                    int    splitcnt = Telemetry.m.Stats.Stats_AnnotationQuery.Split(',').Length;
                    // Normally, AnnotationQuery = "0,0,0,0,0,NOW(),-1".
                    // This contains 7 parts.
                    if (Telemetry.m.Stats.Stats_AnnotationQuery != "" &&
                        splitcnt == 7)
                    {
                        // 18 fields.
                        query =
                            "INSERT INTO laptimes (simulator,circuit,car,series,laptime,s1,s2,s3,driven,lapno,filepath,distance,enginerevs,fuelused,gearchanges,samplelength,localtime,simulatortime) " +
                            "VALUES ('" + Telemetry.m.Sim.ProcessName + "','" +
                            Telemetry.m.Track.Name.Replace("'", "") + "','" +
                            Telemetry.m.Sim.Drivers.Player.CarModel.Replace("'", "") + "','" +
                            Telemetry.m.Sim.Drivers.Player.CarClass.Replace("'", "") + "'," +
                            LastLap.LapTime + "," + LastLap.Sector1 + "," +
                            LastLap.Sector2 + "," + LastLap.Sector3 + ",NOW(), " +
                            (LapNo).ToString() +
                            ",'" + AnnotationFileCompress.Replace(".dat", ".gz") +  // field 11
                            "', " + Telemetry.m.Stats.Stats_AnnotationQuery + ");"; // +7
                    }
                    else
                    {
                        // 11
                        query =
                            "INSERT INTO laptimes (simulator,circuit,car,series,laptime,s1,s2,s3,driven,lapno,filepath) " +
                            "VALUES ('" + Telemetry.m.Sim.ProcessName + "','" +
                            Telemetry.m.Track.Name.Replace("'", "") + "','" +
                            Telemetry.m.Sim.Drivers.Player.CarModel.Replace("'", "") + "','" +
                            Telemetry.m.Sim.Drivers.Player.CarClass.Replace("'", "") + "'," +
                            LastLap.LapTime + "," + LastLap.Sector1 + "," +
                            LastLap.Sector2 + "," + LastLap.Sector3 + ",NOW(), " +
                            (LapNo).ToString() +
                            ",'" + AnnotationFileCompress.Replace(".dat", ".gz") + ");"; // field 11
                    }

                    // Insert into log
                    OleDbConnection con = DatabaseOleDbConnectionPool.GetOleDbConnection();
                    using (OleDbCommand newTime = new OleDbCommand(query, con))
                    {
                        newTime.ExecuteNonQuery();
                    }
                    DatabaseOleDbConnectionPool.Freeup();
                }
                catch (Exception Ex)
                {
                    Debug.WriteLine("Failed to insert laptime @ AnnotateDatabase");
                    Debug.WriteLine(Ex.Message);
                }
                Telemetry.m.Stats.Stats_AnnotationReset = true;
            }
        }