.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gen_modules/examples_gallery/plot_who_can_still_win_wdc.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gen_modules_examples_gallery_plot_who_can_still_win_wdc.py: Who can still win the drivers WDC? ====================================== Calculates which drivers still has chance to win the WDC. Simplified since it doesn't compare positions if points are equal. This example implements 3 functions that it then uses to calculate its result. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import fastf1 from fastf1.ergast import Ergast .. GENERATED FROM PYTHON SOURCE LINES 17-20 For this example, we are looking at the 2025 season. We want to know who can theoretically still win the drivers' championship after the first 12 races. .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python SEASON = 2025 ROUND = 12 .. GENERATED FROM PYTHON SOURCE LINES 26-28 Get the current driver standings from Ergast. Reference https://docs.fastf1.dev/ergast.html#fastf1.ergast.Ergast.get_driver_standings .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python def get_drivers_standings(): ergast = Ergast() standings = ergast.get_driver_standings(season=SEASON, round=ROUND) return standings.content[0] .. GENERATED FROM PYTHON SOURCE LINES 35-38 We need a function to calculates the maximum amount of points possible if a driver wins everything left of the season. https://en.wikipedia.org/wiki/List_of_Formula_One_World_Championship_points_scoring_systems .. GENERATED FROM PYTHON SOURCE LINES 38-55 .. code-block:: Python def calculate_max_points_for_remaining_season(): POINTS_FOR_SPRINT = 8 + 25 # Winning the sprint and race POINTS_FOR_CONVENTIONAL = 25 # Winning the race events = fastf1.events.get_event_schedule(SEASON, backend='ergast') events = events[events['RoundNumber'] > ROUND] # Count how many sprints and conventional races are left sprint_events = len(events.loc[events["EventFormat"] == "sprint_shootout"]) conventional_events = len(events.loc[events["EventFormat"] == "conventional"]) # Calculate points for each sprint_points = sprint_events * POINTS_FOR_SPRINT conventional_points = conventional_events * POINTS_FOR_CONVENTIONAL return sprint_points + conventional_points .. GENERATED FROM PYTHON SOURCE LINES 56-62 For each driver we will see if there is a chance to get more points than the current leader. We assume the leader gets no more points and the driver gets the theoretical maximum amount of points. We currently don't consider the case of two drivers getting equal points since its more complicated and would require comparing positions. .. GENERATED FROM PYTHON SOURCE LINES 62-76 .. code-block:: Python def calculate_who_can_win(driver_standings, max_points): LEADER_POINTS = int(driver_standings.loc[0]['points']) for i, _ in enumerate(driver_standings.iterrows()): driver = driver_standings.loc[i] driver_max_points = int(driver["points"]) + max_points can_win = 'No' if driver_max_points < LEADER_POINTS else 'Yes' print(f"{driver['position']}: {driver['givenName'] + ' ' + driver['familyName']}, " f"Current points: {driver['points']}, " f"Theoretical max points: {driver_max_points}, " f"Can win: {can_win}") .. GENERATED FROM PYTHON SOURCE LINES 77-79 Now using the 3 functions above we can use them to calculate who can still win. .. GENERATED FROM PYTHON SOURCE LINES 79-88 .. code-block:: Python # Get the current drivers standings driver_standings = get_drivers_standings() # Get the maximum amount of points points = calculate_max_points_for_remaining_season() # Print which drivers can still win calculate_who_can_win(driver_standings, points) .. rst-class:: sphx-glr-script-out .. code-block:: none 1: Oscar Piastri, Current points: 234.0, Theoretical max points: 434, Can win: Yes 2: Lando Norris, Current points: 226.0, Theoretical max points: 426, Can win: Yes 3: Max Verstappen, Current points: 165.0, Theoretical max points: 365, Can win: Yes 4: George Russell, Current points: 147.0, Theoretical max points: 347, Can win: Yes 5: Charles Leclerc, Current points: 119.0, Theoretical max points: 319, Can win: Yes 6: Lewis Hamilton, Current points: 103.0, Theoretical max points: 303, Can win: Yes 7: Andrea Kimi Antonelli, Current points: 63.0, Theoretical max points: 263, Can win: Yes 8: Alexander Albon, Current points: 46.0, Theoretical max points: 246, Can win: Yes 9: Nico Hülkenberg, Current points: 37.0, Theoretical max points: 237, Can win: Yes 10: Esteban Ocon, Current points: 23.0, Theoretical max points: 223, Can win: No 11: Isack Hadjar, Current points: 21.0, Theoretical max points: 221, Can win: No 12: Lance Stroll, Current points: 20.0, Theoretical max points: 220, Can win: No 13: Pierre Gasly, Current points: 19.0, Theoretical max points: 219, Can win: No 14: Fernando Alonso, Current points: 16.0, Theoretical max points: 216, Can win: No 15: Carlos Sainz, Current points: 13.0, Theoretical max points: 213, Can win: No 16: Liam Lawson, Current points: 12.0, Theoretical max points: 212, Can win: No 17: Yuki Tsunoda, Current points: 10.0, Theoretical max points: 210, Can win: No 18: Oliver Bearman, Current points: 6.0, Theoretical max points: 206, Can win: No 19: Gabriel Bortoleto, Current points: 4.0, Theoretical max points: 204, Can win: No 20: Franco Colapinto, Current points: 0.0, Theoretical max points: 200, Can win: No 21: Jack Doohan, Current points: 0.0, Theoretical max points: 200, Can win: No .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.044 seconds) .. _sphx_glr_download_gen_modules_examples_gallery_plot_who_can_still_win_wdc.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_who_can_still_win_wdc.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_who_can_still_win_wdc.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_who_can_still_win_wdc.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_