slightly improved the Emulator

This commit is contained in:
2023-05-22 11:29:44 +02:00
parent e650072213
commit 66906cb54e
2 changed files with 63 additions and 46 deletions
+25 -17
View File
@@ -208,9 +208,9 @@ namespace Test_Merge
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform(); actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
//Clicks on the settings Icon //Clicks on the settings Icon
int tries = 0; int settingsClickTries = 0;
bool success = false; bool settingsClickSuccess = false;
while (tries < 100 && !success) while (settingsClickTries < 100 && !settingsClickSuccess)
{ {
Thread.Sleep(100); Thread.Sleep(100);
try try
@@ -221,39 +221,47 @@ namespace Test_Merge
SelectElement select = new SelectElement(selectElement); SelectElement select = new SelectElement(selectElement);
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']")); IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
selectOption.Click(); selectOption.Click();
success = true; settingsClickSuccess = true;
} }
catch catch
{ {
//Sometimes it can crash because it could not get the options to show up in time. When it happens just retry //Sometimes it can crash because it could not get the options to show up in time. When it happens just retry
success = false; settingsClickSuccess = false;
tries++; settingsClickTries++;
} }
} }
if (!success) if (!settingsClickSuccess)
{ {
Screenshot("ERROR105"); Screenshot("ERROR105");
Driver.Dispose(); Driver.Dispose();
return 105; return 105;
} }
else
{
Thread.Sleep(3000);
}
Screenshot("BEFOREFULLSCREEN"); Screenshot("BEFOREFULLSCREEN");
//Makes the feed fullscreen //Makes the feed fullscreen
//Driver.Manage().Window.Size = new System.Drawing.Size(windowWidth, windowHeight); int fullScreenClickTries = 0;
bool fullScreenClickSuccess = false;
Driver.Manage().Window.Maximize(); Driver.Manage().Window.Maximize();
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10)); //WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
try while (fullScreenClickTries < 100 && !fullScreenClickSuccess)
{ {
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton")); Thread.Sleep(150);
fullScreenButton.Click(); try
{
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
fullScreenButton.Click();
fullScreenClickSuccess = true;
}
catch
{
fullScreenClickSuccess = false;
fullScreenClickTries++;
}
} }
catch
if (!fullScreenClickSuccess)
{ {
Screenshot("ERROR106"); Screenshot("ERROR106");
Driver.Dispose(); Driver.Dispose();
+38 -29
View File
@@ -235,39 +235,48 @@ namespace Test_Merge
switch (mainZoneId) switch (mainZoneId)
{ {
case 0: case 0:
//object lockObject = new object();
//Main Zone //Main Zone
//Parallel.For(0, mainZones[mainZoneId].Zones.Count,async i => //Parallel.For(0, mainZones[mainZoneId].Zones.Count, async i =>
for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++) for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++)
{ {
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers)); await Task.Run(async () =>
mainResults.Add(data);
DriverDataLogs[i].Add(data);
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
{ {
//Tries to fix the tyres DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
//Checking if its a new lap //lock (lockObject)
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started //{
if ( mainResults.Add(data);
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0 DriverDataLogs[i].Add(data);
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
{ if (data.Position != -1 && DriverDataLogs[i].Count > 1)
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2]; {
DriverLaps[i]++; //Tries to fix the tyres
Storage.AddDriverStat(stats, DriverLaps[i]); if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
} data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
//Checking if its a pitstop
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero //Checking if its a new lap
if (data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0) //If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
{ //Lap detection can be f***ed if the OCR takes so much time that an entire sector can be raced without us knowing.
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString()); if (
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
} && DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
} {
DriverDataLogs[i].Add(data); DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
DriverLaps[i]++;
Storage.AddDriverStat(stats, DriverLaps[i]);
}
//Checking if its a pitstop
//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; break;
//Next there could be a Title Zone and TrackInfoZone //Next there could be a Title Zone and TrackInfoZone
@@ -285,7 +294,7 @@ namespace Test_Merge
} }
//If 75% or more of the drivers cannot be decoded there must be a problem somewhere. //If 75% or more of the drivers cannot be decoded there must be a problem somewhere.
//Some can be because if they are out of the race usually the OCR returns -1 as the driver position //Some can be because if they are out of the race usually the OCR returns -1 as the driver position
if (nullDrivers >= Convert.ToInt32((float)NUMBER_OF_DRIVERS / 4.0f * 3.0f)) if (nullDrivers >= Convert.ToInt32((float)NUMBER_OF_DRIVERS / 4.0f * 3.0f) || mainResults.Count == 0)
{ {
return ""; return "";
} }