feat(race): practice seeding setting (EFRA 3 in a row), seeding time in lists and a new-seeding-time call (1.89.49)

This commit is contained in:
larssand committed 2026-11-16 22:39:10 +01:00
1 parent f2adc67695
commit 576847279d
15 files changed
+146 -17

No files matched your search

+25 -1
View File
@@ -14,6 +14,7 @@ function createHarness(options = {}) {
status: "running",
startMode: options.startMode || "mass",
startedAt: 1_000,
...(options.session || {}),
};
const state = {
events: [{
@@ -46,7 +47,7 @@ function createHarness(options = {}) {
findEventTeamForPassing: (event, driverId) => event.teams.find((team) => team.driverIds.includes(driverId)) || null,
persistPassingToBackend: () => {},
pushOverlayEvent: (type, label) => overlayEvents.push({ type, label }),
buildLeaderboard: () => [],
buildLeaderboard: options.buildLeaderboard ? () => options.buildLeaderboard(state, session) : () => [],
formatLap: (ms) => `${ms}ms`,
announcePassing: () => {},
triggerRaceAudio: (key, opts) => { audioEvents.push(key); audioCalls.push({ key, variables: opts?.variables || {} }); },
@@ -71,6 +72,29 @@ test("five controlled practice laps trigger one stable-pace voice cue", () => {
assert.equal(call.variables.avgLap, "20 jämnt");
});
test("practice in a race ranked on N laps: a better seeding time is called, the first one is not", () => {
// Seeding time = sum of the last 3 laps (enough for the test), from the stored laps.
const buildLeaderboard = (state, session) => Object.entries(state.resultsBySession[session.id]?.competitors || {}).map(([key, entry]) => {
const laps = (state.resultsBySession[session.id].passings || []).filter((p) => p.competitorKey === key || p.driverId === entry.driverId).map((p) => p.lapMs).filter((ms) => ms > 500);
const window = laps.slice(-3);
return { key, driverId: entry.driverId, seedMetric: window.length === 3 ? { method: "consecutive", lapCount: 3, totalMs: window.reduce((a, b) => a + b, 0), comparableMs: window.reduce((a, b) => a + b, 0) } : null };
});
const harness = createHarness({ sessionType: "practice", session: { seedBestLapCount: 3, seedMethod: "consecutive" }, buildLeaderboard });
let ts = 1_000;
harness.passing(ts, "main");
for (const lapMs of [20_000, 20_000, 20_000, 19_000]) { ts += lapMs; harness.passing(ts, "main"); }
const calls = harness.audioCalls.filter((item) => item.key === "seed_improved");
assert.equal(calls.length, 1, "first full seeding time silent, the improvement called");
assert.equal(calls[0].variables.gain, "1,00");
});
test("open practice never gets the seeding call", () => {
const harness = createHarness({ sessionType: "open_practice", session: { seedBestLapCount: 3 } });
let ts = 1_000;
for (let lap = 0; lap < 6; lap += 1) { harness.passing(ts, "main"); ts += 20_000 - lap * 500; }
assert.equal(harness.audioEvents.includes("seed_improved"), false);
});
test("stable-pace training cue is never emitted during a race", () => {
const harness = createHarness({ sessionType: "team_race" });
for (let lap = 1; lap <= 5; lap += 1) harness.passing(1_000 + lap * 20_000, "main");