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

Reintegrate deprecated rain-filtering and add documentation

parent 7e7c960f
No related branches found
No related tags found
No related merge requests found
...@@ -122,6 +122,15 @@ class DataAnalyser(DataHandler): ...@@ -122,6 +122,15 @@ class DataAnalyser(DataHandler):
# ===== Weather ===== # ===== Weather =====
def isWet(self, weatherDescription: string): def isWet(self, weatherDescription: string):
"""
Determine if a given weather description describes an event with a wet race session, meaning intermediate or wet
tires were used.
Note: The output of this function is not a guarantee for a wet race session. It only matches keywords such as
"rain" and "wet" in the string, and returns a True for a wet race if any keywords are matched.
:param weatherDescription: Weather of an event as a string. This should be the weather conditions as listed on
the event's wikipedia page.
:return: Boolean of whether the race event was held in wet conditions or not.
"""
keywords: list[string] = ["rain", "wet"] keywords: list[string] = ["rain", "wet"]
for keyword in keywords: for keyword in keywords:
if keyword in weatherDescription.lower(): return True if keyword in weatherDescription.lower(): return True
...@@ -164,11 +173,9 @@ class DataAnalyser(DataHandler): ...@@ -164,11 +173,9 @@ class DataAnalyser(DataHandler):
return wetEvents return wetEvents
# TODO: Rename (other than legacy) def filterForRainSessions(self, sessions: list[Session]):
@DeprecationWarning
def filterForRainSessionsLEGACY(self, sessions: list[Session]):
""" """
Filter out & return only those sessions from input list that had rain falling at any point during the session. Filter out & return only those sessions from input list that had rain falling for at least 1 minute during the session.
Note: The sessions returned are not necessarily sessions that had wet conditions for any meaningful amount of 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 time. Also, sessions that had wet conditions only from leftover rainwater on track are not included in the
......
...@@ -105,16 +105,48 @@ class DataImporter(DataHandler, ABC): ...@@ -105,16 +105,48 @@ class DataImporter(DataHandler, ABC):
if firstYear > currentYear: if firstYear > currentYear:
raise ValueError("Cannot get race data from the future :)") raise ValueError("Cannot get race data from the future :)")
rainRaces: list[Session] = []
for year in range(firstYear, currentYear): # FIXME: Handle exception after new years, when no events have run in current year yet
wetWeatherRacesInYear: list[Session] = self.getWetEventsIn(year)
for wetWeatherRace in wetWeatherRacesInYear:
rainRaces.append(wetWeatherRace)
return rainRaces
def getWetEventsIn(self, year: int):
print(f"Fetching wet events in {year}")
events: list[Event] = self.importAllEventsFromYear(year)
analyser: DataAnalyser = DataAnalyser()
rainRaces: list[Session] = analyser.filterForWetEvents(events)
return rainRaces
def getRainRacesSince(self, firstYear: int):
"""
Retrieve all race sessions since and including given year that had at least one minute of rainfall during the race session.
:param firstYear: First year from which to retrieve race sessions.
:return: List of all race sessions from given year until present that had at least 1 minute of rainfall.
"""
currentYear = datetime.now().year
if firstYear > currentYear:
raise ValueError("Cannot get race data from the future :)")
rainRaces: list[Session] = [] rainRaces: list[Session] = []
for firstYear in range(firstYear, currentYear): # FIXME: Handle exception after new years, when no events have run in current year yet for firstYear in range(firstYear, currentYear): # FIXME: Handle exception after new years, when no events have run in current year yet
wetWeatherRacesInYear: list[Session] = self.getWetEventsIn(firstYear) wetWeatherRacesInYear: list[Session] = self.getRainRacesIn(firstYear)
for wetWeatherRace in wetWeatherRacesInYear: for wetWeatherRace in wetWeatherRacesInYear:
rainRaces.append(wetWeatherRace) rainRaces.append(wetWeatherRace)
return rainRaces return rainRaces
# TODO: Rename (other than legacy)
@DeprecationWarning
def getRainRacesIn(self, year: int): def getRainRacesIn(self, year: int):
"""
Retrieve all race sessions from given year that had at least one minute of rainfall during the race session.
:param year: Year from which to retrieve races.
:return: List of all race sessions from given year that had at least 1 minute of rainfall.
"""
events: list[Event] = self.importAllEventsFromYear(year) events: list[Event] = self.importAllEventsFromYear(year)
races: list[Session] = [] races: list[Session] = []
for event in events: for event in events:
...@@ -126,16 +158,7 @@ class DataImporter(DataHandler, ABC): ...@@ -126,16 +158,7 @@ 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.filterForRainSessionsLEGACY(races) rainRaces: list[Session] = analyser.filterForRainSessions(races)
return rainRaces
def getWetEventsIn(self, year: int):
print(f"Fetching wet events in {year}")
events: list[Event] = self.importAllEventsFromYear(year)
analyser: DataAnalyser = DataAnalyser()
rainRaces: list[Session] = analyser.filterForWetEvents(events)
return rainRaces return rainRaces
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment