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

Lap Integrity Check with previous lap "Time" #449

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 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,42 @@ 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'])):
d-tomasino marked this conversation as resolved.
Show resolved Hide resolved
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: # needed condition for check_4
d-tomasino marked this conversation as resolved.
Show resolved Hide resolved
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:
d-tomasino marked this conversation as resolved.
Show resolved Hide resolved
integrity_errors += 1
lap_integrity_flag = False
else:
d-tomasino marked this conversation as resolved.
Show resolved Hide resolved
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
Loading