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] Restart lap times after the red flag #473

Open
formulatimer opened this issue Oct 30, 2023 · 10 comments
Open

[BUG] Restart lap times after the red flag #473

formulatimer opened this issue Oct 30, 2023 · 10 comments
Labels
bug Something isn't working
Milestone

Comments

@formulatimer
Copy link
Contributor

Describe the issue:

Hi,

During the Mexican GP, a Red Flag was displayed on lap 34, prompting the drivers to return to the pit lane.
Lap 35 began when VER crossed the line and entered the pit lane, essentially becoming the "formation lap" behind the safety car.
Lap 36 began when VER crossed the line and then waited on the grid for the race to restart.

In lap 36, the LapTime is recorded as NaT for the first 5 drivers in that lap (VER, HAM, LEC, SAI, RIC), while the other drivers have LapTimes around 2 minutes and 20 seconds.
Given that the TrackStatus in Lap 36 is "1" (Green Flag), I am unable to filter the lap by TrackStatus, PitInTime, or PitOutTime. I believe this may be an inconsistency.

I hope it will be easy to undertsant and thank for your effort

Reproduce the code example:

session = fastf1.get_session(2023, 'Mexico', 'R')
session.load(laps=True, telemetry=False, weather=False, messages=False, livedata=None)
laps=session.laps

Error message:

No response

@theOehrly
Copy link
Owner

I had to do some research to figure out what the correct behaviour here should be.

Quoting from the current sporting regulations:

57.4 Whilst the sprint session or the race is suspended:
a) The sprint session, the race nor the timekeeping system will stop [...]

This would indicate that the timing just keeps going. Therefore, the lap time for lap 35 should include the duration of the pause, given that the timing beam is at the entry of the pit lane. Similarly, the lap time for lap 36 should include the time that the car is stationary on the grid.

This is backed up by the lap time analysis that the FIA makes available. Here is lap 34 to 36 for Verstappen:
grafik

From this, it seems that the only issue in FastF1 is that the first five drivers have a NaT lap time. But the rest is correct, right?

What exactly do you mean with

I am unable to filter the lap by TrackStatus, PitInTime, or PitOutTime

Did you want to remove or select the restart lap?

@formulatimer
Copy link
Contributor Author

I want to remove the restart lap because I want to calculate the average pace of each driver excluding VSC, SC, Red flags, PitIn laps, PitOut laps. I think the TrackStatus in a restartlap should not be 1 (green flag) otherwise i do not know other way to remove the restart lap

@theOehrly
Copy link
Owner

You can just remove the restart lap by its lap number.

Something like :

racing_laps = laps[laps['LapNumber'] != 36]

(disclaimer: untested code)

This is just normal pandas dataframe indexing to select all laps where the LapNumber is not 36.

@theOehrly
Copy link
Owner

I think the TrackStatus in a restartlap should not be 1 (green flag)

If the green flag is shown before the drivers cross the timing line (I'm going to check that this was actually the case) then the entirety of the 36th lap was under green flag conditions. Even though the restart procedure is included in that lap.
I'm going to adhere to the procedure and meaning as described in the sporting regulations here. I am not going to redefine what the meaning of a green flag is.

@formulatimer
Copy link
Contributor Author

You can just remove the restart lap by its lap number

Yes, but I am trying to do a code that works in any race, so the deleted lap should not be a constant

If the green flag is shown before the drivers cross the timing line

Yes, it was the case

I am not going to redefine what the meaning of a green flag is.

I agree. I have reviewed the documentation and '1' indicates 'Track Clear' instead of 'Green Flag', maybe a new value can be added to indicate standing start in that lap, for example: ‘8’: Standing Start and the Track Status of the lap 36 should have been '81' or '18' or '181'

Here I show the documentation about Track Status changes:
‘1’: Track clear (beginning of session ot to indicate the end of another status)
‘2’: Yellow flag (sectors are unknown)
‘3’: ??? Never seen so far, does not exist?
‘4’: Safety Car
‘5’: Red Flag
‘6’: Virtual Safety Car deployed
‘7’: Virtual Safety Car ending (As indicated on the drivers steering wheel, on tv and so on; status ‘1’ will mark the actual end)

Thanks!

@theOehrly
Copy link
Owner

I have reviewed the documentation and '1' indicates 'Track Clear' instead of 'Green Flag'

In fact, green flag indicates "track clear". So these two are equivalent.
The restart procedure just takes place under green flag conditions.

maybe a new value can be added to indicate standing start in that lap, for example: ‘8’

No, because the restart procedure is not a track status. So this is technically incorrect. We would need to use a different way to indicate the restart.

I understand that the data in its current form is not the most practical for you. But you will need to use a different approach for now. Either manually removing the lap. Or removing every lap after a red flag or something like that.

@formulatimer
Copy link
Contributor Author

Hi again,

I have reviewed the data and determined how the information is obtained from it. I found that the "RaceControlMessages.jsonStream" contains information about whether the restart is a "standing start" or a "rolling start" after a red flag. Since I am only interested in removing the "standing start," I can search for it in the race control messages and remove lap+1 when the "standing start" is reported.

Upon checking the documentation, I noticed that "fastf1.core.Session.race_control_messages" does not include the lap of the messages. Do you think it is possible to add the lap information to the messages in future versions? This information is written in https://livetiming.formula1.com/static/2023/2023-10-29_Mexico_City_Grand_Prix/2023-10-29_Race/RaceControlMessages.json

import fastf1
term = fastf1.get_session(2023,'Mexico','R')
term.load(laps=True, telemetry=True, weather=False, messages=True, livedata=None)
messages_info=term.race_control_messages
print(messages_info)

Thanks!

@formulatimer
Copy link
Contributor Author

Hi, i have just created the pull request #475 to add a new column called 'Lap' that contains the Lap information written in RaceControlMessages.jsonStream.

I have tested it and it works, but it is my first pull request in github. I am not sure if I have done everything correctly

Thanks

@theOehrly
Copy link
Owner

In lap 36, the LapTime is recorded as NaT for the first 5 drivers in that lap (VER, HAM, LEC, SAI, RIC), while the other drivers have LapTimes around 2 minutes and 20 seconds.

I've investigated this part now as well. The "problem" is that lap times >=2:30.000 are intentionally ignored in the api parser to filter out some incorrect data. I guess that limit is chosen somewhat unfortunate here. Fixing this correctly (not just increasing the limit slightly) might be a bit more complicated but I'll try to look into that soon.

@theOehrly theOehrly added the bug Something isn't working label Nov 23, 2023
@theOehrly theOehrly added this to the v3.2.0 milestone Nov 23, 2023
@theOehrly theOehrly modified the milestones: v3.2.0, v3.3.0 Jan 5, 2024
@theOehrly
Copy link
Owner

This needs to be tackled when the API parser is rewritten (fairly high priority). Removing that 2:30 filter leads down a rabbit hole of properly handling a range of weird edge cases in the API that are really difficult to fix properly in the current implementation.
(for example, when the sum of two lap times is given as a single lap time in the raw data ... wtf)

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