Fixed the slowest drivers windows and cleaned some of the code

This commit is contained in:
2023-05-30 09:38:51 +02:00
parent 6f36c829c2
commit 067e7233a0
16 changed files with 221 additions and 70 deletions
+45 -1
View File
@@ -1,4 +1,10 @@
using System;
/// Author : Maxime Rohmer
/// Date : 30/05/2023
/// File : SqliteStorage.cs
/// Brief : Class that controls the sqlite database
/// Version : Alpha 1.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -16,10 +22,16 @@ namespace Test_Merge
private const string CONNECTION_STRING = "Data Source=" + DATABASE_FOLDER + DATABASE_FILE + ";Version=3;";
private SQLiteConnection Connection;
/// <summary>
/// Creates a new Sqlite Storage and initialize the database
/// </summary>
public SqliteStorage()
{
Load();
}
/// <summary>
/// Loads a fresh new Database or create a new one if it does not exist.
/// </summary>
private void Load()
{
if (!Directory.Exists(DATABASE_FOLDER))
@@ -75,6 +87,10 @@ namespace Test_Merge
command.ExecuteNonQuery();
}
}
/// <summary>
/// Adds a driver into the drivers table. Meant to be used at the start of the programm
/// </summary>
/// <param name="name">The name of the driver. (non case sensitive)</param>
public void AddDriver(string name)
{
string insertQuery = "INSERT INTO Drivers (Name) VALUES (@name);";
@@ -93,6 +109,11 @@ namespace Test_Merge
}
}
}
/// <summary>
/// Searches for a driver and returns its id if it has been found
/// </summary>
/// <param name="name">Name of the driver (non case sensitive)</param>
/// <returns></returns>
private int GetDriverID(string name)
{
string selectQuery = "SELECT ID FROM Drivers where Name LIKE @driverName";
@@ -117,6 +138,12 @@ namespace Test_Merge
}
return result;
}
/// <summary>
/// Gets the sectors from a lapTime. Sectors are subdivisions of a laptime (could be usefull to validate one or the other)
/// </summary>
/// <param name="driverName">The name of the driver who has done the lap</param>
/// <param name="lap">The lap at wich the driver has done the time</param>
/// <returns>A list of the different sectors time in int (ms)</returns>
public List<int> GetSectorsFromLapTime(string driverName,int lap)
{
int driverId = GetDriverID(driverName);
@@ -143,6 +170,12 @@ namespace Test_Merge
}
return result;
}
/// <summary>
/// Get the laptime history of a driver
/// </summary>
/// <param name="driverName">The name of the driver</param>
/// <param name="numberOfLaptimes">The number of lapTimes you want</param>
/// <returns>A list of tuples with the lap and the laptime. It will only return the amount it found so even if you ask 5 expect getting less or even 0</returns>
public List<(int LapTime, int Lap)> GetDriverLaptimes(string driverName,int numberOfLaptimes)
{
int driverId = GetDriverID(driverName);
@@ -169,6 +202,12 @@ namespace Test_Merge
}
return lapData;
}
/// <summary>
/// Add a pitstop into the db
/// </summary>
/// <param name="driverName">The name of the driver who made his pitstop</param>
/// <param name="lap">The lap where he stopped</param>
/// <param name="tyre">The tyre he took out</param>
public void AddPitstop(string driverName,int lap,string tyre)
{
string insertQuery = "INSERT INTO Pitstops (Lap,DriverID,Tyre) VALUES (@Lap,@DriverID,@Tyre)";
@@ -188,6 +227,11 @@ namespace Test_Merge
}
}
}
/// <summary>
/// Adds drivers info into the DB (it should only be once per lap)
/// </summary>
/// <param name="data">The Driver data</param>
/// <param name="lap">The lap from wich the datas are from</param>
public void AddDriverStat(DriverData data,int lap)
{
string insertQuery = "INSERT INTO Stats (Lap,DriverID,Tyre,LapTime,Sector1,Sector2,Sector3,GapToLeader,Position) VALUES (@Lap,@DriverID,@Tyre,@LapTime,@Sector1,@Sector2,@Sector3,@GapToLeader,@Position);";