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
+20
-4
@@ -30,6 +30,7 @@ import { renderEventManagerMarkup } from "./event_manager_view.js";
|
||||
import { renderEventManagerView } from "./event_manager_controller.js";
|
||||
import { createDefaultAmmcConfigHelper, getManagedWsUrlHelper, loadAmmcConfigFromBackendHelper, saveAmmcConfigToBackendHelper, refreshAmmcStatusHelper, startManagedAmmcHelper, stopManagedAmmcHelper, applyPersistedStateHelper, hydrateFromBackendHelper, scheduleBackendSyncHelper, syncStateToBackendHelper, pingBackendHelper, checkAppVersionHelper, startAppVersionPollingHelper, startOverlaySyncHelper, startBackgroundHydrationHelper, startOverlayRotationHelper, startOverlayLiveRefreshHelper, ensureAudioContextHelper, playPassingBeepHelper, playFinishSirenHelper, playLeaderCueHelper, playStartCueHelper, playBestLapCueHelper, pushOverlayEventHelper, getSpeechVoicesHelper, speakTextHelper, announceRaceStartedHelper, announceRaceFinishedHelper, handleSessionTimerTickHelper, tickClockHelper } from "./runtime_services.js";
|
||||
import { connectDecoderHelper, disconnectDecoderHelper, processDecoderMessageHelper } from "./decoder_runtime.js";
|
||||
import { listPendingSuspectLaps, releaseSettledSuspectLaps } from "./suspect_laps_logic.js";
|
||||
import { writeLocalCache } from "./local_cache.js";
|
||||
import { normalizeTrainingState as normalizeTrainingStateLogic, syncTrainingLedger as syncTrainingLedgerLogic, buildDriverTrainingStats as buildDriverTrainingStatsLogic, buildDriverTimingChannelStats as buildDriverTimingChannelStatsLogic, buildDriverActivePracticeStats as buildDriverActivePracticeStatsLogic, buildEvenLapsProgress as buildEvenLapsProgressLogic, buildStepTrainingProgress as buildStepTrainingProgressLogic, buildTrainingRecommendation as buildTrainingRecommendationLogic, getTrainingGoalProgress as getTrainingGoalProgressLogic, getNextTrainingMilestone as getNextTrainingMilestoneLogic, buildTrainingMissions as buildTrainingMissionsLogic, buildTrainingHighlights as buildTrainingHighlightsLogic, getClubTrainingGoalProgress as getClubTrainingGoalProgressLogic, countDriverExerciseSessions as countDriverExerciseSessionsLogic, countExerciseSessions as countExerciseSessionsLogic, buildTrainingPaceBuckets as buildTrainingPaceBucketsLogic, buildTrainingWeekdayStats as buildTrainingWeekdayStatsLogic, buildTrainingStintAnalysis as buildTrainingStintAnalysisLogic, buildTrainingMarkerComparisons as buildTrainingMarkerComparisonsLogic } from "./training_logic.js";
|
||||
import { renderTrainingView } from "./training_views.js";
|
||||
@@ -476,7 +477,7 @@ const renderRaceDay = () => renderRaceDayView({
|
||||
isStartPending: (session) => Boolean(session && pendingStartSessionId === session.id),
|
||||
resetSessionData, startPracticeNow, findOpenPracticeToContinue,
|
||||
getLiveSession,
|
||||
renderSuspectLapsPanel: (session) => renderSuspectLapsPanelView(session, { t, escapeHtml, formatLap, ensureSessionResult }),
|
||||
renderSuspectLapsPanel: (session) => renderSuspectLapsPanelWithRelease(session),
|
||||
setCompetitorLapStatus,
|
||||
addTrackLayout, renderView, state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock,
|
||||
getEventName, getSessionTypeLabel, getStatusLabel, getStartModeLabel,
|
||||
@@ -534,7 +535,7 @@ const refreshTimingDynamics = () => {
|
||||
node.textContent = clock;
|
||||
});
|
||||
};
|
||||
const renderTiming = () => renderTimingView({ state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock, formatRaceClock, renderTable, uid, getActiveSession, ensureSessionResult, buildLeaderboard, getSessionTiming, getVisiblePassings, getEventName, getSessionTypeLabel, getStatusLabel, normalizeStartMode, getStartModeLabel, renderPositionGrid, renderSessionChannelAnalysis, connectDecoder, disconnectDecoder, applyCompetitorCorrection, invalidateCompetitorLastLap, restoreCompetitorLastInvalidLap, startOperationalSession, finishOperationalSession, cancelRaceStart, triggerRaceAudio, getStartLightState: () => raceAudioEngine.getStartLightState(), saveState, updateHeaderState, renderView, normalizeDriver, normalizeCar, processDecoderMessage, getSelectedLeaderboardKey: () => selectedLeaderboardKey, setSelectedLeaderboardKey: (value) => { selectedLeaderboardKey = value; }, getQuickAddDraft: () => quickAddDraft, setQuickAddDraft: (value) => { quickAddDraft = value; }, getPassingValidationLabel, isCountedPassing, getCompetitorPassings, getManualCorrectionSummary, formatTeamActiveMemberLabel, lastFinishAnnouncementSessionId: () => lastFinishAnnouncementSessionId, setLastFinishAnnouncementSessionId: (value) => { lastFinishAnnouncementSessionId = value; }, lastOverlayLeaderKeyBySession, lastOverlayTop3BySession, overlayEvents: () => overlayEvents, setOverlayEvents: (value) => { overlayEvents = value; }, sessionReplay, syncTrainingLedger, setCompetitorLapStatus, getLiveSession, selectLiveSession: (id) => selectOperationalSession(id), openRaceDay: () => navigateToView("race_day"), openJudging: (rowKey) => { selectedJudgeKey = rowKey; selectedLeaderboardKey = null; navigateToView("judging"); } });
|
||||
const renderTiming = () => renderTimingView({ renderSuspectLapsPanel: (session) => renderSuspectLapsPanelWithRelease(session), state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock, formatRaceClock, renderTable, uid, getActiveSession, ensureSessionResult, buildLeaderboard, getSessionTiming, getVisiblePassings, getEventName, getSessionTypeLabel, getStatusLabel, normalizeStartMode, getStartModeLabel, renderPositionGrid, renderSessionChannelAnalysis, connectDecoder, disconnectDecoder, applyCompetitorCorrection, invalidateCompetitorLastLap, restoreCompetitorLastInvalidLap, startOperationalSession, finishOperationalSession, cancelRaceStart, triggerRaceAudio, getStartLightState: () => raceAudioEngine.getStartLightState(), saveState, updateHeaderState, renderView, normalizeDriver, normalizeCar, processDecoderMessage, getSelectedLeaderboardKey: () => selectedLeaderboardKey, setSelectedLeaderboardKey: (value) => { selectedLeaderboardKey = value; }, getQuickAddDraft: () => quickAddDraft, setQuickAddDraft: (value) => { quickAddDraft = value; }, getPassingValidationLabel, isCountedPassing, getCompetitorPassings, getManualCorrectionSummary, formatTeamActiveMemberLabel, lastFinishAnnouncementSessionId: () => lastFinishAnnouncementSessionId, setLastFinishAnnouncementSessionId: (value) => { lastFinishAnnouncementSessionId = value; }, lastOverlayLeaderKeyBySession, lastOverlayTop3BySession, overlayEvents: () => overlayEvents, setOverlayEvents: (value) => { overlayEvents = value; }, sessionReplay, syncTrainingLedger, setCompetitorLapStatus, getLiveSession, selectLiveSession: (id) => selectOperationalSession(id), openRaceDay: () => navigateToView("race_day"), openJudging: (rowKey) => { selectedJudgeKey = rowKey; selectedLeaderboardKey = null; navigateToView("judging"); } });
|
||||
const renderJudging = () => renderJudgingView({ state, dom, t, escapeHtml, formatLap, renderTable, getActiveSession, ensureSessionResult, buildLeaderboard, getSessionTypeLabel, getJudgeFilteredRows, getJudgeFilteredLog, getCompetitorPassings, isCountedPassing, getPassingValidationLabel, undoJudgingAdjustment, applyCompetitorCorrection, invalidateCompetitorLastLap, restoreCompetitorLastInvalidLap, renderView, getSelectedJudgeKey: () => selectedJudgeKey, setSelectedJudgeKey: (value) => { selectedJudgeKey = value; }, getJudgingCompetitorFilter: () => judgingCompetitorFilter, setJudgingCompetitorFilter: (value) => { judgingCompetitorFilter = value; }, getJudgingLogFilter: () => judgingLogFilter, setJudgingLogFilter: (value) => { judgingLogFilter = value; } , setCompetitorLapStatus });
|
||||
const normalizeTrainingState = (training) => normalizeTrainingStateLogic(training, { uid });
|
||||
const syncTrainingLedger = () => {
|
||||
@@ -727,6 +728,21 @@ const applyCompetitorCorrection = (session, row, options = {}) => {
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Before the suspect list is shown: flagged laps that no longer stand out against the
|
||||
// driver's pace now (they got faster, not a shortcut) lose the flag - this also clears laps
|
||||
// flagged under the old rule, where flagged laps never entered the reference.
|
||||
const renderSuspectLapsPanelWithRelease = (session) => {
|
||||
const result = ensureSessionResult(session.id);
|
||||
const keys = new Set(listPendingSuspectLaps(result).map((passing) => passing.competitorKey));
|
||||
let released = 0;
|
||||
keys.forEach((key) => {
|
||||
const count = releaseSettledSuspectLaps(result.passings, key, String(session.trackLayoutId || "")).length;
|
||||
if (count) recalculateCompetitorFromPassings(session, key);
|
||||
released += count;
|
||||
});
|
||||
if (released) saveCorrectionFor(session)();
|
||||
return renderSuspectLapsPanelView(session, { t, escapeHtml, formatLap, ensureSessionResult });
|
||||
};
|
||||
const recalculateCompetitorFromPassings = (session, rowKey) => recalculateCompetitorFromPassingsLogic(session, rowKey, { ensureSessionResult, getCompetitorPassings, isCountedPassing });
|
||||
const invalidateCompetitorLastLap = (session, row) => invalidateCompetitorLastLapLogic(session, row, { ensureSessionResult, getCompetitorPassings, isCountedPassing, recalculateCompetitorFromPassings, uid, t, formatLap, saveState: saveCorrectionFor(session) });
|
||||
const setCompetitorLapStatus = (session, rowKey, passingTimestamp, action) => setCompetitorLapStatusLogic(session, rowKey, passingTimestamp, action, { ensureSessionResult, recalculateCompetitorFromPassings, uid, t, formatLap, saveState: saveCorrectionFor(session) });
|
||||
@@ -1968,7 +1984,7 @@ const TRANSLATIONS = {
|
||||
"timing.lap_restore": "Återställ",
|
||||
"timing.lap_removed": "borttaget",
|
||||
"suspect.title": "Misstänkt korta varv ({count})",
|
||||
"suspect.hint": "Mycket snabbare än förarens egen nivå - ofta en genväg. Räknas som varv men inte som bästa varv, rekord eller i statistiken förrän det godkänns.",
|
||||
"suspect.hint": "Mycket snabbare än förarens egen nivå - kanske en genväg. Varvet räknas som vanligt (även bästa varv och statistik) tills du tar bort det. Godkänn tar bara bort markeringen.",
|
||||
"suspect.approve": "Godkänn",
|
||||
"suspect.flag_title": "Misstänkt kort varv väntar på granskning",
|
||||
"timing.total_passings": "Totala passeringar",
|
||||
@@ -3810,7 +3826,7 @@ const TRANSLATIONS = {
|
||||
"timing.lap_restore": "Restore",
|
||||
"timing.lap_removed": "removed",
|
||||
"suspect.title": "Suspiciously short laps ({count})",
|
||||
"suspect.hint": "Much quicker than the driver's own pace - often a shortcut. Counts as a lap, but not as a best lap, record or in the stats until approved.",
|
||||
"suspect.hint": "Much quicker than the driver's own pace - maybe a shortcut. The lap counts as usual (best lap and stats too) until you remove it. Approve only drops the flag.",
|
||||
"suspect.approve": "Approve",
|
||||
"suspect.flag_title": "Suspiciously short lap waiting for review",
|
||||
"timing.total_passings": "Total passings",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { decoderDiagnostics } from "./decoder_diagnostics.js";
|
||||
import { getControlledLapStreak } from "./training_logic.js";
|
||||
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
|
||||
import { isSuspectLap, getSuspectReferenceLaps } from "./suspect_laps_logic.js";
|
||||
import { isSuspectLap, getSuspectReferenceLaps, releaseSettledSuspectLaps } from "./suspect_laps_logic.js";
|
||||
import { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
|
||||
import { normalizeRaceAudioSettings } from "./race_audio.js";
|
||||
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.js";
|
||||
@@ -535,8 +535,8 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
||||
const layoutId = String(session.trackLayoutId || "");
|
||||
if (entry.bestLapLayoutId === undefined) entry.bestLapLayoutId = layoutId;
|
||||
else if (entry.bestLapLayoutId !== layoutId) { entry.bestLapMs = null; entry.bestLapLayoutId = layoutId; }
|
||||
// Practice only: a lap far quicker than this driver's own pace (a shortcut) counts as a lap
|
||||
// but not as a best lap, record or training stat until approved (suspect_laps_logic.js).
|
||||
// Practice only: a lap far quicker than this driver's own pace (maybe a shortcut) is flagged
|
||||
// for a look. It counts like any other lap until someone removes it (suspect_laps_logic.js).
|
||||
const suspect = PRACTICE_SESSION_TYPES.has(String(session.type || "").toLowerCase())
|
||||
&& !validationWarning
|
||||
&& isSuspectLap(lapMs, getSuspectReferenceLaps(result.passings, key, layoutId));
|
||||
@@ -552,11 +552,16 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
||||
entry.lastLapMs = lapMs;
|
||||
entry.lastTimestamp = timestamp;
|
||||
|
||||
if (lapMs > 500 && !suspect && (!entry.bestLapMs || lapMs < entry.bestLapMs)) {
|
||||
// A suspect lap counts like any other lap until someone removes it; it is only not called
|
||||
// out as a personal best or record below.
|
||||
if (lapMs > 500 && (!entry.bestLapMs || lapMs < entry.bestLapMs)) {
|
||||
entry.bestLapMs = lapMs;
|
||||
}
|
||||
|
||||
result.passings.push(passing);
|
||||
// Earlier flagged laps of this driver that match the pace now were the driver getting
|
||||
// faster, not shortcuts: drop their flag so the list only shows what stands out.
|
||||
if (PRACTICE_SESSION_TYPES.has(String(session.type || "").toLowerCase())) releaseSettledSuspectLaps(result.passings, key, layoutId);
|
||||
persistPassingToBackend(session.id, passing);
|
||||
pushOverlayEvent("passing", `${entry.displayName || entry.driverName} • ${formatLap(entry.lastLapMs)}`);
|
||||
const leaderboard = buildLeaderboard(session);
|
||||
|
||||
@@ -87,7 +87,7 @@ export function recalculateCompetitorFromPassings(session, rowKey, { ensureSessi
|
||||
// before layouts were tagged have no trackLayoutId and still count).
|
||||
const layoutId = String(session.trackLayoutId || "");
|
||||
const bestLapCandidates = validPassings
|
||||
.filter((passing) => !passing.suspect && (passing.trackLayoutId === undefined || String(passing.trackLayoutId) === layoutId))
|
||||
.filter((passing) => passing.trackLayoutId === undefined || String(passing.trackLayoutId) === layoutId)
|
||||
.map((passing) => Number(passing.lapMs || 0)).filter((lapMs) => lapMs > 500);
|
||||
entry.bestLapMs = bestLapCandidates.length ? Math.min(...bestLapCandidates) : null;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export function restoreCompetitorLastInvalidLap(session, row, { ensureSessionRes
|
||||
}
|
||||
|
||||
// One lap, picked by its timestamp: "remove" (invalidate), "restore" (a removed lap counts
|
||||
// again) or "approve" (a suspect practice lap may count as a best lap). Logged and undoable
|
||||
// again) or "approve" (drops a suspect practice lap's flag; the lap counted already). Logged and undoable
|
||||
// like every other judge correction.
|
||||
const LAP_ACTIONS = {
|
||||
remove: { applies: (passing) => passing.validLap !== false, apply: (passing) => { passing.validLap = false; passing.invalidReason = "manual_invalid"; }, label: "timing.lap_remove", undo: { type: "set_passing_validity", validLap: true, invalidReason: "" } },
|
||||
|
||||
+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;
|
||||
}
|
||||
+1
-1
@@ -566,7 +566,7 @@ export function renderTimingView(deps) {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
${active ? renderSuspectLapsPanel(active, { t, escapeHtml, formatLap, ensureSessionResult }) : ""}
|
||||
${active ? (deps.renderSuspectLapsPanel ? deps.renderSuspectLapsPanel(active) : renderSuspectLapsPanel(active, { t, escapeHtml, formatLap, ensureSessionResult })) : ""}
|
||||
<section class="panel mt-16">
|
||||
<div class="panel-header"><h3>${t("timing.leaderboard")}</h3></div>
|
||||
<div class="panel-body">
|
||||
|
||||
@@ -228,8 +228,8 @@ export function syncTrainingLedger(training, state, { uid }) {
|
||||
(Array.isArray(result?.passings) ? result.passings : []).forEach((passing, index) => {
|
||||
const driverId = String(passing?.driverId || "");
|
||||
const lapMs = Math.round(Number(passing?.lapMs || 0) || 0);
|
||||
// A suspect practice lap (a likely shortcut) joins the stats only once it is approved.
|
||||
if (!driverId || passing?.validLap === false || passing?.suspect || lapMs <= 500) return;
|
||||
// A suspect practice lap counts until someone removes it (validLap false).
|
||||
if (!driverId || passing?.validLap === false || lapMs <= 500) return;
|
||||
const timestamp = Math.max(0, Number(passing?.timestamp || 0) || 0);
|
||||
const sourceKey = getPassingSourceKey(sessionId, passing, index);
|
||||
current.push({
|
||||
|
||||
Reference in new issue
Block a user