feat(practice): flag suspiciously short laps and remove any lap in one click
Practice laps under 85% of the driver's own median (a likely shortcut) are flagged: counted, but never a best lap, record or training stat until approved. Timing and Race Day get a one-click Approve/Remove panel, overlays show a warning mark, and any lap can be removed or restored from Timing and Judging with undo. Also sends judge corrections straight to the server so its hot-results protection can no longer hold back a correction made right after a passing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cc4fa0845
commit
8601954ea2
24 files changed
+556
-60
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// 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.
|
||||
export const SUSPECT_LAP_RATIO = 0.85;
|
||||
export const MIN_REFERENCE_LAPS = 5;
|
||||
const REFERENCE_WINDOW = 20;
|
||||
|
||||
function median(values) {
|
||||
const sorted = [...values].sort((a, b) => a - b);
|
||||
const middle = Math.floor(sorted.length / 2);
|
||||
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).
|
||||
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)
|
||||
.map((passing) => Number(passing.lapMs || 0))
|
||||
.filter((lapMs) => lapMs > 500);
|
||||
}
|
||||
|
||||
export function isSuspectLap(lapMs, referenceLaps) {
|
||||
if (!Array.isArray(referenceLaps) || referenceLaps.length < MIN_REFERENCE_LAPS) return false;
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user