Fix lap limits and five-minute stint statistics

This commit is contained in:
larssand
2026-09-02 19:36:25 +02:00
parent f561dd8feb
commit 483a9dbd5a
14 changed files with 356 additions and 110 deletions

View File

@@ -167,6 +167,35 @@ test("public timer query normalization bounds age and window values", () => {
assert.equal(normalizePublicTrainingWindow(String(25 * 60 * 60 * 1000)), 24 * 60 * 60 * 1000);
});
test("public profile counts a max-boundary lap but excludes it from pace", () => {
const now = Date.now();
const state = buildState(now);
state.training.ledger = [
{ driverId: "driver_1", sourceId: "tp_1", sessionId: "practice", timestamp: now - 127_000, lapMs: 37_000 },
{ driverId: "driver_1", sourceId: "tp_1", sessionId: "practice", timestamp: now - 90_000, lapMs: 37_000 },
{ driverId: "driver_1", sourceId: "tp_1", sessionId: "practice", timestamp: now, lapMs: 90_000, excludedFromPace: true, stintBoundary: true },
];
const profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, "");
assert.equal(profile.stats.totalLaps, 3);
assert.equal(profile.stats.bestLapMs, 37_000);
assert.equal(profile.stats.averageLapMs, 37_000);
assert.equal(profile.stats.stintCount, 2);
});
test("public five-minute result never combines simultaneous transponder sources", () => {
const laps = ["tp_a", "tp_b"].flatMap((sourceId) => Array.from({ length: 9 }, (_, index) => ({
sourceId,
sessionId: "practice_1",
timestamp: (index + 1) * 37_000,
lapMs: 37_000,
})));
const result = getPublicBestDurationResult(splitPublicTrainingStints(laps), 300_000);
assert.equal(result.lapCount, 9);
assert.equal(result.totalMs, 333_000);
});
test("public profile duration result includes the lap started before five minutes", () => {
const laps = Array.from({ length: 16 }, (_, index) => ({
sessionId: "practice_1",