Skip to content
Snippets Groups Projects
Commit 0ea1ff49 authored by Lennard Geese's avatar Lennard Geese
Browse files

Implement fetching and recognition of rain races

parent 97a97d94
No related branches found
No related tags found
No related merge requests found
import pandas as pandas import pandas as pandas
from fastf1.core import Session, Lap, Laps from fastf1.core import Session, Lap, Laps, DataNotLoadedError
from DataHandler import DataHandler, SessionIdentifier from DataHandler import DataHandler, SessionIdentifier
...@@ -117,12 +117,28 @@ class DataAnalyser(DataHandler): ...@@ -117,12 +117,28 @@ class DataAnalyser(DataHandler):
# ===== Weather ===== # ===== Weather =====
def filterForWetSessions(self, sessions: list[Session]): def filterForRainSessions(self, sessions: list[Session]):
x = 0 '''
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
......
...@@ -67,6 +67,6 @@ class DataImporter(DataHandler, ABC): ...@@ -67,6 +67,6 @@ class DataImporter(DataHandler, ABC):
print(f"Weather for {event["EventName"]} {event.year} could not be determined") print(f"Weather for {event["EventName"]} {event.year} could not be determined")
analyser: DataAnalyser = DataAnalyser() analyser: DataAnalyser = DataAnalyser()
rainRaces: list[Session] = analyser.filterForWetSessions(races) rainRaces: list[Session] = analyser.filterForRainSessions(races)
return rainRaces return rainRaces
\ No newline at end of file
# Todos (sorted by priority) # Todos (sorted by priority)
- [x] Automatically title graph by race name (no more hardcoding the graph name) - [x] Automatically title graph by race name (no more hardcoding the graph name)
- [x] Adjust for pitstop discrepancies - [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 ?) - [ ] Adjust for position changes caused by crashes (keep out of calculation similarly to PCs due to pitstops ?)
- [ ] Include safety car periods & driver crashes - [ ] Include safety car periods & driver crashes
- [ ] Automatically determine if race is DWR or SWR - [ ] Automatically determine if race is DWR or SWR
......
...@@ -19,8 +19,11 @@ class Main: ...@@ -19,8 +19,11 @@ class Main:
def main(self): def main(self):
dataHandler: Main.DataHandlingPackage = Main.DataHandlingPackage() 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 = [ racesToAnalyse = [
SessionIdentifier(2022, "Imola", "R"), # Imola 2022 (DWR) SessionIdentifier(2022, "Imola", "R"), # Imola 2022 (DWR)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment