diff --git a/DataAnalyser.py b/DataAnalyser.py index a05ede2a759f42087aeea26f0c0642feb250d501..e6a08f9c86900a5c856ae538a2e295c8588ce4d7 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -25,7 +25,7 @@ class DataAnalyser(DataHandler): return overtakesInRaces def getOvertakesPerLapForRace(self, race: Session): - self.enforceSessionType(race, "Race") + self.__enforceSessionType(race, "Race") overtakesInLaps: list[int] = self.countOvertakesPerLap(race) return overtakesInLaps @@ -52,8 +52,8 @@ class DataAnalyser(DataHandler): if not ( # don't count overtake if driver nonexistent or if one of them is on an in-lap weightedDriverAhead[0] is None or weightedDriverBehind[0] is None - or self.isAnInLap(weightedDriverAhead[0]) - or self.isAnInLap(weightedDriverBehind[0]) + or self.__isAnInLap(weightedDriverAhead[0]) + or self.__isAnInLap(weightedDriverBehind[0]) ): overtakes += 1 i += 1 @@ -109,7 +109,7 @@ class DataAnalyser(DataHandler): gridPosition: int = int(sessionResults['GridPosition'].loc[driverNumber]) return gridPosition - def isAnInLap(self, lap: Lap): + def __isAnInLap(self, lap: Lap): try: return not pandas.isnull(lap['PitInTime'].iloc[0]) except: # caused when lap is empty and possibly when lap is None @@ -159,7 +159,7 @@ class DataAnalyser(DataHandler): return rainSessions - def raceHasWeatherChange(self, race: Session): + def hasWeatherChange(self, race: Session): if self.getFirstTireChange(race) == -1: return True return False @@ -182,8 +182,8 @@ class DataAnalyser(DataHandler): """ compoundsPerLap: list[list[str]] = self.getCompoundsForRace(race) compoundsPerLap[0] = compoundsPerLap[1] # presume grid tires same as 1st lap; races are only picked if weather change after first 10 laps anyway, so it's ok - startingCompound: str = self.getPredominantCompound(compoundsPerLap[0]) - earliestTireChangeLap = self.getFirstLapWithOppositeCompound(compoundsPerLap, startingCompound) + startingCompound: str = self.__getPredominantCompound(compoundsPerLap[0]) + earliestTireChangeLap = self.__getFirstLapWithOppositeCompound(compoundsPerLap, startingCompound) return earliestTireChangeLap @@ -203,14 +203,14 @@ class DataAnalyser(DataHandler): """ compoundsPerLap: list[list[str]] = self.getCompoundsForRace(race) compoundsPerLap[0] = compoundsPerLap[1] # presume grid tires same as 1st lap; races are only picked if weather change after first 10 laps anyway, so it's ok - startingCompound: str = self.getPredominantCompound(compoundsPerLap[0]) - latestTireChangeLap = self.getFirstLapWithoutCompound(compoundsPerLap, startingCompound) + startingCompound: str = self.__getPredominantCompound(compoundsPerLap[0]) + latestTireChangeLap = self.__getFirstLapWithoutCompound(compoundsPerLap, startingCompound) return latestTireChangeLap - def getFirstLapWithoutCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): + def __getFirstLapWithoutCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): currentLap = 0 - compoundFilter = self.setFilter(startingCompound) + compoundFilter = self.__generateFilter(startingCompound) for compoundsThisLap in compoundsPerLap: noStartingCompoundsLeft = True for compound in compoundsThisLap: @@ -239,7 +239,7 @@ class DataAnalyser(DataHandler): return compoundsPerLap - def getPredominantCompound(self, compoundsThisLap: list[str]): + def __getPredominantCompound(self, compoundsThisLap: list[str]): slickCounter = 0 interCounter = 0 wetCounter = 0 @@ -253,8 +253,8 @@ class DataAnalyser(DataHandler): if wetCounter == mostUsed: return 'WET' return 'error' - def getFirstLapWithOppositeCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): - compoundFilter = self.setFilter(startingCompound) + def __getFirstLapWithOppositeCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): + compoundFilter = self.__generateFilter(startingCompound) currentLap = 0 for compoundsThisLap in compoundsPerLap: for compound in compoundsThisLap: @@ -263,7 +263,7 @@ class DataAnalyser(DataHandler): currentLap += 1 return -1 # no lap with opposite compound found; all laps use same compound type - def setFilter(self, startingCompound: str): + def __generateFilter(self, startingCompound: str): if startingCompound == 'SLICK': return self.slickCompounds return startingCompound @@ -283,7 +283,7 @@ class DataAnalyser(DataHandler): # ===== Other - def enforceSessionType(self, session: Session, sessionType: str): + 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: diff --git a/DataImporter.py b/DataImporter.py index 325ad35b7146a5e8e863032c5ce6a751ca20f42f..e30faf452efc6f3873a591553cb80dd50ca971bc 100644 --- a/DataImporter.py +++ b/DataImporter.py @@ -32,13 +32,13 @@ class DataImporter(DataHandler, ABC): if isinstance(event, SessionIdentifier): event = self.importEvent(event.year, event.event) - wikiHtml = self.importWikiHtml(event) + wikiHtml = self.__importWikiHtml(event) analyser = DataAnalyser() weather = analyser.extractWeatherFromHtml(wikiHtml) return weather - def importWikiHtml(self, event: Event): + def __importWikiHtml(self, event: Event): """ Fetch the HTML contents of the wikipedia page for the event given. :param event: Event whose wikipedia page to fetch.