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:
1 parent
f2adc67695
commit
576847279d
15 files changed
+146
-17
No files matched your search
@@ -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");
|
||||
|
||||
@@ -56,3 +56,29 @@ test("qualifying seed notice: preliminary until practice is run, then a reminder
|
||||
assert.equal(getQualifyingSeedNotice(ev, [ran, { ...q, status: "finished", startedAt: 5 }]), null, "qualifying started");
|
||||
assert.equal(getQualifyingSeedNotice(ev, [q]), null, "no practice");
|
||||
});
|
||||
|
||||
test("practice seeding: format values go onto the practice heats, also ones already run", async () => {
|
||||
const { applyFormatToPendingSessions } = await import("../src/event_race_logic.js");
|
||||
const ev = event(4, 10, { practiceSeedLapCount: 3, practiceSeedMethod: "consecutive" });
|
||||
const [heat] = buildPracticeHeats(ev, 1, { t, buildRaceSession: (eventId, name, type, durationMin, o = {}) => ({ id: "x", eventId, name, type, status: "ready", driverIds: o.driverIds, seedBestLapCount: o.seedBestLapCount, seedMethod: o.seedMethod }) });
|
||||
assert.equal(heat.seedBestLapCount, 3);
|
||||
assert.equal(heat.seedMethod, "consecutive");
|
||||
const ran = { type: "practice", status: "finished", startedAt: 1, seedBestLapCount: 0, seedMethod: "best_sum" };
|
||||
applyFormatToPendingSessions([ran], { practiceSeedLapCount: 0, practiceSeedMethod: "best_sum" }, { practiceSeedLapCount: 3, practiceSeedMethod: "consecutive" });
|
||||
assert.equal(ran.seedBestLapCount, 3);
|
||||
assert.equal(ran.seedMethod, "consecutive");
|
||||
});
|
||||
|
||||
test("practice seeding: a driver without N laps ranks after everyone with a seeding time", async () => {
|
||||
const { buildPracticeStandings } = await import("../src/timing_logic.js");
|
||||
const session = { id: "p", type: "practice", seedBestLapCount: 3 };
|
||||
const rows = [{ driverId: "a", driverName: "A", bestLapMs: 17000, laps: 2 }, { driverId: "b", driverName: "B", bestLapMs: 18000, laps: 5 }];
|
||||
const standings = buildPracticeStandings({ id: "e1" }, {
|
||||
getSessionsForEvent: () => [session],
|
||||
buildLeaderboard: () => rows,
|
||||
getCompetitorSeedMetric: (_s, row) => (row.driverId === "b" ? { comparableMs: 54500, totalMs: 54500 } : null),
|
||||
formatSeedMetric: () => "3/54.500",
|
||||
formatRaceClock: () => "",
|
||||
});
|
||||
assert.deepEqual(standings.map((row) => row.driverId), ["b", "a"]);
|
||||
});
|
||||
Reference in new issue
Block a user