feat(export): CSV for a whole race day from the results archive and series rounds (1.89.40)
This commit is contained in:
1 parent
10b5d0a447
commit
7af4a81aaa
12 files changed
+212
-14
No files matched your search
@@ -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");
|
||||
});
|
||||
Reference in new issue
Block a user