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
@@ -46,12 +46,12 @@ export async function runSuspectLapsSmoke({ evaluate, navigate, savedState, wait
|
||||
const shortLap = (await results()).passings.at(-1);
|
||||
assert.equal(shortLap.lapMs, 14000);
|
||||
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");
|
||||
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");
|
||||
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 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();
|
||||
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.bestLapMs, 19800, "and no longer the best lap");
|
||||
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");
|
||||
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 {
|
||||
dialogs.splice(dialogsAtStart);
|
||||
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");
|
||||
});
|
||||
|
||||
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 entry = () => Object.values(harness.state.resultsBySession.session_1.competitors)[0];
|
||||
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);
|
||||
assert.equal(last.suspect, true);
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
|
||||
@@ -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.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].suspect = true;
|
||||
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(harness.result.passings[2].suspect, false);
|
||||
assert.equal(harness.row.bestLapMs, 12000);
|
||||
const approval = harness.result.adjustments.at(-1);
|
||||
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(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(17000, "explode"), false, "unknown action");
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
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";
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
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 = [
|
||||
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),
|
||||
];
|
||||
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", () => {
|
||||
assert.equal(countsForBestLap(lap(15000, { suspect: true })), false);
|
||||
assert.equal(countsForBestLap(lap(15000, { validLap: false })), false);
|
||||
assert.equal(countsForBestLap(lap(15000, { suspectApproved: true })), true);
|
||||
test("a driver who gets faster during the day is not flagged lap after lap", () => {
|
||||
// Slow warm-up laps around 23 s, then a real pace around 19 s (84 % of 23 s).
|
||||
const passings = [23000, 23500, 22800, 23200, 24000, 23100].map((lapMs, index) => lap(lapMs, { timestamp: index }));
|
||||
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 })] };
|
||||
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;
|
||||
const uid = (prefix) => `${prefix}_${++n}`;
|
||||
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" }],
|
||||
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]);
|
||||
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