fix(practice): stop flagging a driver's faster pace as suspect laps (1.42.5)
Flagged laps never entered the reference pace, so a driver who got faster had every lap flagged. They now count in the reference (last 10 laps), settled flags are released, and a flagged lap counts until it is removed; Approve only drops the flag.
This commit is contained in:
1 parent
35eb3eb059
commit
2c2b16537e
13 files changed
+132
-47
No files matched your search
+27
-12
@@ -1,11 +1,12 @@
|
||||
// Suspiciously short laps in practice: new drivers and kids sometimes cut across the track,
|
||||
// and the lap lands just above the minimum lap time. Such a lap is far quicker than the
|
||||
// driver's own pace on the same layout, so it is flagged as suspect: it still counts as a
|
||||
// lap, but never as a best lap, personal best, track record or training stat until someone
|
||||
// approves it - or removes it with one click.
|
||||
// driver's own pace on the same layout, so it is flagged for a look. The flag is only a hint:
|
||||
// the lap counts like any other (best lap, stats) until someone removes it with one click;
|
||||
// Approve just drops the flag. It is never called out as a personal best or record.
|
||||
export const SUSPECT_LAP_RATIO = 0.85;
|
||||
export const MIN_REFERENCE_LAPS = 5;
|
||||
const REFERENCE_WINDOW = 20;
|
||||
// Short enough that the reference follows a driver who gets faster during the day.
|
||||
const REFERENCE_WINDOW = 10;
|
||||
|
||||
function median(values) {
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
@@ -13,13 +14,15 @@ function median(values) {
|
||||
return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
|
||||
}
|
||||
|
||||
// The driver's recent normal laps on this layout: counted, not suspect, and not the first lap
|
||||
// of a stint (those span a break and say nothing about pace).
|
||||
// The driver's recent laps on this layout: counted (not removed) and not the first lap of a
|
||||
// stint (those span a break and say nothing about pace). Laps still flagged as suspect are
|
||||
// part of it on purpose: one shortcut hardly moves the median, but a driver who gets faster
|
||||
// during the day (slow warm-up laps, then a real pace) used to have every new lap flagged -
|
||||
// the flagged laps never entered the reference, so it stayed at the slow pace for good.
|
||||
export function getSuspectReferenceLaps(passings, competitorKey, trackLayoutId = "") {
|
||||
return (Array.isArray(passings) ? passings : [])
|
||||
.filter((passing) => passing.competitorKey === competitorKey
|
||||
&& passing.validLap !== false
|
||||
&& !passing.suspect
|
||||
&& !passing.stintBoundary
|
||||
&& String(passing.trackLayoutId ?? trackLayoutId) === String(trackLayoutId))
|
||||
.slice(-REFERENCE_WINDOW)
|
||||
@@ -32,14 +35,26 @@ export function isSuspectLap(lapMs, referenceLaps) {
|
||||
return Number(lapMs) > 0 && Number(lapMs) < median(referenceLaps) * SUSPECT_LAP_RATIO;
|
||||
}
|
||||
|
||||
// A lap that may count for best lap / records / training stats.
|
||||
export function countsForBestLap(passing) {
|
||||
return passing?.validLap !== false && !passing?.suspect;
|
||||
}
|
||||
|
||||
// Suspect laps still waiting for a decision, newest first.
|
||||
export function listPendingSuspectLaps(result) {
|
||||
return (Array.isArray(result?.passings) ? result.passings : [])
|
||||
.filter((passing) => passing.suspect && passing.validLap !== false)
|
||||
.sort((a, b) => Number(b.timestamp || 0) - Number(a.timestamp || 0));
|
||||
}
|
||||
|
||||
// Pending suspect laps of one driver that no longer stand out against the driver's pace now -
|
||||
// it was the driver getting faster, not a shortcut - lose their flag. A real shortcut stays
|
||||
// flagged. Returns the released laps.
|
||||
export function releaseSettledSuspectLaps(passings, competitorKey, trackLayoutId = "") {
|
||||
const reference = getSuspectReferenceLaps(passings, competitorKey, trackLayoutId);
|
||||
const released = [];
|
||||
(Array.isArray(passings) ? passings : []).forEach((passing) => {
|
||||
if (passing.competitorKey !== competitorKey || !passing.suspect || passing.validLap === false) return;
|
||||
if (String(passing.trackLayoutId ?? trackLayoutId) !== String(trackLayoutId)) return;
|
||||
if (isSuspectLap(Number(passing.lapMs || 0), reference)) return;
|
||||
passing.suspect = false;
|
||||
passing.suspectReleased = true;
|
||||
released.push(passing);
|
||||
});
|
||||
return released;
|
||||
}
|
||||
Reference in new issue
Block a user