feat(results): race overview on Race Day and an event-grouped results archive (1.66.0)
This commit is contained in:
1 parent
31ac04616a
commit
69a65748ce
12 files changed
+321
-30
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// Race overview (Race Day): the whole event in one place - podium, then practice, qualifying
|
||||
// and finals, each with its standings and every heat's result. Also the rows for one CSV.
|
||||
// Works for race events and sponsor events (their heats carry carAssignments).
|
||||
const PHASES = ["practice", "qualification", "final"];
|
||||
|
||||
export function buildRaceOverview(event, deps) {
|
||||
const { sessions = [], cars = [], buildLeaderboard, buildPracticeStandings, buildQualifyingStandings, buildFinalStandings } = deps;
|
||||
if (!event) return null;
|
||||
const carName = (session, driverId) => {
|
||||
const carId = session.carAssignments?.[driverId];
|
||||
return carId ? cars.find((car) => car.id === carId)?.name || "" : "";
|
||||
};
|
||||
const standingsOf = { practice: buildPracticeStandings, qualification: buildQualifyingStandings, final: buildFinalStandings };
|
||||
const phases = PHASES.map((type) => {
|
||||
const heats = sessions
|
||||
.filter((session) => session.type === type && session.status !== "ready")
|
||||
.map((session) => ({
|
||||
session,
|
||||
rows: buildLeaderboard(session).map((row, index) => ({
|
||||
pos: index + 1,
|
||||
name: row.displayName || row.driverName || row.transponder || "-",
|
||||
car: carName(session, row.driverId),
|
||||
laps: Number(row.laps || 0),
|
||||
result: row.resultDisplay || "-",
|
||||
bestLapMs: Number(row.bestLapMs || 0) || null,
|
||||
})),
|
||||
}));
|
||||
const planned = sessions.filter((session) => session.type === type).length;
|
||||
return { type, planned, heats, standings: heats.length ? standingsOf[type](event) || [] : [] };
|
||||
}).filter((phase) => phase.planned);
|
||||
const finals = phases.find((phase) => phase.type === "final");
|
||||
const podium = finals ? finals.standings.filter((row) => /^A?[1-3]$/.test(String(row.rank))).slice(0, 3) : [];
|
||||
return { event, phases, podium, finished: sessions.length > 0 && sessions.every((session) => ["finished", "stopped"].includes(session.status)) };
|
||||
}
|
||||
|
||||
// One CSV for the whole race: the standings ("Total") and every heat, one row per driver.
|
||||
export function buildRaceOverviewCsvRows(overview, { t, formatLap, phaseLabel }) {
|
||||
const rows = [["event", "phase", "heat", "pos", "driver", "car", "laps", "result", "best_lap"]];
|
||||
if (!overview) return rows;
|
||||
const eventName = overview.event.name || "";
|
||||
overview.phases.forEach((phase) => {
|
||||
const label = phaseLabel(phase.type);
|
||||
phase.standings.forEach((row) => rows.push([eventName, label, t("race_overview.total"), String(row.rank), row.driverName || "-", "", "", row.score || "-", ""]));
|
||||
phase.heats.forEach(({ session, rows: heatRows }) => heatRows.forEach((row) => rows.push([
|
||||
eventName, label, session.name, String(row.pos), row.name, row.car, String(row.laps), row.result, row.bestLapMs ? formatLap(row.bestLapMs) : "",
|
||||
])));
|
||||
});
|
||||
return rows;
|
||||
}
|
||||
Reference in new issue
Block a user