slightly improved the Emulator
This commit is contained in:
@@ -208,9 +208,9 @@ namespace Test_Merge
|
||||
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
|
||||
//Clicks on the settings Icon
|
||||
|
||||
int tries = 0;
|
||||
bool success = false;
|
||||
while (tries < 100 && !success)
|
||||
int settingsClickTries = 0;
|
||||
bool settingsClickSuccess = false;
|
||||
while (settingsClickTries < 100 && !settingsClickSuccess)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
try
|
||||
@@ -221,39 +221,47 @@ namespace Test_Merge
|
||||
SelectElement select = new SelectElement(selectElement);
|
||||
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
|
||||
selectOption.Click();
|
||||
success = true;
|
||||
settingsClickSuccess = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Sometimes it can crash because it could not get the options to show up in time. When it happens just retry
|
||||
success = false;
|
||||
tries++;
|
||||
settingsClickSuccess = false;
|
||||
settingsClickTries++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
if (!settingsClickSuccess)
|
||||
{
|
||||
Screenshot("ERROR105");
|
||||
Driver.Dispose();
|
||||
return 105;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
Screenshot("BEFOREFULLSCREEN");
|
||||
|
||||
//Makes the feed fullscreen
|
||||
//Driver.Manage().Window.Size = new System.Drawing.Size(windowWidth, windowHeight);
|
||||
int fullScreenClickTries = 0;
|
||||
bool fullScreenClickSuccess = false;
|
||||
Driver.Manage().Window.Maximize();
|
||||
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
|
||||
try
|
||||
//WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
|
||||
while (fullScreenClickTries < 100 && !fullScreenClickSuccess)
|
||||
{
|
||||
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
|
||||
fullScreenButton.Click();
|
||||
Thread.Sleep(150);
|
||||
try
|
||||
{
|
||||
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
|
||||
fullScreenButton.Click();
|
||||
fullScreenClickSuccess = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
fullScreenClickSuccess = false;
|
||||
fullScreenClickTries++;
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
if (!fullScreenClickSuccess)
|
||||
{
|
||||
Screenshot("ERROR106");
|
||||
Driver.Dispose();
|
||||
|
||||
@@ -235,39 +235,48 @@ namespace Test_Merge
|
||||
switch (mainZoneId)
|
||||
{
|
||||
case 0:
|
||||
//object lockObject = new object();
|
||||
//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++)
|
||||
{
|
||||
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)
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
//Tries to fix the tyres
|
||||
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;
|
||||
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
|
||||
|
||||
//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
|
||||
//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);
|
||||
//lock (lockObject)
|
||||
//{
|
||||
mainResults.Add(data);
|
||||
DriverDataLogs[i].Add(data);
|
||||
|
||||
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
|
||||
{
|
||||
//Tries to fix the tyres
|
||||
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
|
||||
//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.
|
||||
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
|
||||
//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
|
||||
@@ -285,7 +294,7 @@ namespace Test_Merge
|
||||
}
|
||||
//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
|
||||
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 "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user