Improved functionnality of the main form
This commit is contained in:
@@ -237,6 +237,10 @@ namespace Test_Merge
|
||||
Driver.Dispose();
|
||||
return 105;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
Screenshot("BEFOREFULLSCREEN");
|
||||
|
||||
|
||||
15
Test_Merge/Form1.Designer.cs
generated
15
Test_Merge/Form1.Designer.cs
generated
@@ -33,6 +33,7 @@
|
||||
this.btnStartDecoding = new System.Windows.Forms.Button();
|
||||
this.pbxResult = new System.Windows.Forms.PictureBox();
|
||||
this.btnStopUpdating = new System.Windows.Forms.Button();
|
||||
this.btnResetEmulator = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pbxResult)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -84,11 +85,22 @@
|
||||
this.btnStopUpdating.UseVisualStyleBackColor = true;
|
||||
this.btnStopUpdating.Click += new System.EventHandler(this.btnStopUpdating_Click);
|
||||
//
|
||||
// btnResetEmulator
|
||||
//
|
||||
this.btnResetEmulator.Location = new System.Drawing.Point(336, 12);
|
||||
this.btnResetEmulator.Name = "btnResetEmulator";
|
||||
this.btnResetEmulator.Size = new System.Drawing.Size(162, 53);
|
||||
this.btnResetEmulator.TabIndex = 5;
|
||||
this.btnResetEmulator.Text = "Reset emulator";
|
||||
this.btnResetEmulator.UseVisualStyleBackColor = true;
|
||||
this.btnResetEmulator.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 335);
|
||||
this.ClientSize = new System.Drawing.Size(799, 335);
|
||||
this.Controls.Add(this.btnResetEmulator);
|
||||
this.Controls.Add(this.btnStopUpdating);
|
||||
this.Controls.Add(this.pbxResult);
|
||||
this.Controls.Add(this.btnStartDecoding);
|
||||
@@ -111,6 +123,7 @@
|
||||
private System.Windows.Forms.Button btnStartDecoding;
|
||||
private System.Windows.Forms.PictureBox pbxResult;
|
||||
private System.Windows.Forms.Button btnStopUpdating;
|
||||
private System.Windows.Forms.Button btnResetEmulator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
|
||||
namespace Test_Merge
|
||||
{
|
||||
@@ -16,6 +18,10 @@ namespace Test_Merge
|
||||
Reader Reader = null;
|
||||
F1TVEmulator Emulator = null;
|
||||
private bool cancelRequested = false;
|
||||
private SemaphoreSlim semaphore = new SemaphoreSlim(1);
|
||||
|
||||
string ConfigFile = "";
|
||||
string GpUrl = "";
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -23,7 +29,7 @@ namespace Test_Merge
|
||||
}
|
||||
public async void RefreshUI()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
private async void btnSettings_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -31,28 +37,29 @@ namespace Test_Merge
|
||||
Settings settingsForm = new Settings();
|
||||
settingsForm.ShowDialog();
|
||||
//MessageBox.Show(settingsForm.GrandPrixUrl + Environment.NewLine + settingsForm.GrandPrixName + Environment.NewLine + settingsForm.GrandPrixYear);
|
||||
Emulator = new F1TVEmulator(settingsForm.GrandPrixUrl);
|
||||
try
|
||||
if(settingsForm.GrandPrixUrl != "" && settingsForm.SelectedConfigFile != "")
|
||||
{
|
||||
await Emulator.Start();
|
||||
Reader = new Reader(settingsForm.SelectedConfigFile, Emulator.Screenshot(), true);
|
||||
GpUrl = settingsForm.GrandPrixUrl;
|
||||
if (File.Exists(settingsForm.SelectedConfigFile))
|
||||
{
|
||||
ConfigFile = settingsForm.SelectedConfigFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("The config file has not been found please return to the config and change it");
|
||||
}
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
//Could not start the driver even with the new config
|
||||
MessageBox.Show("The config is wrong or incomplete please try again");
|
||||
MessageBox.Show("There is no URL for the Grand Prix you want to decode. Please return to the config and add a valid one");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
string configFile = "./Presets/Clean_4K_2023.json";
|
||||
string gpUrl = "https://f1tv.formula1.com/detail/1000006688/2023-azerbaijan-grand-prix?action=play";
|
||||
|
||||
Emulator = new F1TVEmulator(gpUrl);
|
||||
await Emulator.Start();
|
||||
Reader = new Reader(configFile, Emulator.Screenshot(), true);
|
||||
//Those are the default values but they will need to be changed later when the configuration has been done
|
||||
ConfigFile = "./Presets/Clean_4K_2023.json";
|
||||
GpUrl = "https://f1tv.formula1.com/detail/1000006688/2023-azerbaijan-grand-prix?action=play";
|
||||
}
|
||||
|
||||
private async void btnUpdate_Click(object sender, EventArgs e)
|
||||
@@ -66,24 +73,33 @@ namespace Test_Merge
|
||||
btnSettings.Enabled = false;
|
||||
while (!cancelRequested)
|
||||
{
|
||||
// Start the time-consuming task on a separate thread
|
||||
await Task.Run(async () =>
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
Bitmap screen = Emulator.Screenshot();
|
||||
screen.Save("SCREEEEEEEEN.png");
|
||||
Reader.ChangeImage(screen);
|
||||
|
||||
string result = await Reader.Decode(Reader.MainZones, Reader.Drivers);
|
||||
sw.Stop();
|
||||
// Task completed
|
||||
Invoke((MethodInvoker)delegate
|
||||
// Start the time-consuming task on a separate thread
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
DisplayResults(result, sw, screen);
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
Bitmap screen = Emulator.Screenshot();
|
||||
screen.Save("HopefullyDataScreenshot.png");
|
||||
Reader.ChangeImage(screen);
|
||||
|
||||
string result = await Reader.Decode(Reader.MainZones, Reader.Drivers);
|
||||
sw.Stop();
|
||||
// Task completed
|
||||
Invoke((MethodInvoker)delegate
|
||||
{
|
||||
DisplayResults(result, sw, screen);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
// Re-enable UI controls
|
||||
btnStartDecoding.Enabled = true;
|
||||
@@ -98,12 +114,20 @@ namespace Test_Merge
|
||||
Emulator.Stop();
|
||||
}
|
||||
}
|
||||
private void DisplayResults(string result,Stopwatch sw,Bitmap screen)
|
||||
private void DisplayResults(string result, Stopwatch sw, Bitmap screen)
|
||||
{
|
||||
tbxResult.Text = "";
|
||||
tbxResult.Text = "Decoding done in :" + sw.ElapsedMilliseconds + "ms" + Environment.NewLine;
|
||||
tbxResult.Text += result;
|
||||
pbxResult.Image = screen;
|
||||
if (result == "")
|
||||
{
|
||||
cancelRequested = true;
|
||||
MessageBox.Show("An error has occured while trying to recover data from live feed. This can happen sometimes. I would advise you to restart a few times. If the problem persists check your configuration.");
|
||||
}
|
||||
else
|
||||
{
|
||||
tbxResult.Text = "";
|
||||
tbxResult.Text = "Decoding done in :" + sw.ElapsedMilliseconds + "ms" + Environment.NewLine;
|
||||
tbxResult.Text += result;
|
||||
pbxResult.Image = screen;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStopUpdating_Click(object sender, EventArgs e)
|
||||
@@ -111,5 +135,39 @@ namespace Test_Merge
|
||||
// Set the cancellation flag
|
||||
cancelRequested = true;
|
||||
}
|
||||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnResetEmulator.Enabled = false;
|
||||
btnSettings.Enabled = false;
|
||||
btnStartDecoding.Enabled = false;
|
||||
btnStopUpdating.Enabled = false;
|
||||
int errorCode = -1;
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (Emulator != null)
|
||||
Emulator.ResetDriver();
|
||||
|
||||
Emulator = null;
|
||||
Reader = null;
|
||||
|
||||
Emulator = new F1TVEmulator(GpUrl);
|
||||
errorCode = await Emulator.Start();
|
||||
});
|
||||
|
||||
if (errorCode != 0)
|
||||
{
|
||||
//IMPLEMENT MORE SPECIFIC ERROR CODES !!
|
||||
MessageBox.Show("An error has occured while trying to start the driver.");
|
||||
btnResetEmulator.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Reader = new Reader(ConfigFile, Emulator.Screenshot(), true);
|
||||
btnResetEmulator.Enabled = true;
|
||||
btnSettings.Enabled = true;
|
||||
btnStartDecoding.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Test_Merge
|
||||
//outputBitmap.Save(Window.STRING_DEBUG_FOLDER + @"\Final_treshold_" + id + ".png");
|
||||
break;
|
||||
case WindowType.Tyre:
|
||||
outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\raw_" + id + ".png");
|
||||
//outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\raw_" + id + ".png");
|
||||
|
||||
outputBitmap = RemoveUseless(outputBitmap);
|
||||
//outputBitmap.Save(Window.TYRE_DEBUG_FOLDER + @"\uselessRemoved_" + id + ".png");
|
||||
|
||||
@@ -236,6 +236,7 @@ namespace Test_Merge
|
||||
{
|
||||
case 0:
|
||||
//Main Zone
|
||||
//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));
|
||||
@@ -259,34 +260,39 @@ namespace Test_Merge
|
||||
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)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
//Display
|
||||
int nullDrivers = 0;
|
||||
foreach (DriverData driver in mainResults)
|
||||
{
|
||||
if (driver.Position == -1 && driver.LapTime == 0)
|
||||
nullDrivers++;
|
||||
result += driver.ToString();
|
||||
result += Environment.NewLine;
|
||||
}
|
||||
|
||||
return result;
|
||||
//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))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeImage(Bitmap Image)
|
||||
|
||||
Reference in New Issue
Block a user