From 285b7992ef282c378f72cfa25b6a38b767e58dd1 Mon Sep 17 00:00:00 2001 From: Lennard Geese <lennard.geese@sva.de> Date: Wed, 9 Apr 2025 19:47:27 +0200 Subject: [PATCH] Implement plotting multiple weather change windows --- DataHandler.py | 11 ++++++++++- DataPlotter.py | 9 ++++----- Todos.md | 1 + main.py | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DataHandler.py b/DataHandler.py index dcb288e..e9c8d7a 100644 --- a/DataHandler.py +++ b/DataHandler.py @@ -18,4 +18,13 @@ class SessionIdentifier: def __init__(self, year: int, event: int | str, sessionType: str = "R"): self.year = year self.event = event - self.sessionType = sessionType \ No newline at end of file + self.sessionType = sessionType + + +class WeatherChangeWindow: + firstLap: int + lastLap: int + + def __init__(self, firstTireChange: int, lastTireChange: int): + self.firstLap = firstTireChange - 1 + self.lastLap = lastTireChange + 1 \ No newline at end of file diff --git a/DataPlotter.py b/DataPlotter.py index 31bc04a..ab0be5b 100644 --- a/DataPlotter.py +++ b/DataPlotter.py @@ -7,13 +7,11 @@ import matplotlib as mpl import numpy as np from matplotlib.colors import ListedColormap -from DataHandler import DataHandler +from DataHandler import DataHandler, WeatherChangeWindow # TODO: Adjust input parameters for multiple weather change windows class DataPlotter(DataHandler): - def plotOvertakesWithTireChangeWindow(self, overtakesPerLap: list[int], firstTireChange: int, lastTireChange: int, raceName: str): - firstTireChange -= 1 - lastTireChange += 1 + def plotOvertakes(self, overtakesPerLap: list[int], raceName: str, weatherChangeWindows: list[WeatherChangeWindow] = None): # Define variables laps: int = len(overtakesPerLap) @@ -27,7 +25,8 @@ class DataPlotter(DataHandler): plt.plot(x_values, overtakesPerLap) # Paint background between first and last tire change - axis.axvspan(firstTireChange, lastTireChange, color='blue', alpha=0.3) + for weatherChangeWindow in weatherChangeWindows: + axis.axvspan(weatherChangeWindow.firstLap, weatherChangeWindow.lastLap, color='blue', alpha=0.3) # Label stuff axis.set_xlabel('Lap') diff --git a/Todos.md b/Todos.md index d34f5ff..9595957 100644 --- a/Todos.md +++ b/Todos.md @@ -3,6 +3,7 @@ - [x] Adjust for pitstop discrepancies - [x] Fetch rain races via API, not Reddit - [x] Paint back of graph for weather change window + - Also implemented for multiple weather changes - [ ] Adjust for position changes caused by crashes (keep out of calculation similarly to PCs due to pitstops ?) - [ ] Include safety car periods & driver crashes - [ ] Automatically determine if race is DWR or SWR diff --git a/main.py b/main.py index b10339d..4005197 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ from fastf1.core import Session from fastf1.events import Event +import DataHandler from DataAnalyser import DataAnalyser from DataChecker import DataChecker from DataHandler import SessionIdentifier @@ -63,7 +64,8 @@ class Main: # Plot - dataHandler.plotter.plotOvertakesWithTireChangeWindow(overtakesInRaces, earliestTireChange, latestTireChange, grandPrixName) + weatherChangeWindow = DataHandler.WeatherChangeWindow(earliestTireChange, latestTireChange) + dataHandler.plotter.plotOvertakes(overtakesInRaces, grandPrixName, [weatherChangeWindow]) print("Plot done") -- GitLab