Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
theOehrly opened this issue Mar 10, 2024 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@theOehrly
Copy link
Owner

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)!
@theOehrly theOehrly added the bug Something isn't working label Mar 10, 2024
@theOehrly theOehrly added this to the v3.5.0 milestone Mar 10, 2024
@HarshitACE
Copy link

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
Copy link
Owner Author

theOehrly commented Mar 17, 2024

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:

  • you need to keep track of which drivers have already been aligned
  • an additional constraint (likely) would be that while some drivers may pit on a lap that is used for alignment, the leader must no pit on that lap
  • when splitting the alignment up like that, the leader may be different on these laps and an additional time offset may need to be considered

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
Copy link

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

  • Split the alignment into "passes"
    • First pass will try to align as many drivers as possible, most cases
      this will be enough for the entire field, then we move onto subsequent
      "passes" where it will align the leftover drivers from the first pass
      i.e. Where the left over drivers can be aligned with least number of
      leftover drivers.
    • Once, that lap is found and the leftover drivers are aligned then we
      calculate another offset from the first pass, this will be the gap of
      the leader of this lap (could even be the same leader) to the leader
      of the lap from the first pass.
    • Then we add those offsets together to get the net offset which would
      in turn still be aligned to the "first passes'" lap.

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
Copy link
Owner Author

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
Copy link
Owner Author

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

@HarshitACE
Copy link

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

@theOehrly
Copy link
Owner Author

Ok, great to hear 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants