diff --git a/DataHandler.py b/DataHandler.py index dcb288ec6148368c50118ffc14ba7fd8cd20e024..e9c8d7a95c0bd2f031ab9e22947a7b3d4367c56b 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 31bc04a59d2b1e58914839707f1e8328dc87bf59..ab0be5b401acb2dd98cfc479f6e8a870148e452b 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 d34f5ff80e1f8d10d2fd3affd8cdb7c3f45a11ec..959595799dff8b78339ca02e0aeb7343c8d890ed 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 b10339d31f5952e766579cb34f6e2d2694bc5939..40051979856bac57657244e3235bf3db49c924ed 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")