Skip to content

[BUG] List format stints in legacy API responses cause dropped stints #863

@Casper-Guo

Description

@Casper-Guo

Describe the issue:

Document discussion in #860 in case there is any taker for a close-to-done bug fix. This issue is definitely triggered by the 2018 Baku GP data but there may be other cases.

21056_AZ-PitStop-IT-750.jpg (view on web)

There are five drivers who pitted on lap 1 according to the above Pirelli graphics. The following strategy visualization code do not show any of these pitstops. It produces the following graphic:

Image

This is because the stints field in the API data response is not correctly processed:

"Stints":[
            {
               "LapFlags":0,
               "Compound":"ULTRASOFT",
               "New":"false",
               "TyresNotChanged":"0",
               "TotalLaps":4,
               "StartLaps":3
            },
            {
               "LapFlags":0,
               "Compound":"SOFT",
               "New":"true",
               "TyresNotChanged":"0",
               "TotalLaps":0,
               "StartLaps":0
            }
         ]

The diff in #860 shows where the fix needs should be implemented but is not necessarily correct, and more testing is certainly needed

Reproduce the code example:

from matplotlib import pyplot as plt

import fastf1
import fastf1.plotting

session = fastf1.get_session(2018, "Azerbaijan", 'R')
session.load()

drivers = session.drivers
drivers = [session.get_driver(driver)["Abbreviation"] for driver in drivers]

stints = session.laps[["Driver", "Stint", "Compound", "LapNumber"]]
stints = stints.groupby(["Driver", "Stint", "Compound"])
stints = stints.count().reset_index()
stints = stints.rename(columns={"LapNumber": "StintLength"})

fig, ax = plt.subplots(figsize=(5, 10))

for driver in drivers:
    driver_stints = stints.loc[stints["Driver"] == driver]

    previous_stint_end = 0
    for idx, row in driver_stints.iterrows():
        # each row contains the compound name and stint length
        # we can use these information to draw horizontal bars
        compound_color = fastf1.plotting.get_compound_color(row["Compound"],
                                                            session=session)
        plt.barh(
            y=driver,
            width=row["StintLength"],
            left=previous_stint_end,
            color=compound_color,
            edgecolor="black",
            fill=True
        )

        previous_stint_end += row["StintLength"]

plt.title("2018 Azerbaijan Grand Prix Strategies")
plt.xlabel("Lap Number")
plt.grid(False)
# invert the y-axis so drivers that finish higher are closer to the top
ax.invert_yaxis()

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)

plt.tight_layout()
plt.show()

State your Fastf1 version number:

3.8.1

Error message:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions