Now the SQLITE database is operationnal and is fed with driver infos
This commit is contained in:
+48
-11
@@ -23,23 +23,32 @@ namespace Test_Merge
|
||||
public List<Zone> MainZones;
|
||||
|
||||
private SqliteStorage _storage;
|
||||
private List<DriverData>[] DriverDataLogs = new List<DriverData>[NUMBER_OF_DRIVERS];
|
||||
private int[] DriverLaps = new int[NUMBER_OF_DRIVERS];
|
||||
|
||||
public SqliteStorage Storage { get => _storage; private set => _storage = value; }
|
||||
|
||||
public Reader(string configFile, Bitmap image, bool loadOCR = true)
|
||||
{
|
||||
Storage = new SqliteStorage();
|
||||
MainZones = Load(image, configFile, ref Drivers, loadOCR);
|
||||
}
|
||||
/// <summary>
|
||||
/// Method that reads the JSON config file and create all the Zones and Windows
|
||||
/// </summary>
|
||||
/// <param name="imageNumber">The image #id on wich you want to create the zones on</param>
|
||||
public static List<Zone> Load(Bitmap image, string configFilePath, ref List<string> driverListToFill, bool LoadOCR)
|
||||
public List<Zone> Load(Bitmap image, string configFilePath, ref List<string> driverListToFill, bool LoadOCR)
|
||||
{
|
||||
List<Zone> mainZones = new List<Zone>();
|
||||
Bitmap fullImage = image;
|
||||
Zone mainZone;
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_DRIVERS; i++)
|
||||
{
|
||||
DriverDataLogs[i] = new List<DriverData>();
|
||||
DriverLaps[i] = 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string jsonString = File.ReadAllText(configFilePath);
|
||||
@@ -149,7 +158,7 @@ namespace Test_Merge
|
||||
sec1El.GetProperty("y").GetInt32(),
|
||||
sec1El.GetProperty("width").GetInt32(),
|
||||
sec1El.GetProperty("height").GetInt32()),
|
||||
1,LoadOCR);
|
||||
1, LoadOCR);
|
||||
|
||||
//Sector2
|
||||
JsonElement sec2El = windowElement.GetProperty("Sector2");
|
||||
@@ -187,7 +196,9 @@ namespace Test_Merge
|
||||
JsonElement driversElement = main.GetProperty("Drivers");
|
||||
foreach (JsonElement driverElement in driversElement.EnumerateArray())
|
||||
{
|
||||
driverListToFill.Add(driverElement.GetString());
|
||||
string driverName = driverElement.GetString();
|
||||
driverListToFill.Add(driverName);
|
||||
Storage.AddDriver(driverName);
|
||||
}
|
||||
|
||||
mainZones.Add(mainZone);
|
||||
@@ -204,7 +215,7 @@ namespace Test_Merge
|
||||
foreach (Zone z in mainZones[0].Zones)
|
||||
{
|
||||
driverID++;
|
||||
z.ZoneImage.Save("LoadedDriver"+driverID+".png");
|
||||
z.ZoneImage.Save("LoadedDriver" + driverID + ".png");
|
||||
}
|
||||
return mainZones;
|
||||
}
|
||||
@@ -218,8 +229,6 @@ namespace Test_Merge
|
||||
string result = "";
|
||||
List<DriverData> mainResults = new List<DriverData>();
|
||||
|
||||
Storage = new SqliteStorage();
|
||||
|
||||
//Decode
|
||||
for (int mainZoneId = 0; mainZoneId < mainZones.Count; mainZoneId++)
|
||||
{
|
||||
@@ -227,12 +236,40 @@ namespace Test_Merge
|
||||
{
|
||||
case 0:
|
||||
//Main Zone
|
||||
//Parallel.ForEach(mainZones[mainZoneId].Zones,async (z) =>
|
||||
foreach (Zone z in mainZones[mainZoneId].Zones)
|
||||
for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++)
|
||||
{
|
||||
mainResults.Add(await z.Decode(new List<string>(drivers)));
|
||||
}//);
|
||||
//MessageBox.Show("Finished");
|
||||
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
|
||||
mainResults.Add(data);
|
||||
DriverDataLogs[i].Add(data);
|
||||
|
||||
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
|
||||
{
|
||||
//Checking if its a new lap
|
||||
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
|
||||
if (
|
||||
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
|
||||
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
|
||||
{
|
||||
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
|
||||
DriverLaps[i]++;
|
||||
Storage.AddDriverStat(stats, DriverLaps[i]);
|
||||
}
|
||||
//Checking if its a pitstop
|
||||
//If the tyre is a different counpound or if the tyre is much fresher than the older one then it must be because the driver had a pitstop
|
||||
//BE CAREFULL the last if is here because the OCR is quite weak with the number 4
|
||||
//if (data.CurrentTyre.Coumpound != DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.Coumpound
|
||||
//|| data.CurrentTyre.NumberOfLaps != DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps
|
||||
//&& data.CurrentTyre.NumberOfLaps < DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps
|
||||
//&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 3)
|
||||
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero
|
||||
if(data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0)
|
||||
{
|
||||
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString());
|
||||
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop
|
||||
}
|
||||
}
|
||||
DriverDataLogs[i].Add(data);
|
||||
}
|
||||
break;
|
||||
//Next there could be a Title Zone and TrackInfoZone
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user