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.

import fastf1
from fastf1.ergast import Ergast

Get the current driver standings from Ergast. Reference https://theoehrly.github.io/Fast-F1-Pre-Release-Documentation/ergast.html#fastf1.ergast.Ergast.get_driver_standings

def get_drivers_standings():
    ergast = Ergast()
    standings = ergast.get_driver_standings(season=2023)
    return standings.content[0]

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

def calculate_max_points_for_remaining_season():
    POINTS_FOR_SPRINT = 8 + 25 + 1  # Winning the sprint, race and fastest lap
    POINTS_FOR_CONVENTIONAL = 25 + 1  # Winning the race and fastest lap

    events = fastf1.events.get_events_remaining(backend="ergast")
    # 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

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.

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}")

Now using the 3 functions above we can use them to calculate who can still win.

# 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)
1: Max Verstappen, Current points: 549.0, Theoretical max points: 575, Can win: Yes
2: Sergio Pérez, Current points: 273.0, Theoretical max points: 299, Can win: No
3: Lewis Hamilton, Current points: 232.0, Theoretical max points: 258, Can win: No
4: Carlos Sainz, Current points: 200.0, Theoretical max points: 226, Can win: No
5: Fernando Alonso, Current points: 200.0, Theoretical max points: 226, Can win: No
6: Lando Norris, Current points: 195.0, Theoretical max points: 221, Can win: No
7: Charles Leclerc, Current points: 188.0, Theoretical max points: 214, Can win: No
8: George Russell, Current points: 160.0, Theoretical max points: 186, Can win: No
9: Oscar Piastri, Current points: 89.0, Theoretical max points: 115, Can win: No
10: Lance Stroll, Current points: 73.0, Theoretical max points: 99, Can win: No
11: Pierre Gasly, Current points: 62.0, Theoretical max points: 88, Can win: No
12: Esteban Ocon, Current points: 58.0, Theoretical max points: 84, Can win: No
13: Alexander Albon, Current points: 27.0, Theoretical max points: 53, Can win: No
14: Yuki Tsunoda, Current points: 13.0, Theoretical max points: 39, Can win: No
15: Valtteri Bottas, Current points: 10.0, Theoretical max points: 36, Can win: No
16: Nico Hülkenberg, Current points: 9.0, Theoretical max points: 35, Can win: No
17: Daniel Ricciardo, Current points: 6.0, Theoretical max points: 32, Can win: No
18: Guanyu Zhou, Current points: 6.0, Theoretical max points: 32, Can win: No
19: Kevin Magnussen, Current points: 3.0, Theoretical max points: 29, Can win: No
20: Liam Lawson, Current points: 2.0, Theoretical max points: 28, Can win: No
21: Logan Sargeant, Current points: 1.0, Theoretical max points: 27, Can win: No
22: Nyck de Vries, Current points: 0.0, Theoretical max points: 26, Can win: No

Total running time of the script: (0 minutes 0.519 seconds)

Gallery generated by Sphinx-Gallery