feat(results): qualifying place (TQ) next to final results and podium bands for the top three (1.74.0)

This commit is contained in:
larssand committed 2026-11-06 23:31:09 +01:00
1 parent 41043a990d
commit fee9f8073d
12 files changed
+149 -38

No files matched your search

+26 -4
View File
@@ -3,6 +3,22 @@
// Works for race events and sponsor events (their heats carry carAssignments).
const PHASES = ["practice", "qualification", "final"];
// Where each driver ended up in qualifying ("TQ" for the top qualifier), shown next to the
// final result so you can see who climbed or dropped - like House of RC's "Qual." column.
export function qualifyingPlaces(qualifyingRows = []) {
const places = new Map();
qualifyingRows.forEach((row) => {
if (row?.driverId && row.rank) places.set(row.driverId, String(row.rank) === "1" ? "TQ" : String(row.rank));
});
return places;
}
export function withQualifyingPlaces(rows = [], qualifyingRows = []) {
const places = qualifyingPlaces(qualifyingRows);
if (!places.size) return rows;
return rows.map((row) => ({ ...row, qual: places.get(row.driverId) || "" }));
}
export function buildRaceOverview(event, deps) {
const { sessions = [], cars = [], buildLeaderboard, buildPracticeStandings, buildQualifyingStandings, buildFinalStandings } = deps;
if (!event) return null;
@@ -11,6 +27,9 @@ export function buildRaceOverview(event, deps) {
return carId ? cars.find((car) => car.id === carId)?.name || "" : "";
};
const standingsOf = { practice: buildPracticeStandings, qualification: buildQualifyingStandings, final: buildFinalStandings };
const qualPlaces = sessions.some((session) => session.type === "qualification" && session.status !== "ready")
? qualifyingPlaces(buildQualifyingStandings(event) || [])
: new Map();
const phases = PHASES.map((type) => {
const heats = sessions
.filter((session) => session.type === type && session.status !== "ready")
@@ -18,6 +37,8 @@ export function buildRaceOverview(event, deps) {
session,
rows: buildLeaderboard(session).map((row, index) => ({
pos: index + 1,
driverId: row.driverId,
qual: type === "final" ? qualPlaces.get(row.driverId) || "" : "",
name: row.displayName || row.driverName || row.transponder || "-",
car: carName(session, row.driverId),
laps: Number(row.laps || 0),
@@ -26,7 +47,8 @@ export function buildRaceOverview(event, deps) {
})),
}));
const planned = sessions.filter((session) => session.type === type).length;
return { type, planned, heats, standings: heats.length ? standingsOf[type](event) || [] : [] };
const standings = heats.length ? standingsOf[type](event) || [] : [];
return { type, planned, heats, standings: type === "final" && qualPlaces.size ? standings.map((row) => ({ ...row, qual: qualPlaces.get(row.driverId) || "" })) : standings };
}).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) : [];
@@ -35,14 +57,14 @@ export function buildRaceOverview(event, deps) {
// 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"]];
const rows = [["event", "phase", "heat", "pos", "qual", "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.standings.forEach((row) => rows.push([eventName, label, t("race_overview.total"), String(row.rank), row.qual || "", 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) : "",
eventName, label, session.name, String(row.pos), row.qual || "", row.name, row.car, String(row.laps), row.result, row.bestLapMs ? formatLap(row.bestLapMs) : "",
])));
});
return rows;