diff --git a/DataAnalyser.py b/DataAnalyser.py index 98abb6119a9964e4a430c7a4fbb869e37ff9b3c0..d58820b92a0b04d1ec83e903326af82e3c042ffa 100644 --- a/DataAnalyser.py +++ b/DataAnalyser.py @@ -22,30 +22,12 @@ class DataAnalyser(DataHandler): overtakesInLaps: List[int] = self.countOvertakesPerLap(race) return overtakesInLaps - def analyseRaceForOvertakesOld(self, race: Session): - # Collect grid positions - allLapPositions: List[dict[str, int]] = [] - - gridPositions: dict[str, int] = self.getGridPositions(race) - allLapPositions.append(gridPositions) - - runningLapsPositions: List[dict[str, int]] = self.getRunningLapsPositions(race) - for runningLapPositions in runningLapsPositions: - allLapPositions.append(runningLapPositions) - - # Count position changes between all lap pairs - overtakesInLaps: List[int] = self.countOvertakesPerLap(allLapPositions) - - return overtakesInLaps - def countOvertakesPerLap(self, race: Session): overtakes: list[int] = [] - # TODO: Implement overtake counting for starting lap (lap 1) (necessary?) for lapNumber in range(1, race.total_laps + 1): # in this context, index 1 = lap 1 overtakes.append(self.countOvertakesInLap(lapNumber, race)) return overtakes - def prepareWeightedOrderFromLap(self, lapNumber: int, race: Session): '''Prepare a list from specific lap & race, that can be sorted via bubble sort to determine the number of overtakes that occured in that lap. @@ -56,7 +38,9 @@ class DataAnalyser(DataHandler): sorted by the driver's positions at the start of the lap. If an invalid lap number (below 1 or above the number 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 + previousLaps: Laps = race.laps.pick_laps(lapNumber - 1) currentLaps: Laps = race.laps.pick_laps(lapNumber) out: int = self.numberOfDrivers # weighting for drivers that did not complete the lap (they are "out" of the lap/race) @@ -99,14 +83,14 @@ 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.isInLap(weightedDriverAhead[0]) - or self.isInLap(weightedDriverBehind[0]) + or self.isAnInLap(weightedDriverAhead[0]) + or self.isAnInLap(weightedDriverBehind[0]) ): overtakes += 1 i += 1 return overtakes - def isInLap(self, lap: Lap): + def isAnInLap(self, lap: Lap): # TODO: Implement :) return False @@ -162,55 +146,6 @@ class DataAnalyser(DataHandler): return runningLapsPositions - ''' - def countOvertakesInLaps(self, allLapPositions: List[dict[str, int]]): - overtakesInLaps: List[int] = [] - for i in range(len(allLapPositions) - 1): - overtakesInLap: int = self.countOvertakesInLap(allLapPositions[i], allLapPositions[i + 1]) - overtakesInLaps.append(overtakesInLap) - if self.activateDebugOvertakeAnalysis: print(f"Overtakes in lap {i+1}: {overtakesInLap}") - return overtakesInLaps - - def countOvertakesInLap(self, startOrder: dict[str, int], endOrder: dict[str, int]): - out: int = self.numberOfDrivers - orderToSort: List[int] = [self.numberOfDrivers] * self.numberOfDrivers - for driver in startOrder: - if driver not in endOrder: # add missing drivers for sorting/counting purposes - endOrder[driver] = out # heaviest weighting to drop driver to bottom, as they do irl when crashing or similar - if math.isnan(startOrder[driver]): startOrder[driver] = out - if math.isnan(endOrder[driver]): endOrder[driver] = out - driverStartPosition: int = int(startOrder[driver]) - driverEndPosition: int = int(endOrder[driver]) - - orderToSort[driverStartPosition - 1] = driverEndPosition - - if self.activateDebugOvertakeAnalysis: - #print("Weighting:") - for i in range(len(orderToSort)): - x=0 - #print(orderToSort[i]) - - - overtakes: int = 0 - i: int = 0 - while i < len(orderToSort) - 1: - if self.countOutPitstops: # TODO: Remove? This was never fully implemented here, new implementation elsewhere - driverPittedThisLap: bool = False - currentDriversEndPosition = orderToSort[i] - driver = self.getDriverByPositionFromMap(endOrder, currentDriversEndPosition) - - if orderToSort[i] > orderToSort[i + 1]: - temp: int = orderToSort[i] - orderToSort[i] = orderToSort[i + 1] - orderToSort[i + 1] = temp - overtakes += 1 - i = -1 # reset to first index; -1 because loop will set it to 0 - - i += 1 - - return overtakes - ''' - def getDriverByPositionFromMap(self, positions: dict[str, int], position: int): driver = list(positions.keys())[list(positions.values()).index(position)] return driver diff --git a/Todos.md b/Todos.md index 0c54bfa2b71f57848ffa7ae4dae180876e1e0dc4..edd108378cb02553aa49d1e46d8ccf3a1d5727f4 100644 --- a/Todos.md +++ b/Todos.md @@ -1,6 +1,6 @@ # Todo (sorted by priority) - Fetch rain races via API, not Reddit -- Adjust for pitstop discreptancies +- Adjust for pitstop discrepancies - Include safety car periods & driver crashes - Automatically determine if race is DWR or SWR - Adjust for situations like Canada 2024 -> 2 drivers taking wets at the start does not constitute a weather change @@ -10,6 +10,9 @@ - Read out number of drivers participating in session, rather than hardcoding number of drivers (since it might change from 20 to more (or less) in future) - Also read out direct weather data from API +# Current +- Fetch grid positions & use them for counting in lap 1 +- Implement isAnInLap() function for taking pitstops into account # Done - Automatically title graph by race name (no more hardcoding the graph name)