Skip to content

Commit

Permalink
ENH: improve lap integrity Check with previous lap "Time" (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-tomasino authored Oct 17, 2023
1 parent cd115fc commit 25339e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,7 @@ def _check_lap_accuracy(self):
prev_lap = None
integrity_errors = 0
for _, lap in self.laps[self.laps['DriverNumber'] == drv].iterrows():
lap_integrity_ok = True
# require existence, non-existence and specific values for some variables
check_1 = (pd.isnull(lap['PitInTime'])
& pd.isnull(lap['PitOutTime'])
Expand All @@ -1889,7 +1890,7 @@ def _check_lap_accuracy(self):
lap['LapTime'].total_seconds(),
atol=0.003, rtol=0, equal_nan=False)
if not check_2:
integrity_errors += 1
lap_integrity_ok = False
else:
check_2 = False # data not available means fail

Expand All @@ -1899,7 +1900,31 @@ def _check_lap_accuracy(self):
else:
check_3 = True # no previous lap, no SC error

result = check_1 and check_2 and check_3
pre_check_4 = (((not pd.isnull(lap['Time']))
& (not pd.isnull(lap['LapTime'])))
and (prev_lap is not None)
and (not pd.isnull(prev_lap['Time'])))

if pre_check_4: # needed condition for check_4
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:
lap_integrity_ok = False

else:
check_4 = True

if not lap_integrity_ok:
integrity_errors += 1

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 @@ -110,7 +110,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 25339e1

Please sign in to comment.