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

Implement counting of position changes in lap 1

parent 80492edc
Branches
No related tags found
No related merge requests found
......@@ -39,7 +39,10 @@ class DataAnalyser(DataHandler):
of laps the race had), all laps in the list will be either None objects or empty Panda Dataframes.
'''
# TODO: Implement returning starting grid for lapNumber = 0
# TODO: Implement returning starting grid for lapNumber = 1
# TODO: Sidestep getting start position from lap, get from session results instead, for lap 1 SOL (start of lap)
previousLaps: Laps = race.laps.pick_laps(lapNumber - 1)
currentLaps: Laps = race.laps.pick_laps(lapNumber)
......@@ -48,22 +51,26 @@ class DataAnalyser(DataHandler):
# Put every driver's laps in a sortable array & apply weighting based on position at end of lap
for driver in race.drivers:
driverCurrentLap: Laps = previousLaps.pick_drivers(
driversPreviousLap: Laps = previousLaps.pick_drivers(
driver) # should only get 1 lap, but data type shenanigans
driverNextLap: Laps = currentLaps.pick_drivers(driver)
driversCurrentLap: Laps = currentLaps.pick_drivers(driver)
startPosition: int = out
endPosition: int = out
try:
startPosition = int(driverCurrentLap['Position'].iloc[0])
endPosition = int(driverNextLap['Position'].iloc[0])
if lapNumber == 1:
startPosition = self.getGridPositionFor(driver, race)
else: startPosition = int(driversPreviousLap['Position'].iloc[0])
endPosition = int(driversCurrentLap['Position'].iloc[0])
except ValueError:
if self.activateDebugOvertakeAnalysis: print(f"Could not fetch positions from lap; driver %d likely didn't finish lap %d or %d",
driver, lapNumber, (lapNumber + 1))
except IndexError:
if self.activateDebugOvertakeAnalysis: print("['Position'].iloc[0] was out of bounds; lap was likely empty because driver previously left the race")
weightedOrder[startPosition - 1] = (driverCurrentLap, endPosition)
weightedOrder[startPosition - 1] = (driversCurrentLap, endPosition)
return weightedOrder
def countOvertakesInLap(self, lapNumber: int, race: Session):
......@@ -95,7 +102,10 @@ class DataAnalyser(DataHandler):
return False
def getGridPositionFor(self, driverNumber: int, race: Session):
sessionResults = race.results
gridPosition: int = int(sessionResults['GridPosition'].loc[driverNumber])
return gridPosition
def getGridPositions(self, race: Session):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment