Skip to content

Commit

Permalink
IDEA: improved lap time split
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Sep 5, 2024
1 parent 95f6231 commit b674282
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3340,13 +3340,32 @@ def split_qualifying_sessions(self) -> list[Optional["Laps"]]:
# add the very last timestamp, to get an end for the last interval
split_times.append(self.session.session_status['Time'].iloc[-1])
laps = [None, None, None]
prev_early = None
for i in range(len(split_times) - 1):
# split by start time instead of end time, because the split times
# that are generated from timing data may not account for crashed
# cars being returned or having a generated lap time that results
# in a late 'Time' value!
laps[i] = self[(self['LapStartTime'] > split_times[i])
& (self['LapStartTime'] < split_times[i + 1])]
cond = ((self['LapStartTime'] > split_times[i])
& (self['LapStartTime'] < split_times[i + 1]))

# if this is Q2 or Q3 and there are left over "early" laps from the
# last session, add them to the current session
if prev_early is not None:
cond |= prev_early

# find laps that "start" early, this happens when cars cross the
# timing beam in the pits before the next quali session starts
# is pit out, starts in current session, but ends in next session
is_early = ((self['LapStartTime'] < split_times[i + 1])
& (self['Time'] > split_times[i + 1])
& ~pd.isna(self['PitOutTime']))

# select the laps for the current session, excluding the early laps
laps[i] = self[cond & ~is_early]

prev_early = is_early

if laps[i].empty:
laps[i] = None
return laps
Expand Down

0 comments on commit b674282

Please sign in to comment.