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

Refactor private method names

parent 525b445c
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment