diff --git a/DataAnalyser.py b/DataAnalyser.py index 8deb6390d91424481309e755a0460da700c1d9fe..6a9d99df4b2b75186afa99948a1cc9a092a25a79 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -122,6 +122,15 @@ class DataAnalyser(DataHandler): # ===== Weather ===== 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"] for keyword in keywords: if keyword in weatherDescription.lower(): return True @@ -164,11 +173,9 @@ class DataAnalyser(DataHandler): return wetEvents - # TODO: Rename (other than legacy) - @DeprecationWarning - def filterForRainSessionsLEGACY(self, sessions: list[Session]): + 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. + 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 time. Also, sessions that had wet conditions only from leftover rainwater on track are not included in the diff --git a/DataImporter.py b/DataImporter.py index 840d6fd57e98d5357b8fadbdd51aac5da889f5e0..e8fe41861a3733afd14ea7a1d6675377650f19e7 100644 --- a/DataImporter.py +++ b/DataImporter.py @@ -105,16 +105,48 @@ class DataImporter(DataHandler, ABC): if firstYear > currentYear: 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] = [] 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: rainRaces.append(wetWeatherRace) return rainRaces - # TODO: Rename (other than legacy) - @DeprecationWarning 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) races: list[Session] = [] for event in events: @@ -126,16 +158,7 @@ class DataImporter(DataHandler, ABC): print(f"Weather for {event["EventName"]} {event.year} could not be determined") analyser: DataAnalyser = DataAnalyser() - rainRaces: list[Session] = analyser.filterForRainSessionsLEGACY(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) + rainRaces: list[Session] = analyser.filterForRainSessions(races) return rainRaces