Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
main.py 3.56 KiB
import string

from fastf1.core import Session
from fastf1.events import Event

import DataHandler
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()

    racesToAnalyse = [
        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)
    ]

    def main(self):

        #dataHandler = Main.DataHandlingPackage()
        #dataHandler.plotter.plotBackgroundPaintTest()

        #self.testNewRainRaceFetching()

        self.printWetEvents()

        #self.overtakeAnalysis(racesToAnalyse)

    def testNewRainRaceFetching(self):
        dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage()
        weather: list[string] = dataHandler.importer.fetchWeather(self.racesToAnalyse)
        print(weather)
        for w in weather:
            isWet: bool = dataHandler.analyser.isWet(w)
            print(isWet)

    def printWetEvents(self):
        dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage()
        year: int = 2015
        wetEvents: list[Event] = dataHandler.importer.getWetEventsSince(year)
        print(f"Wet races since {year} (according to wikipedia):")
        for wetEvent in wetEvents:
            print(f"{wetEvent.year} {wetEvent["EventName"]}")


    def overtakeAnalysis(self, raceSessionIdentifiers: list[SessionIdentifier]):
        dataHandler: Main.DataHandlingPackage = self.DataHandlingPackage()

        for raceSessionIdentifier in raceSessionIdentifiers:


            # Import
            raceSession = dataHandler.importer.importSession(raceSessionIdentifier)
            grandPrixName: str = f"{raceSession.event['EventName']} {raceSession.event.year}"
            print("Import done")


            # Analyse
            overtakesInRaces: list[int] = dataHandler.analyser.getOvertakesPerLapForRace(raceSession)
            print("Overtake analysis done")
            # weatherInRaces = analyser.analyseRaceForWeather(raceSession)
            earliestTireChange: int = dataHandler.analyser.getFirstTireChange(raceSession) # first lap where someone switched from slicks to non slicks or vice versa, denoted by lap number
            print("First tire change done")
            latestTireChange: int = dataHandler.analyser.getLastTireChange(raceSession)
            print("Last tire change done")


            # Plot
            weatherChangeWindow = DataHandler.WeatherChangeWindow(earliestTireChange, latestTireChange)
            dataHandler.plotter.plotOvertakes(overtakesInRaces, grandPrixName, [weatherChangeWindow])
            print("Plot done")


            # Print data
            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()