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
@@ -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