diff --git a/DataPlotter.py b/DataPlotter.py index 31bc35cf563d0c66dc8f912e9b1d840614860c33..9638cc33aa892ee20b39f484bccca62ff15e109a 100644 --- a/DataPlotter.py +++ b/DataPlotter.py @@ -12,7 +12,7 @@ from DataHandler import DataHandler class DataPlotter(DataHandler): - def plotOvertakesWithTireChangeWindow(self, overtakesPerLap: List[int], earliestTireChange: int, latestTireChange: int): + def plotOvertakesWithTireChangeWindow(self, overtakesPerLap: List[int], earliestTireChange: int, latestTireChange: int, raceName: str): overtakesPerLap.insert(0, 0) # Insert 0th lap, which cannot have overtakes laps: int = len(overtakesPerLap) @@ -24,6 +24,7 @@ class DataPlotter(DataHandler): axis.set_xlabel('Lap') axis.set_ylabel('Position changes in lap') + plt.title(raceName) major_ticks_laps = np.arange(0, laps, 5) major_ticks_overtakes = np.arange(0, max(overtakesPerLap) + 1, 5) diff --git a/main.py b/main.py index cb9736e123d740785f6f2b6b62beae1d78482283..a74cedabdaaad05459f7ef12fe1d413099c8110a 100644 --- a/main.py +++ b/main.py @@ -19,10 +19,10 @@ class Main: def main(self): # contains pairs of season & race number to identify specific races race_indexes = [ - [2022, 4] # Imola 2022 (DWR) - # [2024, 7] # Imola 2024 (SWR) - # [2024, 9] # Canada 2024 (DWR) - # + [2022, 4], # Imola 2022 (DWR) + [2024, 7], # Imola 2024 (SWR) + [2024, 9], # Canada 2024 (DWR) + [2023, 8] # Canada 2023 (SWR) # TODO: add more races ] @@ -31,10 +31,14 @@ class Main: plotter = DataPlotter() for race_index in race_indexes: + + # Import raceSession = importer.importRaceSession(race_index) + raceName: str = f"{raceSession.event['EventName']} {raceSession.event.year}" print("Import done") + # Analyse overtakesInRaces: List[int] = analyser.analyseRaceForOvertakes(raceSession) print("Overtake analysis done") @@ -44,11 +48,13 @@ class Main: latestTireChange: int = analyser.getLatestTireChange(raceSession) print("Last tire change done") - plotter.plotOvertakesWithTireChangeWindow(overtakesInRaces, earliestTireChange, latestTireChange) - print("Plot done") + # Plot + plotter.plotOvertakesWithTireChangeWindow(overtakesInRaces, earliestTireChange, latestTireChange, raceName) + print("Plot done") + # Print data print(f"\n\n===== Data for race {race_index[0]}/{race_index[1]} =====") print("Lap\tOvertakes") currentLap = 0 @@ -60,70 +66,6 @@ class Main: print(f"Weather change window is therefore: laps {earliestTireChange-1} - {latestTireChange+1}") - - - def fastF1Example(self): - # Load FastF1's dark color scheme - fastf1.plotting.setup_mpl(mpl_timedelta_support=False, misc_mpl_mods=False, - color_scheme='fastf1') - - - session = fastf1.get_session(2024, 7, 'R') - session.load(laps=True, weather=True) - - figure, axis = plt.subplots(figsize=(8.0, 4.9)) - - - for driver in session.drivers: - driverLaps = session.laps.pick_drivers(driver) - - driverAbbreviation = driverLaps['Driver'].iloc[0] - style = fastf1.plotting.get_driver_style(identifier=driverAbbreviation, - style=['color', 'linestyle'], - session=session) - - axis.plot(driverLaps['LapNumber'], driverLaps['Position'], - label=driverAbbreviation, **style) - - - axis.set_ylim([20.5, 0.5]) - axis.set_yticks([1, 5, 10, 15, 20]) - axis.set_xlabel('Lap') - axis.set_ylabel('Position') - - - axis.legend(bbox_to_anchor=(1.0, 1.02)) - plt.tight_layout() - - plt.show() - - - def oldJavaTransfer(self): - # contains pairs of season & race number to identify specific races - race_indexes = [ - [2024, 7], # Imola 2024 - [2022, 4] # Imola 2022 - # TODO: add more races - ] - - importer = DataImporter() - checker = DataChecker() - analyser = DataAnalyser() - # plotter = DataPlotter() # Commented as it's not used - - races = importer.import_laps_for_races(race_indexes) - checker.check_imported_races(races) - overtakes_in_races = analyser.count_overtakes_in_races(races) - - print(f"Data for race {race_indexes[0][1]}/{race_indexes[0][0]}") - for current_lap in range(len(overtakes_in_races[0])): - print(f"Overtakes in lap {current_lap + 1}: {overtakes_in_races[0][current_lap]}") - - return overtakes_in_races - - - - if __name__ == '__main__': app = Main()