From 0ea1ff499cfa5910a74945a6e4872aedd9dcf716 Mon Sep 17 00:00:00 2001 From: Lennard Geese <lennard.geese@sva.de> Date: Sun, 6 Apr 2025 20:18:38 +0200 Subject: [PATCH] Implement fetching and recognition of rain races --- DataAnalyser.py | 26 +++++++++++++++++++++----- DataImporter.py | 2 +- Todos.md | 2 +- main.py | 7 +++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/DataAnalyser.py b/DataAnalyser.py index db90be6..940848d 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 7fe7647..ab523e2 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 1231d7f..e6eb65e 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 77cbe18..d462a51 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) -- GitLab