diff --git a/DataAnalyser.py b/DataAnalyser.py index 940848d7f3e0eaab06a946ffa6a5ecf9e2cd4532..a7c6100fcb765334ba8b1a4ddd4cc6f4bb6706fa 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -22,8 +22,7 @@ class DataAnalyser(DataHandler): return overtakesInRaces def getOvertakesPerLapForRace(self, race: Session): - if not race.session_info["Type"] == "Race": - raise ValueError(f"Session must be a race session, not a {race.session_info["Type"]} session") + self.enforceSessionType(race, "Race") overtakesInLaps: list[int] = self.countOvertakesPerLap(race) return overtakesInLaps @@ -140,6 +139,9 @@ class DataAnalyser(DataHandler): return rainSessions + def raceHasWeatherChange(self, race: Session): + if self.getEarliestTireChange(race) == -1: return True + return False # ===== Tire Changes ===== @@ -251,3 +253,11 @@ class DataAnalyser(DataHandler): def analyseRacesForSafetyCars(self, races): x = 0 + + # ===== Other + + def enforceSessionType(self, session: Session, sessionType: str): + if sessionType not in self.validSessionTypes: + raise ValueError(f"Invalid session type \"{sessionType}\"; only {self.validSessionTypes} are allowed") + if not session.session_info["Type"] == sessionType: + raise ValueError(f"Session must be a {sessionType} session, not a {session.session_info["Type"]} session") \ No newline at end of file diff --git a/DataHandler.py b/DataHandler.py index e9c8d7a95c0bd2f031ab9e22947a7b3d4367c56b..90e9e7c39f22bb59dcb5f6bbc90a9178ae0901ac 100644 --- a/DataHandler.py +++ b/DataHandler.py @@ -7,6 +7,7 @@ class DataHandler(ABC): self.invalidDriverId = "NO_DRIVER" self.activateDebugOvertakeAnalysis = False self.slickCompounds = ('SOFT', 'MEDIUM', 'HARD') + self.validSessionTypes = ("Practice", "Qualifying", "Race") # TODO: Check if it's called Qualify or Qualifying in the Pandas dataframes self.countOutPitstops = True self.firstFastF1Year: int = 2018