Skip to content

Commit

Permalink
FIX: missing first lap in Monaco 2024 race in timing data (fixes #594)
Browse files Browse the repository at this point in the history
(cherry picked from commit f3b0e46)
  • Loading branch information
theOehrly committed May 28, 2024
1 parent 57111b2 commit 6aa4c83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions fastf1/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,6 @@ def _laps_data_driver(driver_raw, empty_vals, drv):
in_past = True
continue

if (lapcnt == 0) and ((drv_data['Time'][lapcnt] - to_timedelta(time)) > pd.Timedelta(5, 'min')):
# ignore any data which arrives more than 5 minutes before the end of the first lap, except 'PitOut'
if ('InPit' in resp) and (resp['InPit'] is False):
drv_data['PitOutTime'][lapcnt] = to_timedelta(time)
pitstops = 0 # special here, can be multiple times for no reason therefore set zero instead of +=1
continue

# values which are up to five seconds late are still counted towards the previous lap
# (sector times, speed traps and lap times)
lap_offset = 0
Expand Down Expand Up @@ -706,6 +699,23 @@ def data_in_lap(lap_n):
else:
drv_data['IsPersonalBest'][pb_idx] = True

# fix the number of pit stops; due to potentially multiple laps to the grid
# where a car goes through the pit lane before finally taking its place
# on the grid, the number of pit stops on the first lap may be already
# greater than zero; therefore, apply correction so that we start with zero
pitstop_offset = drv_data['NumberOfPitStops'][0]
for i in range(len(drv_data['NumberOfPitStops'])):
drv_data['NumberOfPitStops'][i] -= pitstop_offset

# fix first lap PitInTime; same reason as above for pit stops, there may
# be an incorrect PitInTime on the first lap. There always is a PitOutTime
# for when the car leaves the box for the lap to the grid. There is a
# PitInTime if the car drives multiple laps to the grid, discard these.
# There is also a PitInTime if the car actually pits at the end of the
# first lap, those need to be kept.
if drv_data['PitInTime'][0] < drv_data['PitOutTime'][0]:
drv_data['PitInTime'][0] = pd.NaT

if integrity_errors:
_logger.warning(
f"Driver {drv: >2}: Encountered {len(integrity_errors)} timing "
Expand Down
2 changes: 1 addition & 1 deletion fastf1/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Cache(metaclass=_MetaCache):
"""
_CACHE_DIR = None
# version of the api parser code (unrelated to release version number)
_API_CORE_VERSION = 12
_API_CORE_VERSION = 13
_IGNORE_VERSION = False
_FORCE_RENEW = False

Expand Down

0 comments on commit 6aa4c83

Please sign in to comment.