feat(export): CSV for a whole race day from the results archive and series rounds (1.89.40)

This commit is contained in:
larssand committed 2026-11-15 21:40:54 +01:00
1 parent 10b5d0a447
commit 7af4a81aaa
12 files changed
+212 -14

No files matched your search

+5 -1
View File
@@ -24,11 +24,15 @@ export async function runArchiveQualifyingSmoke({ evaluate, navigate, savedState
await navigate("archive", "archiveDriverFilter");
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-archive-event="aq_event"]'))`), "the race is in the archive");
// Race day CSV: off until one date is picked (from = to).
assert.equal(await evaluate(`document.getElementById("archiveDayCsv").disabled`), true, "day CSV waits for a date");
for (const id of ["archiveDateFrom", "archiveDateTo"]) await evaluate(`(() => { const input = document.getElementById("${id}"); input.value = "${event.date}"; input.dispatchEvent(new Event("change")); })()`);
await waitFor(async () => evaluate(`document.getElementById("archiveDayCsv")?.disabled === false`), "day CSV is on for one date");
await evaluate(`document.querySelector('[data-archive-event="aq_event"]').click()`);
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-archive-open="aq_f1"]'))`), "the final heat is listed");
await evaluate(`document.querySelector('[data-archive-open="aq_f1"]').click()`);
await waitFor(async () => evaluate(`Boolean(document.querySelector(".archive-detail .tq-badge"))`), "the final heat shows TQ");
const rows = await evaluate(`[...document.querySelectorAll(".archive-detail tbody tr")].slice(0, 2).map((row) => [...row.children].slice(0, 3).map((cell) => cell.textContent.trim()))`);
assert.deepEqual(rows, [["1", "2", "AQ Winner"], ["2", "TQ", "AQ Pole"]], "winner qualified 2nd, the pole sitter finished 2nd");
console.log("PASS results archive: a final heat shows each driver's qualifying place with TQ for the top qualifier");
console.log("PASS results archive: a final heat shows each driver's qualifying place with TQ for the top qualifier; day CSV turns on for one date");
}
+66
View File
@@ -0,0 +1,66 @@
import test from "node:test";
import assert from "node:assert/strict";
import { raceDaySessions, buildRaceDayLapRows, buildRaceDaySummaryRows, buildRaceDayCsvRows, raceDayCsvFilename } from "../src/race_day_export_logic.js";
const passing = (driverId, timestamp, lapMs, extra = {}) => ({ driverId, competitorKey: `driver_${driverId}`, transponder: `T${driverId}`, timestamp, lapMs, ...extra });
const state = () => ({
classes: [{ id: "4wd", name: "4WD" }, { id: "2wd", name: "2WD" }],
events: [{ id: "r4", name: "Cup 4WD", classId: "4wd", date: "2026-11-15" }, { id: "r2", name: "Cup 2WD", classId: "2wd", date: "2026-11-15" }, { id: "old", name: "Cup 4WD", classId: "4wd", date: "2026-11-01" }],
sessions: [
{ id: "a1", eventId: "r4", name: "A1", type: "final", status: "finished", finalLeg: 1 },
{ id: "q1", eventId: "r4", name: "Q1 H1", type: "qualifying", status: "finished" },
{ id: "q2", eventId: "r4", name: "Q2 H1", type: "qualifying", status: "ready" },
{ id: "b1", eventId: "r2", name: "Q1 H1", type: "qualifying", status: "finished" },
{ id: "x", eventId: "old", name: "Q1 H1", type: "qualifying", status: "finished" },
],
resultsBySession: {
q1: { passings: [passing("anna", 1000, 20000), passing("anna", 2000, 4000, { validLap: false, invalidReason: "below_min" }), passing("anna", 3000, 22000), passing("bo", 1500, 21000)] },
a1: { passings: [passing("bo", 5000, 19000)] },
b1: { passings: [passing("cid", 7000, 25000)] },
},
});
const helpers = (s) => ({
buildLeaderboard: (session) => {
const ids = [...new Set((s.resultsBySession[session.id]?.passings || []).map((p) => p.driverId))];
return ids.map((id) => ({ key: `driver_${id}`, driverId: id, driverName: id, transponder: `T${id}`, laps: s.resultsBySession[session.id].passings.filter((p) => p.driverId === id && p.validLap !== false).length, totalElapsedMs: 42000, bestLapMs: 20000 }));
},
getPassings: (session, row) => s.resultsBySession[session.id].passings.filter((p) => p.competitorKey === row.key),
getClassName: (id) => s.classes.find((c) => c.id === id)?.name || "",
formatLap: (ms) => (ms / 1000).toFixed(3),
formatClock: (ts) => `t${ts}`,
invalidLabel: (p) => p.invalidReason,
});
test("the day's finished heats only, race by race in running order, one class or all", () => {
const s = state();
assert.deepEqual(raceDaySessions(s, { date: "2026-11-15" }).map(({ session }) => session.id), ["b1", "q1", "a1"]);
assert.deepEqual(raceDaySessions(s, { date: "2026-11-15", classId: "4wd" }).map(({ session }) => session.id), ["q1", "a1"]);
assert.deepEqual(raceDaySessions(s, { date: "2026-11-01" }).map(({ session }) => session.id), ["x"]);
assert.deepEqual(raceDaySessions(s, {}), []);
});
test("one row per lap; a lap not counted has no lap number and says why", () => {
const s = state();
const rows = buildRaceDayLapRows(s, { date: "2026-11-15", classId: "4wd", ...helpers(s) });
assert.equal(rows.length, 1 + 4 + 1);
assert.deepEqual(rows[1], ["4WD", "Cup 4WD", "1", "Q1 H1", "anna", "Tanna", "1", "20.000", "t1000", "export.yes"]);
assert.deepEqual(rows[2].slice(6), ["", "4.000", "t2000", "below_min"]);
assert.equal(rows[3][6], "2");
assert.deepEqual(rows[5].slice(2, 5), ["2", "A1", "bo"]);
});
test("summary per heat: place, laps, times, average of counted laps only", () => {
const s = state();
const rows = buildRaceDaySummaryRows(s, { date: "2026-11-15", classId: "4wd", ...helpers(s) });
assert.deepEqual(rows[1], ["4WD", "Cup 4WD", "1", "Q1 H1", "1", "anna", "Tanna", "2", "42.000", "20.000", "21.000"]);
assert.equal(rows[2][4], "2");
const all = buildRaceDayCsvRows(s, { date: "2026-11-15", ...helpers(s) });
assert.deepEqual(all[0], ["export.summary"]);
assert.ok(all.some((row) => row.length === 0));
});
test("file name has the date and the class", () => {
assert.equal(raceDayCsvFilename("2026-11-15", "4WD"), "racedag_2026-11-15_4WD.csv");
assert.equal(raceDayCsvFilename("2026-11-15", ""), "racedag_2026-11-15.csv");
assert.equal(raceDayCsvFilename("2026-11-15", "Open Class / 1:10"), "racedag_2026-11-15_Open_Class_1_10.csv");
});
+1
View File
@@ -38,6 +38,7 @@ import "./public_training_profile.test.js";
import "./race_timing_logic.test.js";
import "./track_layouts_logic.test.js";
import "./race_day_logic.test.js";
import "./race_day_export.test.js";
import "./backup_service.test.js";
import "./judging_logic.test.js";
import "./session_control.test.js";