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.29k stars 239 forks source link

[BUG] Japan position data for RIC and ALB #569

Closed theOehrly closed 3 weeks ago

theOehrly commented 2 months ago

Problem Description

Discussed in https://github.com/theOehrly/Fast-F1/discussions/568

Originally posted by **AreaXimus1** April 8, 2024 For the first lap, the positional data for Ricciardo and Albon puts them in P2 and P3, respectively. Is this just an issue with how the data is collected? ![image](https://github.com/theOehrly/Fast-F1/assets/154688263/d2ab5d2d-fd92-4845-abf4-0ca96f8ca818)

Reason after Analysis

When a driver crashes on the first lap, a lap entry is generated by FastF1 so that the telemetry data for the crash lap is easily accessible (among other things). The driver's positions at the end of each lap are calculated from the timing data ('Time' where a lap was set). But the generated laps have a fictional/assumed end time which is set to be equal to the time of the leader.

Ideas

AND2797 commented 2 months ago

I think the crashed drivers LapTime is currently set to NaT. given that, does it make sense to give the drivers NaN position?

theOehrly commented 2 months ago

I think the crashed drivers LapTime is currently set to NaT. given that, does it make sense to give the drivers NaN position?

That would be an option, given that the position is float dtype already, so NaN is an option. Preferably, we should check what F1 and the FIA are doing and mirror that behaviour. I think the FIA has some official timing document for position per lap and driver? If they are still listed in any position there, then we shouldn't use NaN, if possible. But thinking about it, I would assume that they aren't listed any more on the lap where they crash, as they never make it to the timing line. So NaN would seem good then.

AND2797 commented 2 months ago

I found this: https://www.fia.com/sites/default/files/2024_04_jpn_f1_r0_timing_racelapchart_v02.pdf

Based on it, it seems ALB (23) and RIC (3) are not featured on the Lap 1 positioning.

theOehrly commented 2 months ago

NaN seems like the right choice then.

AND2797 commented 2 months ago

I can look into creating a PR for it.

theOehrly commented 2 months ago

I can look into creating a PR for it.

That would be great 👍

AND2797 commented 1 month ago

snippet to reproduce bug

import fastf1
race = fastf1.get_session(2024, "Japan", "R")
race.load()
laps = race.laps
ric_pos = laps[laps["Driver"] == "RIC"]["Position"]
alb_pos = laps[laps["Driver"] == "ALB"]["Position"]
AND2797 commented 1 month ago

Can we do this - After all positions for all laps have been calculated

What we can also do is -

the problem with this might be that in the future we may use FastF1Generated for some other use cases (other than generating a lap for lap 1 DNF drivers.) this logic may break in that case.

should the crashed drivers get the last positions assigned? In this case, the 'FastF1Generated' flag can be used to filter the laps additionally during calculation

theOehrly commented 1 month ago

Can we do this - After all positions for all laps have been calculated

* filter which drivers have only 1 lap

* if the lap has FastF1Generated = True, we assign NaN position.

I think that is the best solution right now.

the problem with this might be that in the future we may use FastF1Generated for some other use cases (other than generating a lap for lap 1 DNF drivers.) this logic may break in that case.

Yes, but I don't see any other use for this flag right now, because there are no other missing laps that we'd need to generate. And we don't have any other way to do this at the moment without making this much more complicated.