Newer
Older
from fastf1.core import Session
from DataAnalyser import DataAnalyser
from DataChecker import DataChecker
from DataHandler import SessionIdentifier
from DataImporter import DataImporter
from DataPlotter import DataPlotter
class Main:
class DataHandlingPackage:
importer = DataImporter()
analyser = DataAnalyser()
plotter = DataPlotter()
checker = DataChecker()
#dataHandler = Main.DataHandlingPackage()
#dataHandler.plotter.plotBackgroundPaintTest()
# self.printRainRaces()
SessionIdentifier(2022, "Imola", "R"), # Imola 2022 (DWR)
SessionIdentifier(2024, "Imola", "R"), # Imola 2024 (SWR)
SessionIdentifier(2024, "Montreal", "R"), # Canada 2024 (DWR)
SessionIdentifier(2023, "Montreal", "R") # Canada 2023 (SWR)
self.overtakeAnalysis(racesToAnalyse)
def printRainRaces(self):
dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage()
year: int = 2015
rainRaces: list[Session] = dataHandler.importer.getRainRacesSince(year)
print(f"Rain races since {max(year, 2018)}")
for rainRace in rainRaces:
print(rainRace)
def overtakeAnalysis(self, raceSessionIdentifiers: list[SessionIdentifier]):
dataHandler: Main.DataHandlingPackage = self.DataHandlingPackage()
for raceSessionIdentifier in raceSessionIdentifiers:
raceSession = dataHandler.importer.importSession(raceSessionIdentifier)
grandPrixName: str = f"{raceSession.event['EventName']} {raceSession.event.year}"
overtakesInRaces: list[int] = dataHandler.analyser.getOvertakesPerLapForRace(raceSession)
print("Overtake analysis done")
# weatherInRaces = analyser.analyseRaceForWeather(raceSession)
earliestTireChange: int = dataHandler.analyser.getEarliestTireChange(raceSession) # first lap where someone switched from slicks to non slicks or vice versa, denoted by lap number
latestTireChange: int = dataHandler.analyser.getLatestTireChange(raceSession)
weatherChangeWindow = DataHandler.WeatherChangeWindow(earliestTireChange, latestTireChange)
dataHandler.plotter.plotOvertakes(overtakesInRaces, grandPrixName, [weatherChangeWindow])
print("Plot done")
print(f"\n\n===== Data for {grandPrixName} =====")
print("Lap\tOvertakes")
currentLap = 0
for overtakesInLap in overtakesInRaces:
print(f"{currentLap}\t{overtakesInLap}")
currentLap += 1
print(f"First tire compound: lap {earliestTireChange}")
print(f"Last tire compound: lap {latestTireChange}")
print(f"Weather change window is therefore: laps {earliestTireChange-1} - {latestTireChange+1}")
if __name__ == '__main__':
app = Main()
app.main()