diff --git a/DataAnalyser.py b/DataAnalyser.py index d58820b92a0b04d1ec83e903326af82e3c042ffa..c03b8c8ba89db122273d6fab01075b7d5cc84474 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -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):