Skip to content

Commit

Permalink
Previous Lap Integrity Check
Browse files Browse the repository at this point in the history
  • Loading branch information
d-tomasino committed Sep 21, 2023
1 parent 317bacf commit 9da52b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@ def _check_lap_accuracy(self):
prev_lap = None
integrity_errors = 0
for _, lap in self.laps[self.laps['DriverNumber'] == drv].iterrows():
lap_integrity_flag = True #to avoid to add two integrity_errors for the same lap
# require existence, non-existence and specific values for some variables
check_1 = (pd.isnull(lap['PitInTime'])
& pd.isnull(lap['PitOutTime'])
Expand All @@ -1884,16 +1885,45 @@ def _check_lap_accuracy(self):
atol=0.003, rtol=0, equal_nan=False)
if not check_2:
integrity_errors += 1
lap_integrity_flag = False
else:
check_2 = False # data not available means fail

if prev_lap is not None:
if (not pd.isnull(prev_lap['Time'])):
prev_lap_check = True #it's needed for check_4
else:
prev_lap_check = False
# first lap after safety car often has timing issues (as do all laps under safety car)
check_3 = (prev_lap['TrackStatus'] != '4')
else:
prev_lap_check = False
check_3 = True # no previous lap, no SC error

result = check_1 and check_2 and check_3

pre_check_4 = (prev_lap_check
& (not pd.isnull(lap['Time']))
& (not pd.isnull(lap['LapTime'])))

if pre_check_4:
pass
time_diff = np.sum((lap['Time'], -1 * prev_lap['Time'])).total_seconds()
lap_time = lap['LapTime'].total_seconds()
# If the difference between the two times is within a
# certain tolerance, the lap time data is considered to be valid.
check_4 = np.allclose(time_diff, lap_time, atol=0.003, rtol=0, equal_nan=False)

if not check_4 and lap_integrity_flag:
integrity_errors += 1
lap_integrity_flag = False
else:
pass
if not prev_lap_check:
check_4 = True #can't check if previous lap or its lap 'Time' is missing
else:
check_4 = False #data on current lap not available, means fail

result = check_1 and check_2 and check_3 #and check_4
is_accurate.append(result)
prev_lap = lap

Expand Down
2 changes: 1 addition & 1 deletion fastf1/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
identifier to differentiate between the various sessions of one event.
This identifier can currently be one of the following:
- session name abbreviation: ``'FP1', 'FP2', 'FP3', 'Q', 'S', 'SS', R'``
- session name abbreviation: ``'FP1', 'FP2', 'FP3', 'Q', 'S', 'SS', 'R'``
- full session name: ``'Practice 1', 'Practice 2',
'Practice 3', 'Sprint', 'Sprint Shootout', 'Qualifying', 'Race'``;
provided names will be normalized, so that the name is
Expand Down

0 comments on commit 9da52b4

Please sign in to comment.