Now you can see the five slowest and five fastest drivers

This commit is contained in:
2023-05-24 16:06:27 +02:00
parent e8028528e0
commit 03130f6c42
4 changed files with 107 additions and 35 deletions

View File

@@ -151,6 +151,64 @@ namespace Test_Merge
}
}
}
public void DisplayTimesDeltas(Panel pnlFastest,Panel pnlSlowest, Form1 form1)
{
List<(int avg, string driverName)> averages = new List<(int avg, string driverName)>();
foreach (DriverData driver in LiveDriverDataLogs[LiveDriverDataLogs.Count - 1])
{
//We want to recover the last 5 lap times
List<(int lapTime,int lap)> laps = Storage.GetDriverLaptimes(driver.Name,5);
if(laps.Count > 0)
{
int avg = 0;
foreach ((int lapTime, int lap) lap in laps)
{
avg += lap.lapTime;
}
avg = avg / laps.Count;
averages.Add((avg, driver.Name));
}
}
int numberOfDriversToShow = 5;
if (averages.Count > 0 && averages.Count > numberOfDriversToShow)
{
averages = averages.OrderBy(item => item.avg).ToList();
pnlFastest.Controls.Clear();
pnlSlowest.Controls.Clear();
int maxUiSize = pnlFastest.Height / numberOfDriversToShow;
for (int i = 0; i < numberOfDriversToShow; i++)
{
Button newButton = new Button();
(int avg, string driver) data = averages[i];
pnlFastest.Controls.Add(newButton);
newButton.Size = new Size(pnlFastest.Width, maxUiSize);
newButton.Location = new Point(0, i * maxUiSize);
newButton.Text = data.driver;
newButton.Name = data.driver + "_fastest_" + i;
newButton.Click += form1.btnDriver_Click;
//We take the average time lost per lap
if (i != 0)
newButton.Text += " + " + Reader.ConvertMsToTime(Convert.ToInt32(((float)data.avg - (float)averages[0].avg) / 5.0f));
}
int badId = 0;
for (int i = averages.Count -1; i >= averages.Count - numberOfDriversToShow; i--)
{
Button newButton = new Button();
(int avg, string driver) data = averages[i];
pnlSlowest.Controls.Add(newButton);
newButton.Size = new Size(pnlFastest.Width, maxUiSize);
newButton.Location = new Point(0, badId * maxUiSize);
newButton.Text = data.driver;
newButton.Name = data.driver + "_slowest_" + i;
newButton.Click += form1.btnDriver_Click;
//We take the average time lost per lap
newButton.Text += " + " + Reader.ConvertMsToTime(Convert.ToInt32(((float)data.avg) - (float)averages[0].avg / 5.0f));
badId++;
}
}
}
public void DisplayLapTimeInfos(string driverName, int Lap, string LapTime)
{
List<int> sectors = Storage.GetSectorsFromLapTime(driverName, Lap);

View File

@@ -40,7 +40,6 @@
this.gpbxRanking = new System.Windows.Forms.GroupBox();
this.pnlLiveRanking = new System.Windows.Forms.Panel();
this.gpbxOvertakes = new System.Windows.Forms.GroupBox();
this.pnlOvertakes = new System.Windows.Forms.Panel();
this.gpbxDriverInfos = new System.Windows.Forms.GroupBox();
this.lblCurrentDriverPosition = new System.Windows.Forms.Label();
this.lblCurrentDriverDRS = new System.Windows.Forms.Label();
@@ -58,10 +57,11 @@
this.gpbxLapTimes = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.pnlLosingTime = new System.Windows.Forms.Panel();
this.pnlGainingTime = new System.Windows.Forms.Panel();
this.pnlSlowest = new System.Windows.Forms.Panel();
this.pnlFastest = new System.Windows.Forms.Panel();
this.gpbxBattles = new System.Windows.Forms.GroupBox();
this.pnlBattles = new System.Windows.Forms.Panel();
this.lsbOvertakes = new System.Windows.Forms.ListBox();
((System.ComponentModel.ISupportInitialize)(this.pbxResult)).BeginInit();
this.gpbxControls.SuspendLayout();
this.gpbxRanking.SuspendLayout();
@@ -185,7 +185,7 @@
//
// gpbxOvertakes
//
this.gpbxOvertakes.Controls.Add(this.pnlOvertakes);
this.gpbxOvertakes.Controls.Add(this.lsbOvertakes);
this.gpbxOvertakes.Location = new System.Drawing.Point(987, 12);
this.gpbxOvertakes.Name = "gpbxOvertakes";
this.gpbxOvertakes.Size = new System.Drawing.Size(287, 342);
@@ -193,13 +193,6 @@
this.gpbxOvertakes.TabStop = false;
this.gpbxOvertakes.Text = "Overtakes";
//
// pnlOvertakes
//
this.pnlOvertakes.Location = new System.Drawing.Point(6, 21);
this.pnlOvertakes.Name = "pnlOvertakes";
this.pnlOvertakes.Size = new System.Drawing.Size(275, 315);
this.pnlOvertakes.TabIndex = 2;
//
// gpbxDriverInfos
//
this.gpbxDriverInfos.Controls.Add(this.lblCurrentDriverPosition);
@@ -353,46 +346,46 @@
//
this.gpbxLapTimes.Controls.Add(this.label3);
this.gpbxLapTimes.Controls.Add(this.label2);
this.gpbxLapTimes.Controls.Add(this.pnlLosingTime);
this.gpbxLapTimes.Controls.Add(this.pnlGainingTime);
this.gpbxLapTimes.Controls.Add(this.pnlSlowest);
this.gpbxLapTimes.Controls.Add(this.pnlFastest);
this.gpbxLapTimes.Location = new System.Drawing.Point(371, 12);
this.gpbxLapTimes.Name = "gpbxLapTimes";
this.gpbxLapTimes.Size = new System.Drawing.Size(610, 239);
this.gpbxLapTimes.TabIndex = 11;
this.gpbxLapTimes.TabStop = false;
this.gpbxLapTimes.Text = "Driver infos";
this.gpbxLapTimes.Text = "Last five laps";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(311, 14);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(75, 16);
this.label3.Size = new System.Drawing.Size(54, 16);
this.label3.TabIndex = 3;
this.label3.Text = "Losing time";
this.label3.Text = "Slowest";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 14);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(81, 16);
this.label2.Size = new System.Drawing.Size(51, 16);
this.label2.TabIndex = 2;
this.label2.Text = "Gaining time";
this.label2.Text = "Fastest";
//
// pnlLosingTime
// pnlSlowest
//
this.pnlLosingTime.Location = new System.Drawing.Point(314, 33);
this.pnlLosingTime.Name = "pnlLosingTime";
this.pnlLosingTime.Size = new System.Drawing.Size(290, 200);
this.pnlLosingTime.TabIndex = 1;
this.pnlSlowest.Location = new System.Drawing.Point(314, 33);
this.pnlSlowest.Name = "pnlSlowest";
this.pnlSlowest.Size = new System.Drawing.Size(290, 200);
this.pnlSlowest.TabIndex = 1;
//
// pnlGainingTime
// pnlFastest
//
this.pnlGainingTime.Location = new System.Drawing.Point(6, 33);
this.pnlGainingTime.Name = "pnlGainingTime";
this.pnlGainingTime.Size = new System.Drawing.Size(290, 200);
this.pnlGainingTime.TabIndex = 0;
this.pnlFastest.Location = new System.Drawing.Point(6, 33);
this.pnlFastest.Name = "pnlFastest";
this.pnlFastest.Size = new System.Drawing.Size(290, 200);
this.pnlFastest.TabIndex = 0;
//
// gpbxBattles
//
@@ -411,6 +404,15 @@
this.pnlBattles.Size = new System.Drawing.Size(595, 171);
this.pnlBattles.TabIndex = 2;
//
// lsbOvertakes
//
this.lsbOvertakes.FormattingEnabled = true;
this.lsbOvertakes.ItemHeight = 16;
this.lsbOvertakes.Location = new System.Drawing.Point(6, 21);
this.lsbOvertakes.Name = "lsbOvertakes";
this.lsbOvertakes.Size = new System.Drawing.Size(274, 308);
this.lsbOvertakes.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
@@ -454,7 +456,6 @@
private System.Windows.Forms.GroupBox gpbxRanking;
private System.Windows.Forms.Panel pnlLiveRanking;
private System.Windows.Forms.GroupBox gpbxOvertakes;
private System.Windows.Forms.Panel pnlOvertakes;
private System.Windows.Forms.GroupBox gpbxDriverInfos;
private System.Windows.Forms.Label lblCurrentDriverPosition;
private System.Windows.Forms.Label lblCurrentDriverDRS;
@@ -472,10 +473,11 @@
private System.Windows.Forms.GroupBox gpbxLapTimes;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel pnlLosingTime;
private System.Windows.Forms.Panel pnlGainingTime;
private System.Windows.Forms.Panel pnlSlowest;
private System.Windows.Forms.Panel pnlFastest;
private System.Windows.Forms.GroupBox gpbxBattles;
private System.Windows.Forms.Panel pnlBattles;
private System.Windows.Forms.ListBox lsbOvertakes;
}
}

View File

@@ -117,6 +117,7 @@ namespace Test_Merge
{
DisplayResults(errorCode, sw, screen);
DisplayBattles();
DisplayDeltas();
});
});
}
@@ -137,6 +138,10 @@ namespace Test_Merge
{
Wrapper.DisplayBattles(pnlBattles,this);
}
private void DisplayDeltas()
{
Wrapper.DisplayTimesDeltas(pnlFastest,pnlSlowest,this);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (Emulator != null)

View File

@@ -328,10 +328,17 @@ namespace Test_Merge
{
if (rawNumbers[1].Length == 6)
{
//It has been interpreted as a number
minuts = Convert.ToInt32(rawNumbers[0].ToString());
seconds = Convert.ToInt32(rawNumbers[1][0].ToString() + rawNumbers[1][1].ToString());
miliseconds = Convert.ToInt32(rawNumbers[1][3].ToString() + rawNumbers[1][4].ToString() + rawNumbers[1][5].ToString());
try
{
//It has been interpreted as a number
minuts = Convert.ToInt32(rawNumbers[0].ToString());
seconds = Convert.ToInt32(rawNumbers[1][0].ToString() + rawNumbers[1][1].ToString());
miliseconds = Convert.ToInt32(rawNumbers[1][3].ToString() + rawNumbers[1][4].ToString() + rawNumbers[1][5].ToString());
}
catch
{
//It can happen and to be honest I dont know how to fix it
}
}
else
{