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
+58
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);