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
@@ -8,6 +8,16 @@ The application version is maintained in `package.json` and displayed in the adm
|
|||||||
|
|
||||||
No changes recorded yet.
|
No changes recorded yet.
|
||||||
|
|
||||||
|
## 1.42.5 - 2026-10-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Suspiciously short laps: far fewer false flags.** A driver who got faster during the day (slow warm-up laps, then a real pace) had every lap at the new pace flagged - over 50 in one practice - because flagged laps never entered the driver's reference pace, so it stayed at the slow level for good. Flagged laps are now part of the reference (one shortcut hardly moves it), the reference is the last 10 laps instead of 20, and earlier flags that no longer stand out against the driver's pace are released automatically - also those already flagged under the old rule, as soon as Timing or Race Day shows the list. A real one-off shortcut stays flagged.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **A flagged lap counts like any other lap until someone removes it** - as best lap and in the training stats too. **Remove** takes it out; **Approve** only drops the flag. It is still never called out as a personal best or record.
|
||||||
|
|
||||||
## 1.42.4 - 2026-10-25
|
## 1.42.4 - 2026-10-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^12.11.1",
|
"better-sqlite3": "^12.11.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.42.4",
|
"version": "1.42.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+20
-4
@@ -30,6 +30,7 @@ import { renderEventManagerMarkup } from "./event_manager_view.js";
|
|||||||
import { renderEventManagerView } from "./event_manager_controller.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 { 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 { connectDecoderHelper, disconnectDecoderHelper, processDecoderMessageHelper } from "./decoder_runtime.js";
|
||||||
|
import { listPendingSuspectLaps, releaseSettledSuspectLaps } from "./suspect_laps_logic.js";
|
||||||
import { writeLocalCache } from "./local_cache.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 { 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";
|
import { renderTrainingView } from "./training_views.js";
|
||||||
@@ -476,7 +477,7 @@ const renderRaceDay = () => renderRaceDayView({
|
|||||||
isStartPending: (session) => Boolean(session && pendingStartSessionId === session.id),
|
isStartPending: (session) => Boolean(session && pendingStartSessionId === session.id),
|
||||||
resetSessionData, startPracticeNow, findOpenPracticeToContinue,
|
resetSessionData, startPracticeNow, findOpenPracticeToContinue,
|
||||||
getLiveSession,
|
getLiveSession,
|
||||||
renderSuspectLapsPanel: (session) => renderSuspectLapsPanelView(session, { t, escapeHtml, formatLap, ensureSessionResult }),
|
renderSuspectLapsPanel: (session) => renderSuspectLapsPanelWithRelease(session),
|
||||||
setCompetitorLapStatus,
|
setCompetitorLapStatus,
|
||||||
addTrackLayout, renderView, state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock,
|
addTrackLayout, renderView, state, dom, t, escapeHtml, formatLap, formatCountdown, formatElapsedClock,
|
||||||
getEventName, getSessionTypeLabel, getStatusLabel, getStartModeLabel,
|
getEventName, getSessionTypeLabel, getStatusLabel, getStartModeLabel,
|
||||||
@@ -534,7 +535,7 @@ const refreshTimingDynamics = () => {
|
|||||||
node.textContent = clock;
|
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 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 normalizeTrainingState = (training) => normalizeTrainingStateLogic(training, { uid });
|
||||||
const syncTrainingLedger = () => {
|
const syncTrainingLedger = () => {
|
||||||
@@ -727,6 +728,21 @@ const applyCompetitorCorrection = (session, row, options = {}) => {
|
|||||||
}
|
}
|
||||||
return result;
|
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 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 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) });
|
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_restore": "Återställ",
|
||||||
"timing.lap_removed": "borttaget",
|
"timing.lap_removed": "borttaget",
|
||||||
"suspect.title": "Misstänkt korta varv ({count})",
|
"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.approve": "Godkänn",
|
||||||
"suspect.flag_title": "Misstänkt kort varv väntar på granskning",
|
"suspect.flag_title": "Misstänkt kort varv väntar på granskning",
|
||||||
"timing.total_passings": "Totala passeringar",
|
"timing.total_passings": "Totala passeringar",
|
||||||
@@ -3810,7 +3826,7 @@ const TRANSLATIONS = {
|
|||||||
"timing.lap_restore": "Restore",
|
"timing.lap_restore": "Restore",
|
||||||
"timing.lap_removed": "removed",
|
"timing.lap_removed": "removed",
|
||||||
"suspect.title": "Suspiciously short laps ({count})",
|
"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.approve": "Approve",
|
||||||
"suspect.flag_title": "Suspiciously short lap waiting for review",
|
"suspect.flag_title": "Suspiciously short lap waiting for review",
|
||||||
"timing.total_passings": "Total passings",
|
"timing.total_passings": "Total passings",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { decoderDiagnostics } from "./decoder_diagnostics.js";
|
import { decoderDiagnostics } from "./decoder_diagnostics.js";
|
||||||
import { getControlledLapStreak } from "./training_logic.js";
|
import { getControlledLapStreak } from "./training_logic.js";
|
||||||
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_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 { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
|
||||||
import { normalizeRaceAudioSettings } from "./race_audio.js";
|
import { normalizeRaceAudioSettings } from "./race_audio.js";
|
||||||
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.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 || "");
|
const layoutId = String(session.trackLayoutId || "");
|
||||||
if (entry.bestLapLayoutId === undefined) entry.bestLapLayoutId = layoutId;
|
if (entry.bestLapLayoutId === undefined) entry.bestLapLayoutId = layoutId;
|
||||||
else if (entry.bestLapLayoutId !== layoutId) { entry.bestLapMs = null; 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
|
// Practice only: a lap far quicker than this driver's own pace (maybe a shortcut) is flagged
|
||||||
// but not as a best lap, record or training stat until approved (suspect_laps_logic.js).
|
// 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())
|
const suspect = PRACTICE_SESSION_TYPES.has(String(session.type || "").toLowerCase())
|
||||||
&& !validationWarning
|
&& !validationWarning
|
||||||
&& isSuspectLap(lapMs, getSuspectReferenceLaps(result.passings, key, layoutId));
|
&& isSuspectLap(lapMs, getSuspectReferenceLaps(result.passings, key, layoutId));
|
||||||
@@ -552,11 +552,16 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
|
|||||||
entry.lastLapMs = lapMs;
|
entry.lastLapMs = lapMs;
|
||||||
entry.lastTimestamp = timestamp;
|
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;
|
entry.bestLapMs = lapMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.passings.push(passing);
|
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);
|
persistPassingToBackend(session.id, passing);
|
||||||
pushOverlayEvent("passing", `${entry.displayName || entry.driverName} • ${formatLap(entry.lastLapMs)}`);
|
pushOverlayEvent("passing", `${entry.displayName || entry.driverName} • ${formatLap(entry.lastLapMs)}`);
|
||||||
const leaderboard = buildLeaderboard(session);
|
const leaderboard = buildLeaderboard(session);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export function recalculateCompetitorFromPassings(session, rowKey, { ensureSessi
|
|||||||
// before layouts were tagged have no trackLayoutId and still count).
|
// before layouts were tagged have no trackLayoutId and still count).
|
||||||
const layoutId = String(session.trackLayoutId || "");
|
const layoutId = String(session.trackLayoutId || "");
|
||||||
const bestLapCandidates = validPassings
|
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);
|
.map((passing) => Number(passing.lapMs || 0)).filter((lapMs) => lapMs > 500);
|
||||||
entry.bestLapMs = bestLapCandidates.length ? Math.min(...bestLapCandidates) : null;
|
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
|
// 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.
|
// like every other judge correction.
|
||||||
const LAP_ACTIONS = {
|
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: "" } },
|
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,
|
// 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
|
// 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
|
// driver's own pace on the same layout, so it is flagged for a look. The flag is only a hint:
|
||||||
// lap, but never as a best lap, personal best, track record or training stat until someone
|
// the lap counts like any other (best lap, stats) until someone removes it with one click;
|
||||||
// approves it - or 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 SUSPECT_LAP_RATIO = 0.85;
|
||||||
export const MIN_REFERENCE_LAPS = 5;
|
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) {
|
function median(values) {
|
||||||
const sorted = [...values].sort((a, b) => a - b);
|
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;
|
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
|
// The driver's recent laps on this layout: counted (not removed) and not the first lap of a
|
||||||
// of a stint (those span a break and say nothing about pace).
|
// 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 = "") {
|
export function getSuspectReferenceLaps(passings, competitorKey, trackLayoutId = "") {
|
||||||
return (Array.isArray(passings) ? passings : [])
|
return (Array.isArray(passings) ? passings : [])
|
||||||
.filter((passing) => passing.competitorKey === competitorKey
|
.filter((passing) => passing.competitorKey === competitorKey
|
||||||
&& passing.validLap !== false
|
&& passing.validLap !== false
|
||||||
&& !passing.suspect
|
|
||||||
&& !passing.stintBoundary
|
&& !passing.stintBoundary
|
||||||
&& String(passing.trackLayoutId ?? trackLayoutId) === String(trackLayoutId))
|
&& String(passing.trackLayoutId ?? trackLayoutId) === String(trackLayoutId))
|
||||||
.slice(-REFERENCE_WINDOW)
|
.slice(-REFERENCE_WINDOW)
|
||||||
@@ -32,14 +35,26 @@ export function isSuspectLap(lapMs, referenceLaps) {
|
|||||||
return Number(lapMs) > 0 && Number(lapMs) < median(referenceLaps) * SUSPECT_LAP_RATIO;
|
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.
|
// Suspect laps still waiting for a decision, newest first.
|
||||||
export function listPendingSuspectLaps(result) {
|
export function listPendingSuspectLaps(result) {
|
||||||
return (Array.isArray(result?.passings) ? result.passings : [])
|
return (Array.isArray(result?.passings) ? result.passings : [])
|
||||||
.filter((passing) => passing.suspect && passing.validLap !== false)
|
.filter((passing) => passing.suspect && passing.validLap !== false)
|
||||||
.sort((a, b) => Number(b.timestamp || 0) - Number(a.timestamp || 0));
|
.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>
|
</div>
|
||||||
</section>
|
</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">
|
<section class="panel mt-16">
|
||||||
<div class="panel-header"><h3>${t("timing.leaderboard")}</h3></div>
|
<div class="panel-header"><h3>${t("timing.leaderboard")}</h3></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|||||||
@@ -228,8 +228,8 @@ export function syncTrainingLedger(training, state, { uid }) {
|
|||||||
(Array.isArray(result?.passings) ? result.passings : []).forEach((passing, index) => {
|
(Array.isArray(result?.passings) ? result.passings : []).forEach((passing, index) => {
|
||||||
const driverId = String(passing?.driverId || "");
|
const driverId = String(passing?.driverId || "");
|
||||||
const lapMs = Math.round(Number(passing?.lapMs || 0) || 0);
|
const lapMs = Math.round(Number(passing?.lapMs || 0) || 0);
|
||||||
// A suspect practice lap (a likely shortcut) joins the stats only once it is approved.
|
// A suspect practice lap counts until someone removes it (validLap false).
|
||||||
if (!driverId || passing?.validLap === false || passing?.suspect || lapMs <= 500) return;
|
if (!driverId || passing?.validLap === false || lapMs <= 500) return;
|
||||||
const timestamp = Math.max(0, Number(passing?.timestamp || 0) || 0);
|
const timestamp = Math.max(0, Number(passing?.timestamp || 0) || 0);
|
||||||
const sourceKey = getPassingSourceKey(sessionId, passing, index);
|
const sourceKey = getPassingSourceKey(sessionId, passing, index);
|
||||||
current.push({
|
current.push({
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ export async function runSuspectLapsSmoke({ evaluate, navigate, savedState, wait
|
|||||||
const shortLap = (await results()).passings.at(-1);
|
const shortLap = (await results()).passings.at(-1);
|
||||||
assert.equal(shortLap.lapMs, 14000);
|
assert.equal(shortLap.lapMs, 14000);
|
||||||
assert.equal(shortLap.suspect, true, "flagged as suspect");
|
assert.equal(shortLap.suspect, true, "flagged as suspect");
|
||||||
assert.equal((await results()).competitors.driver_sl_driver.bestLapMs, 19800, "not used as the best lap");
|
assert.equal((await results()).competitors.driver_sl_driver.bestLapMs, 14000, "it counts like any lap until someone removes it");
|
||||||
|
|
||||||
await waitFor(async () => Boolean(await evaluate(`document.getElementById("suspectLapsPanel")`)), "suspect panel on Timing");
|
await waitFor(async () => Boolean(await evaluate(`document.getElementById("suspectLapsPanel")`)), "suspect panel on Timing");
|
||||||
assert.match(await evaluate(`document.getElementById("suspectLapsPanel").innerText`), /SL Kid/);
|
assert.match(await evaluate(`document.getElementById("suspectLapsPanel").innerText`), /SL Kid/);
|
||||||
assert.equal(await evaluate(`Boolean([...document.querySelectorAll(".table-primary")].find((node) => node.textContent.includes("SL Kid"))?.querySelector(".suspect-flag"))`), true, "⚠ in the leaderboard");
|
assert.equal(await evaluate(`Boolean([...document.querySelectorAll(".table-primary")].find((node) => node.textContent.includes("SL Kid"))?.querySelector(".suspect-flag"))`), true, "⚠ in the leaderboard");
|
||||||
console.log("PASS a lap far quicker than the driver's own pace is flagged on Timing and not used as the best lap");
|
console.log("PASS a lap far quicker than the driver's own pace is flagged on Timing but counts until removed");
|
||||||
|
|
||||||
await navigate("overlay", "view");
|
await navigate("overlay", "view");
|
||||||
await waitFor(async () => evaluate(`document.body.innerText.includes("SL Kid")`), "overlay shows the driver");
|
await waitFor(async () => evaluate(`document.body.innerText.includes("SL Kid")`), "overlay shows the driver");
|
||||||
@@ -69,9 +69,27 @@ export async function runSuspectLapsSmoke({ evaluate, navigate, savedState, wait
|
|||||||
const after = await results();
|
const after = await results();
|
||||||
assert.equal(after.passings.at(-1).invalidReason, "manual_invalid");
|
assert.equal(after.passings.at(-1).invalidReason, "manual_invalid");
|
||||||
assert.equal(after.competitors.driver_sl_driver.laps, 6, "no longer counted");
|
assert.equal(after.competitors.driver_sl_driver.laps, 6, "no longer counted");
|
||||||
|
assert.equal(after.competitors.driver_sl_driver.bestLapMs, 19800, "and no longer the best lap");
|
||||||
assert.ok(after.adjustments?.some((adjustment) => adjustment.category === "invalid"), "logged as a judge correction (undoable)");
|
assert.ok(after.adjustments?.some((adjustment) => adjustment.category === "invalid"), "logged as a judge correction (undoable)");
|
||||||
await waitFor(async () => !(await evaluate(`Boolean(document.getElementById("suspectLapsPanel"))`)), "panel gone once nothing is pending");
|
await waitFor(async () => !(await evaluate(`Boolean(document.getElementById("suspectLapsPanel"))`)), "panel gone once nothing is pending");
|
||||||
console.log("PASS one click removes the suspect lap and it is logged as an undoable correction");
|
console.log("PASS one click removes the suspect lap and it is logged as an undoable correction");
|
||||||
|
|
||||||
|
// Flags from the old rule (flagged laps never entered the reference): a driver who simply
|
||||||
|
// got faster had every lap at the new pace flagged. Opening Timing releases those.
|
||||||
|
const pace = [23000, 23400, 22900, 23100, 23300, 19000, 19200, 18900, 19100, 18800, 19300, 19000];
|
||||||
|
let paceTs = Date.now() - 400000;
|
||||||
|
const pacePassings = pace.map((lapMs, index) => { paceTs += lapMs; return { driverId: "sl_fast", driverName: "SL Fast", displayName: "SL Fast", competitorKey: "driver_sl_fast", transponder: "8330002", lapMs, timestamp: paceTs, validLap: true, suspect: index >= 5 }; });
|
||||||
|
const current = await results();
|
||||||
|
// The session is live: write its results the way a correction does (a full-state save
|
||||||
|
// can't overwrite live results), then reload so the page hydrates them.
|
||||||
|
const sessionResult = { ...current, passings: [...current.passings, ...pacePassings], competitors: { ...current.competitors, driver_sl_fast: { key: "driver_sl_fast", driverId: "sl_fast", driverName: "SL Fast", displayName: "SL Fast", transponder: "8330002", laps: pace.length, lastLapMs: 19000, bestLapMs: 22900, startTimestamp: startedAt, lastTimestamp: paceTs } } };
|
||||||
|
const stored = await fetch(base + "/api/session-results", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ sessionId: practice.id, sessionResult }) });
|
||||||
|
assert.equal(stored.ok, true);
|
||||||
|
assert.equal((await results()).passings.filter((passing) => passing.competitorKey === "driver_sl_fast" && passing.suspect).length, 7, "seven laps flagged under the old rule");
|
||||||
|
await navigate("timing", "activeSessionSelect");
|
||||||
|
await waitFor(async () => { const fast = (await results()).passings.filter((passing) => passing.competitorKey === "driver_sl_fast"); return fast.length === pace.length && !fast.some((passing) => passing.suspect); }, "the old flags at the driver's real pace are released");
|
||||||
|
assert.equal((await results()).competitors.driver_sl_fast.bestLapMs, 18800, "and the best lap is recalculated");
|
||||||
|
console.log("PASS laps flagged under the old rule at a driver's real (faster) pace are released");
|
||||||
} finally {
|
} finally {
|
||||||
dialogs.splice(dialogsAtStart);
|
dialogs.splice(dialogsAtStart);
|
||||||
const current = await savedState();
|
const current = await savedState();
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ test("practice on a fresh pack: no personal best calls for the first ten laps, t
|
|||||||
assert.equal(Object.values(harness.state.resultsBySession.session_1.competitors)[0].bestLapMs, 20_500, "but it is still the best lap");
|
assert.equal(Object.values(harness.state.resultsBySession.session_1.competitors)[0].bestLapMs, 20_500, "but it is still the best lap");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("practice: a shortcut lap is flagged suspect - counted, but no best lap, personal best or record", () => {
|
test("practice: a shortcut lap is flagged suspect - it counts (also as best lap) until removed, but is never called out", () => {
|
||||||
const harness = createHarness({ sessionType: "open_practice" });
|
const harness = createHarness({ sessionType: "open_practice" });
|
||||||
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
const entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
||||||
let ts = 1_000;
|
let ts = 1_000;
|
||||||
@@ -186,9 +186,9 @@ test("practice: a shortcut lap is flagged suspect - counted, but no best lap, pe
|
|||||||
const last = harness.state.resultsBySession.session_1.passings.at(-1);
|
const last = harness.state.resultsBySession.session_1.passings.at(-1);
|
||||||
assert.equal(last.suspect, true);
|
assert.equal(last.suspect, true);
|
||||||
assert.equal(entry().laps, 7, "still counted as a lap");
|
assert.equal(entry().laps, 7, "still counted as a lap");
|
||||||
assert.equal(entry().bestLapMs, 19_800, "not a best lap");
|
assert.equal(entry().bestLapMs, 15_000, "it counts until someone removes it");
|
||||||
assert.equal(harness.audioEvents.filter((event) => event === "personal_best").length, pbsBefore, "no personal best call for it");
|
assert.equal(harness.audioEvents.filter((event) => event === "personal_best").length, pbsBefore, "no personal best call for it");
|
||||||
ts += 15_100; // a second shortcut in a row is flagged too (suspect laps aren't the reference)
|
ts += 15_100; // a second shortcut in a row is flagged too (one lap hardly moves the median)
|
||||||
harness.passing(ts, "main");
|
harness.passing(ts, "main");
|
||||||
assert.equal(harness.state.resultsBySession.session_1.passings.at(-1).suspect, true);
|
assert.equal(harness.state.resultsBySession.session_1.passings.at(-1).suspect, true);
|
||||||
assert.ok(harness.overlayEvents.some((event) => event.type === "suspect"), "the overlay event feed shows it");
|
assert.ok(harness.overlayEvents.some((event) => event.type === "suspect"), "the overlay event feed shows it");
|
||||||
|
|||||||
@@ -99,18 +99,20 @@ test("any lap can be removed, restored or (if suspect) approved - each logged an
|
|||||||
assert.equal(harness.row.laps, 3);
|
assert.equal(harness.row.laps, 3);
|
||||||
assert.equal(harness.row.bestLapMs, 16000);
|
assert.equal(harness.row.bestLapMs, 16000);
|
||||||
|
|
||||||
// A suspect lap doesn't count for best lap until approved; undo makes it suspect again.
|
// A suspect lap counts (also as best lap) until removed; approve only drops the flag, and
|
||||||
|
// undo puts the flag back.
|
||||||
harness.result.passings[2].lapMs = 12000;
|
harness.result.passings[2].lapMs = 12000;
|
||||||
harness.result.passings[2].suspect = true;
|
harness.result.passings[2].suspect = true;
|
||||||
harness.deps.recalculateCompetitorFromPassings(harness.session, "driver_1");
|
harness.deps.recalculateCompetitorFromPassings(harness.session, "driver_1");
|
||||||
assert.equal(harness.row.bestLapMs, 16000);
|
assert.equal(harness.row.bestLapMs, 12000);
|
||||||
assert.equal(act(50500, "approve"), true);
|
assert.equal(act(50500, "approve"), true);
|
||||||
|
assert.equal(harness.result.passings[2].suspect, false);
|
||||||
assert.equal(harness.row.bestLapMs, 12000);
|
assert.equal(harness.row.bestLapMs, 12000);
|
||||||
const approval = harness.result.adjustments.at(-1);
|
const approval = harness.result.adjustments.at(-1);
|
||||||
assert.equal(approval.category, "invalid");
|
assert.equal(approval.category, "invalid");
|
||||||
assert.equal(undoJudgingAdjustment(harness.session, approval.id, { ...harness.deps, findPassingByUndoMarker: (session, key, ts) => harness.result.passings.find((passing) => passing.competitorKey === key && passing.timestamp === ts) }), true);
|
assert.equal(undoJudgingAdjustment(harness.session, approval.id, { ...harness.deps, findPassingByUndoMarker: (session, key, ts) => harness.result.passings.find((passing) => passing.competitorKey === key && passing.timestamp === ts) }), true);
|
||||||
assert.equal(harness.result.passings[2].suspect, true);
|
assert.equal(harness.result.passings[2].suspect, true);
|
||||||
assert.equal(harness.row.bestLapMs, 16000);
|
assert.equal(harness.row.bestLapMs, 12000);
|
||||||
assert.equal(act(99999, "remove"), false, "unknown lap");
|
assert.equal(act(99999, "remove"), false, "unknown lap");
|
||||||
assert.equal(act(17000, "explode"), false, "unknown action");
|
assert.equal(act(17000, "explode"), false, "unknown action");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { isSuspectLap, getSuspectReferenceLaps, countsForBestLap, listPendingSuspectLaps, SUSPECT_LAP_RATIO, MIN_REFERENCE_LAPS } from "../src/suspect_laps_logic.js";
|
import { isSuspectLap, getSuspectReferenceLaps, listPendingSuspectLaps, releaseSettledSuspectLaps, SUSPECT_LAP_RATIO, MIN_REFERENCE_LAPS } from "../src/suspect_laps_logic.js";
|
||||||
import { syncTrainingLedger } from "../src/training_logic.js";
|
import { syncTrainingLedger } from "../src/training_logic.js";
|
||||||
|
|
||||||
const lap = (lapMs, extra = {}) => ({ competitorKey: "d1", lapMs, timestamp: lapMs, validLap: true, ...extra });
|
const lap = (lapMs, extra = {}) => ({ competitorKey: "d1", lapMs, timestamp: lapMs, validLap: true, ...extra });
|
||||||
@@ -14,23 +14,42 @@ test("a lap well under 85 % of the driver's own median is suspect - only once th
|
|||||||
assert.equal(isSuspectLap(12000, reference.slice(0, 4)), false, "too little to compare with yet");
|
assert.equal(isSuspectLap(12000, reference.slice(0, 4)), false, "too little to compare with yet");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("the reference is the driver's own recent normal laps on the same layout", () => {
|
test("the reference is the driver's own recent laps on the same layout - flagged ones included", () => {
|
||||||
const passings = [
|
const passings = [
|
||||||
lap(20000), lap(20000), lap(30000, { stintBoundary: true }), lap(9000, { validLap: false }),
|
lap(20000), lap(20000), lap(30000, { stintBoundary: true }), lap(9000, { validLap: false }),
|
||||||
lap(15000, { suspect: true }), lap(25000, { competitorKey: "other" }), lap(40000, { trackLayoutId: "old" }), lap(21000),
|
lap(15000, { suspect: true }), lap(25000, { competitorKey: "other" }), lap(40000, { trackLayoutId: "old" }), lap(21000),
|
||||||
];
|
];
|
||||||
assert.deepEqual(getSuspectReferenceLaps(passings, "d1", ""), [20000, 20000, 21000]);
|
assert.deepEqual(getSuspectReferenceLaps(passings, "d1", ""), [20000, 20000, 15000, 21000]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("suspect and removed laps never count for best lap; pending ones are listed newest first", () => {
|
test("a driver who gets faster during the day is not flagged lap after lap", () => {
|
||||||
assert.equal(countsForBestLap(lap(15000, { suspect: true })), false);
|
// Slow warm-up laps around 23 s, then a real pace around 19 s (84 % of 23 s).
|
||||||
assert.equal(countsForBestLap(lap(15000, { validLap: false })), false);
|
const passings = [23000, 23500, 22800, 23200, 24000, 23100].map((lapMs, index) => lap(lapMs, { timestamp: index }));
|
||||||
assert.equal(countsForBestLap(lap(15000, { suspectApproved: true })), true);
|
const flagged = [];
|
||||||
|
[19000, 19200, 18900, 19100, 18800, 19300, 19000, 18900].forEach((lapMs, index) => {
|
||||||
|
const suspect = isSuspectLap(lapMs, getSuspectReferenceLaps(passings, "d1", ""));
|
||||||
|
passings.push(lap(lapMs, { timestamp: 100 + index, suspect }));
|
||||||
|
if (suspect) flagged.push(lapMs);
|
||||||
|
releaseSettledSuspectLaps(passings, "d1", "");
|
||||||
|
});
|
||||||
|
assert.ok(flagged.length <= 5, `only the first laps at the new pace look odd (${flagged.length})`);
|
||||||
|
assert.deepEqual(listPendingSuspectLaps({ passings }), [], "and they lose the flag once the pace is clear");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a real shortcut among normal laps stays flagged", () => {
|
||||||
|
const passings = [20000, 20500, 19800, 20200, 21000, 20300].map((lapMs, index) => lap(lapMs, { timestamp: index }));
|
||||||
|
passings.push(lap(15000, { timestamp: 10, suspect: isSuspectLap(15000, getSuspectReferenceLaps(passings, "d1", "")) }));
|
||||||
|
passings.push(lap(20100, { timestamp: 11 }));
|
||||||
|
releaseSettledSuspectLaps(passings, "d1", "");
|
||||||
|
assert.deepEqual(listPendingSuspectLaps({ passings }).map((passing) => passing.lapMs), [15000]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("pending suspect laps are listed newest first; a removed one is no longer pending", () => {
|
||||||
const result = { passings: [lap(15000, { suspect: true, timestamp: 1 }), lap(16000, { suspect: true, validLap: false, timestamp: 2 }), lap(14000, { suspect: true, timestamp: 3 })] };
|
const result = { passings: [lap(15000, { suspect: true, timestamp: 1 }), lap(16000, { suspect: true, validLap: false, timestamp: 2 }), lap(14000, { suspect: true, timestamp: 3 })] };
|
||||||
assert.deepEqual(listPendingSuspectLaps(result).map((passing) => passing.lapMs), [14000, 15000], "a removed suspect lap is no longer pending");
|
assert.deepEqual(listPendingSuspectLaps(result).map((passing) => passing.lapMs), [14000, 15000]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a suspect lap stays out of the training stats until it is approved", () => {
|
test("a suspect lap counts in the training stats until it is removed", () => {
|
||||||
let n = 0;
|
let n = 0;
|
||||||
const uid = (prefix) => `${prefix}_${++n}`;
|
const uid = (prefix) => `${prefix}_${++n}`;
|
||||||
const state = {
|
const state = {
|
||||||
@@ -38,7 +57,7 @@ test("a suspect lap stays out of the training stats until it is approved", () =>
|
|||||||
events: [{ id: "e", name: "Club" }],
|
events: [{ id: "e", name: "Club" }],
|
||||||
resultsBySession: { op: { passings: [{ ...lap(20000), driverId: "d1", timestamp: 1000 }, { ...lap(15000, { suspect: true }), driverId: "d1", timestamp: 2000 }] } },
|
resultsBySession: { op: { passings: [{ ...lap(20000), driverId: "d1", timestamp: 1000 }, { ...lap(15000, { suspect: true }), driverId: "d1", timestamp: 2000 }] } },
|
||||||
};
|
};
|
||||||
assert.deepEqual(syncTrainingLedger({}, state, { uid }).ledger.map((entry) => entry.lapMs), [20000]);
|
|
||||||
Object.assign(state.resultsBySession.op.passings[1], { suspect: false, suspectApproved: true });
|
|
||||||
assert.deepEqual(syncTrainingLedger({}, state, { uid }).ledger.map((entry) => entry.lapMs), [20000, 15000]);
|
assert.deepEqual(syncTrainingLedger({}, state, { uid }).ledger.map((entry) => entry.lapMs), [20000, 15000]);
|
||||||
|
Object.assign(state.resultsBySession.op.passings[1], { validLap: false, invalidReason: "manual_invalid" });
|
||||||
|
assert.deepEqual(syncTrainingLedger({}, state, { uid }).ledger.map((entry) => entry.lapMs), [20000]);
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user