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

Refactor private method names

parent 525b445c
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ class DataAnalyser(DataHandler): ...@@ -25,7 +25,7 @@ class DataAnalyser(DataHandler):
return overtakesInRaces return overtakesInRaces
def getOvertakesPerLapForRace(self, race: Session): def getOvertakesPerLapForRace(self, race: Session):
self.enforceSessionType(race, "Race") self.__enforceSessionType(race, "Race")
overtakesInLaps: list[int] = self.countOvertakesPerLap(race) overtakesInLaps: list[int] = self.countOvertakesPerLap(race)
return overtakesInLaps return overtakesInLaps
...@@ -52,8 +52,8 @@ class DataAnalyser(DataHandler): ...@@ -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 if not ( # don't count overtake if driver nonexistent or if one of them is on an in-lap
weightedDriverAhead[0] is None weightedDriverAhead[0] is None
or weightedDriverBehind[0] is None or weightedDriverBehind[0] is None
or self.isAnInLap(weightedDriverAhead[0]) or self.__isAnInLap(weightedDriverAhead[0])
or self.isAnInLap(weightedDriverBehind[0]) or self.__isAnInLap(weightedDriverBehind[0])
): overtakes += 1 ): overtakes += 1
i += 1 i += 1
...@@ -109,7 +109,7 @@ class DataAnalyser(DataHandler): ...@@ -109,7 +109,7 @@ class DataAnalyser(DataHandler):
gridPosition: int = int(sessionResults['GridPosition'].loc[driverNumber]) gridPosition: int = int(sessionResults['GridPosition'].loc[driverNumber])
return gridPosition return gridPosition
def isAnInLap(self, lap: Lap): def __isAnInLap(self, lap: Lap):
try: try:
return not pandas.isnull(lap['PitInTime'].iloc[0]) return not pandas.isnull(lap['PitInTime'].iloc[0])
except: # caused when lap is empty and possibly when lap is None except: # caused when lap is empty and possibly when lap is None
...@@ -159,7 +159,7 @@ class DataAnalyser(DataHandler): ...@@ -159,7 +159,7 @@ class DataAnalyser(DataHandler):
return rainSessions return rainSessions
def raceHasWeatherChange(self, race: Session): def hasWeatherChange(self, race: Session):
if self.getFirstTireChange(race) == -1: return True if self.getFirstTireChange(race) == -1: return True
return False return False
...@@ -182,8 +182,8 @@ class DataAnalyser(DataHandler): ...@@ -182,8 +182,8 @@ class DataAnalyser(DataHandler):
""" """
compoundsPerLap: list[list[str]] = self.getCompoundsForRace(race) 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 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]) startingCompound: str = self.__getPredominantCompound(compoundsPerLap[0])
earliestTireChangeLap = self.getFirstLapWithOppositeCompound(compoundsPerLap, startingCompound) earliestTireChangeLap = self.__getFirstLapWithOppositeCompound(compoundsPerLap, startingCompound)
return earliestTireChangeLap return earliestTireChangeLap
...@@ -203,14 +203,14 @@ class DataAnalyser(DataHandler): ...@@ -203,14 +203,14 @@ class DataAnalyser(DataHandler):
""" """
compoundsPerLap: list[list[str]] = self.getCompoundsForRace(race) 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 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]) startingCompound: str = self.__getPredominantCompound(compoundsPerLap[0])
latestTireChangeLap = self.getFirstLapWithoutCompound(compoundsPerLap, startingCompound) latestTireChangeLap = self.__getFirstLapWithoutCompound(compoundsPerLap, startingCompound)
return latestTireChangeLap return latestTireChangeLap
def getFirstLapWithoutCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): def __getFirstLapWithoutCompound(self, compoundsPerLap: list[list[str]], startingCompound: str):
currentLap = 0 currentLap = 0
compoundFilter = self.setFilter(startingCompound) compoundFilter = self.__generateFilter(startingCompound)
for compoundsThisLap in compoundsPerLap: for compoundsThisLap in compoundsPerLap:
noStartingCompoundsLeft = True noStartingCompoundsLeft = True
for compound in compoundsThisLap: for compound in compoundsThisLap:
...@@ -239,7 +239,7 @@ class DataAnalyser(DataHandler): ...@@ -239,7 +239,7 @@ class DataAnalyser(DataHandler):
return compoundsPerLap return compoundsPerLap
def getPredominantCompound(self, compoundsThisLap: list[str]): def __getPredominantCompound(self, compoundsThisLap: list[str]):
slickCounter = 0 slickCounter = 0
interCounter = 0 interCounter = 0
wetCounter = 0 wetCounter = 0
...@@ -253,8 +253,8 @@ class DataAnalyser(DataHandler): ...@@ -253,8 +253,8 @@ class DataAnalyser(DataHandler):
if wetCounter == mostUsed: return 'WET' if wetCounter == mostUsed: return 'WET'
return 'error' return 'error'
def getFirstLapWithOppositeCompound(self, compoundsPerLap: list[list[str]], startingCompound: str): def __getFirstLapWithOppositeCompound(self, compoundsPerLap: list[list[str]], startingCompound: str):
compoundFilter = self.setFilter(startingCompound) compoundFilter = self.__generateFilter(startingCompound)
currentLap = 0 currentLap = 0
for compoundsThisLap in compoundsPerLap: for compoundsThisLap in compoundsPerLap:
for compound in compoundsThisLap: for compound in compoundsThisLap:
...@@ -263,7 +263,7 @@ class DataAnalyser(DataHandler): ...@@ -263,7 +263,7 @@ class DataAnalyser(DataHandler):
currentLap += 1 currentLap += 1
return -1 # no lap with opposite compound found; all laps use same compound type 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 if startingCompound == 'SLICK': return self.slickCompounds
return startingCompound return startingCompound
...@@ -283,7 +283,7 @@ class DataAnalyser(DataHandler): ...@@ -283,7 +283,7 @@ class DataAnalyser(DataHandler):
# ===== Other # ===== Other
def enforceSessionType(self, session: Session, sessionType: str): def __enforceSessionType(self, session: Session, sessionType: str):
if sessionType not in self.validSessionTypes: if sessionType not in self.validSessionTypes:
raise ValueError(f"Invalid session type \"{sessionType}\"; only {self.validSessionTypes} are allowed") raise ValueError(f"Invalid session type \"{sessionType}\"; only {self.validSessionTypes} are allowed")
if not session.session_info["Type"] == sessionType: if not session.session_info["Type"] == sessionType:
......
...@@ -32,13 +32,13 @@ class DataImporter(DataHandler, ABC): ...@@ -32,13 +32,13 @@ class DataImporter(DataHandler, ABC):
if isinstance(event, SessionIdentifier): if isinstance(event, SessionIdentifier):
event = self.importEvent(event.year, event.event) event = self.importEvent(event.year, event.event)
wikiHtml = self.importWikiHtml(event) wikiHtml = self.__importWikiHtml(event)
analyser = DataAnalyser() analyser = DataAnalyser()
weather = analyser.extractWeatherFromHtml(wikiHtml) weather = analyser.extractWeatherFromHtml(wikiHtml)
return weather return weather
def importWikiHtml(self, event: Event): def __importWikiHtml(self, event: Event):
""" """
Fetch the HTML contents of the wikipedia page for the event given. Fetch the HTML contents of the wikipedia page for the event given.
:param event: Event whose wikipedia page to fetch. :param event: Event whose wikipedia page to fetch.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment