theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.46k stars 259 forks source link

[BUG] Lap time alignment fails if a driver retires on the first lap of a race and pits #549

Open theOehrly opened 6 months ago

theOehrly commented 6 months ago

Describe the issue:

The alignment of the (absolute) lap start times across drivers fails if a driver retires on the first lap and pits. Example: 2024, Saudi Arabia, Race

Other combinations of factors may have the same effect.

The lap time alignment should be extended to be able to align laps based on different reference laps for each driver instead of being fixed to one single lap where the constraints must be met by all drivers.

Reproduce the code example:

import fastf1

fastf1.Cache.set_disabled()

session = fastf1.get_session(2024, 2, 'R')
session.load()

Error message:

req         WARNING     DEFAULT CACHE ENABLED! (412.31 MB) C:\Users\phisc\AppData\Local\Temp\fastf1
core           INFO     Loading data for Saudi Arabian Grand Prix - Race [v3.4.0.dev1]
_api           INFO     Fetching session info data...
_api           INFO     Fetching driver list...
_api           INFO     Fetching session status data...
_api           INFO     Fetching lap count data...
_api           INFO     Fetching track status data...
_api           INFO     Fetching timing data...
_api           INFO     Parsing timing data...
_api        WARNING     Skipping lap alignment (no suitable lap)!
HarshitACE commented 6 months ago

Hi, I was working on this bug and just wanted to understand what exactly do you mean by different laps. i.e. What strategy you had in mind? Thanks :)

theOehrly commented 6 months ago

Currently, there are two requirements for a lap that can be used to align the data.

  1. no driver pits on that lap
  2. no driver has retired yet

Assume the following scenario: Driver A pits on the first lap of the GP and then continues the race, driver B retires on the second lap.

With the current logic, it is now impossible to correctly align any of the data.

But in theory, you could align all drivers except driver A based on the first lap. Driver A can then be aligned based on the second lap.

This requires the following:

Also, when a driver retires on the very first lap, it will always be impossible to correctly align that driver with the other drivers. This should not cause the whole alignment procedure to fail, but just leave that one driver unaligned.

HarshitACE commented 6 months ago

Thanks for your response, based on that explanation I have come up with the following strategy:

Can either run it recursively until the entire field is aligned or set a hard "passes" limit, i.e max 3 passes (pass limit would be faster for obvious reasons. Does that sound reasonable?

theOehrly commented 6 months ago

That sounds like a reasonable way to solve this problem 👍

I don't think a hard limit to the number of passes will be necessary. Correctly aligning all data should be preferred over performance, even though performance is important of course. But passes that don't align any drivers should not take much time. And all other passes are time well spent. Apart from this, I expect the computation time to be fairly negligible compared to the overall data loading time.

theOehrly commented 4 months ago

@HarshitACE what's the current status on this? Are you still working on it?

HarshitACE commented 4 months ago

Hey, yes I'm going to tidy it a bit and submit a PR (by next weekend at the earliest).

theOehrly commented 4 months ago

Ok, great to hear 👍