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] Laps "split_qualifying_sessions" doesn't split laps correctly. #605

Open Tom-Archer opened 3 months ago

Tom-Archer commented 3 months ago

Describe the issue:

Attempting to use "split_qualifying_sessions" and "pick_drivers" doesn't seem to correctly split the laps.

See the output from the code example. Lap 15 is actually a Q2 lap. Lap 18 is actually a Q3 lap.

Reproduce the code example:

import fastf1

event = fastf1.get_event(2024, "Spain")
session = event.get_session("Q")
session.load(telemetry=False, laps=True, weather=False)
q1_laps, q2_laps, q3_laps = session.laps.pick_drivers("VER").split_qualifying_sessions()

print(q1_laps)
print("===")
print(q2_laps)
print("===")
print(q3_laps)

Error message:

Time Driver DriverNumber  ... DeletedReason  FastF1Generated  IsAccurate
12 0 days 00:19:52.736000    VER            1  ...                          False       False
13 0 days 00:21:05.042000    VER            1  ...                          False        True
14 0 days 00:22:47.851000    VER            1  ...                          False       False
15 0 days 00:45:51.261000    VER            1  ...                          False       False

[4 rows x 31 columns]
===
                     Time Driver DriverNumber  ... DeletedReason  FastF1Generated  IsAccurate
16 0 days 00:47:02.914000    VER            1  ...                          False        True
17 0 days 00:48:38.541000    VER            1  ...                          False       False
18 0 days 01:04:10.070000    VER            1  ...                          False       False

[3 rows x 31 columns]
===
                     Time Driver DriverNumber  ... DeletedReason  FastF1Generated  IsAccurate
19 0 days 01:05:21.743000    VER            1  ...                          False        True
20 0 days 01:06:59.915000    VER            1  ...                          False       False
21 0 days 01:12:40.726000    VER            1  ...                          False       False
22 0 days 01:13:52.129000    VER            1  ...                          False        True
23 0 days 01:15:29.255000    VER            1  ...                          False       False

[5 rows x 31 columns]
Tom-Archer commented 3 months ago

Is this due to the position of a driver's garage in relation to the timing beam. I.e. VER crosses the timing beam after his 3rd lap in Q1, technically starting his 4th lap. The 4th lap isn't completed until the end of his out lap in Q2?

theOehrly commented 3 months ago

This will be either due to the position of the garage or because drivers start lining up at the red light at pit exit. Either way, the most probable cause is that they cross the timing beam before the start of the next qualifying session, as you suggested. The fix should be fairly straightforward. There likely just needs to be some more logic added to differentiate between in-laps and out-laps to differentiate between crossing the timing beam on the way in or on track versus on the way out. PRs are welcome for this :)