diff --git a/DataAnalyser.py b/DataAnalyser.py index db90be62c06ed7ce267adf14b628664baa8db586..940848d7f3e0eaab06a946ffa6a5ecf9e2cd4532 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -1,5 +1,5 @@ import pandas as pandas -from fastf1.core import Session, Lap, Laps +from fastf1.core import Session, Lap, Laps, DataNotLoadedError from DataHandler import DataHandler, SessionIdentifier @@ -117,12 +117,28 @@ class DataAnalyser(DataHandler): # ===== Weather ===== - def filterForWetSessions(self, sessions: list[Session]): - x = 0 - + def filterForRainSessions(self, sessions: list[Session]): + ''' + Filter out & return only those sessions from input list that had rain falling at any point during the session. + Note: The sessions returned are not necessarily sessions that had wet conditions for any meaningful amount of + time. Also, sessions that had wet conditions only from leftover rainwater on track are not included in the + returned sessions, as no rain occured during the session. This is due to technical limitations. + :param sessions: List of sessions from which to pick out sessions with rain. + :return: List of sessions which had rain falling during the session for any amount of time. + ''' - return sessions + rainSessions: list[Session] = [] + for session in sessions: + try: + for rainfallEntry in session.weather_data["Rainfall"]: + if rainfallEntry is True: + rainSessions.append(session) + break + except DataNotLoadedError: + raise DataNotLoadedError(f"Weather data not loaded for session {session}") + + return rainSessions diff --git a/DataImporter.py b/DataImporter.py index 7fe764778dcfd92983bf2f5916bc38c436426ece..ab523e2d224da71b1554533434cfbcab8a1ebe64 100644 --- a/DataImporter.py +++ b/DataImporter.py @@ -67,6 +67,6 @@ class DataImporter(DataHandler, ABC): print(f"Weather for {event["EventName"]} {event.year} could not be determined") analyser: DataAnalyser = DataAnalyser() - rainRaces: list[Session] = analyser.filterForWetSessions(races) + rainRaces: list[Session] = analyser.filterForRainSessions(races) return rainRaces \ No newline at end of file diff --git a/Todos.md b/Todos.md index 1231d7f76bb3cc6951cef8fcaea14c5af872e160..e6eb65e421ae0a4ed4e2956fdbbc70b02453b224 100644 --- a/Todos.md +++ b/Todos.md @@ -1,7 +1,7 @@ # Todos (sorted by priority) - [x] Automatically title graph by race name (no more hardcoding the graph name) - [x] Adjust for pitstop discrepancies -- [ ] Fetch rain races via API, not Reddit +- [x] Fetch rain races via API, not Reddit - [ ] 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 77cbe18a6f5c73a2abbb90b0d34ee494459126b3..d462a51578968cb2bd40b5b42a37a0247bbdeffa 100644 --- a/main.py +++ b/main.py @@ -19,8 +19,11 @@ class Main: def main(self): dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage() - rainRaces: list[Session] = dataHandler.importer.getRainRacesSince(2015) - + year: int = 2015 + rainRaces: list[Session] = dataHandler.importer.getRainRacesSince(year) + print(f"Rain races since {max(year, 2018)}") + for rainRace in rainRaces: + print(rainRace) racesToAnalyse = [ SessionIdentifier(2022, "Imola", "R"), # Imola 2022 (DWR)