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

+6
View File
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
No changes recorded yet. No changes recorded yet.
## 1.74.0
### Added
- Final results show each driver's qualifying place in a "Qual." column next to the position, with a "TQ" badge for the top qualifier, so you can see who climbed or dropped. In the race overview (final standings and every final heat), the results overview printout, the PDF and the CSV.
- Places 1-3 (also A1-A3) get a gold, silver or bronze tinted band fading out to the right, in the app, the printouts and the PDF, next to the medal.
## 1.73.0 ## 1.73.0
### Added ### Added
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.73.0", "version": "1.74.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.73.0", "version": "1.74.0",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"better-sqlite3": "^12.11.1", "better-sqlite3": "^12.11.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "rc-racecore", "name": "rc-racecore",
"version": "1.73.0", "version": "1.74.0",
"private": true, "private": true,
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence", "description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
"engines": { "engines": {
+28 -8
View File
@@ -14,6 +14,7 @@ const MEDALS = {
2: ["#7d8691", "#cfd5dc", "#ffffff", "#33383f"], 2: ["#7d8691", "#cfd5dc", "#ffffff", "#33383f"],
3: ["#84491a", "#d38a4c", "#ffd7b0", "#3d2109"], 3: ["#84491a", "#d38a4c", "#ffd7b0", "#3d2109"],
}; };
const PODIUM_TINT = { 1: "#fbeebf", 2: "#e9edf1", 3: "#f5dcc6" };
const TEXT = "#1d2330"; const TEXT = "#1d2330";
const MUTED = "#6b7486"; const MUTED = "#6b7486";
const RULE = "#d8dde6"; const RULE = "#d8dde6";
@@ -60,6 +61,8 @@ function wrapText(text, size, bold, maxWidth) {
return lines.length ? lines : [""]; return lines.length ? lines : [""];
} }
// Blend two #rrggbb colours; amount 0 gives the first, 1 the second.
const mix = (from, to, amount) => `#${[1, 3, 5].map((index) => Math.round(parseInt(from.slice(index, index + 2), 16) * (1 - amount) + parseInt(to.slice(index, index + 2), 16) * amount).toString(16).padStart(2, "0")).join("")}`;
const rgb = (hex) => [1, 3, 5].map((index) => (parseInt(hex.slice(index, index + 2), 16) / 255).toFixed(3)).join(" "); const rgb = (hex) => [1, 3, 5].map((index) => (parseInt(hex.slice(index, index + 2), 16) / 255).toFixed(3)).join(" ");
const escapePdfText = (text) => String(text || "").replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)"); const escapePdfText = (text) => String(text || "").replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)");
const n = (value) => Number(value.toFixed(2)); const n = (value) => Number(value.toFixed(2));
@@ -161,13 +164,14 @@ function createWriter(pageWidth, pageHeight, title) {
writer.page.push(`${rgb(color)} rg ${n(cx + r)} ${n(cy)} m ${n(cx + r)} ${n(cy + k)} ${n(cx + k)} ${n(cy + r)} ${n(cx)} ${n(cy + r)} c ${n(cx - k)} ${n(cy + r)} ${n(cx - r)} ${n(cy + k)} ${n(cx - r)} ${n(cy)} c ${n(cx - r)} ${n(cy - k)} ${n(cx - k)} ${n(cy - r)} ${n(cx)} ${n(cy - r)} c ${n(cx + k)} ${n(cy - r)} ${n(cx + r)} ${n(cy - k)} ${n(cx + r)} ${n(cy)} c f`); writer.page.push(`${rgb(color)} rg ${n(cx + r)} ${n(cy)} m ${n(cx + r)} ${n(cy + k)} ${n(cx + k)} ${n(cy + r)} ${n(cx)} ${n(cy + r)} c ${n(cx - k)} ${n(cy + r)} ${n(cx - r)} ${n(cy + k)} ${n(cx - r)} ${n(cy)} c ${n(cx - r)} ${n(cy - k)} ${n(cx - k)} ${n(cy - r)} ${n(cx)} ${n(cy - r)} c ${n(cx + k)} ${n(cy - r)} ${n(cx + r)} ${n(cy - k)} ${n(cx + r)} ${n(cy)} c f`);
}, },
// A gold/silver/bronze medal: rim, face, a soft highlight and the place in bold. // A gold/silver/bronze medal: rim, face, a soft highlight and the place in bold.
medal(cx, cy, place) { medal(cx, cy, place, label = String(place)) {
const [rim, face, light, ink] = MEDALS[place]; const [rim, face, light, ink] = MEDALS[place];
writer.circle(cx, cy, 7, rim); writer.circle(cx, cy, 7, rim);
writer.circle(cx, cy, 5.8, face); writer.circle(cx, cy, 5.8, face);
writer.circle(cx - 1.6, cy + 1.8, 2.4, light); writer.circle(cx - 1.6, cy + 1.8, 2.4, light);
writer.circle(cx - 0.3, cy + 0.3, 4.1, face); writer.circle(cx - 0.3, cy + 0.3, 4.1, face);
writer.text(cx - 6, cy - 2.6, String(place), 7.5, { bold: true, color: ink, align: "center", width: 12 }); const size = label.length > 1 ? 6 : 7.5;
writer.text(cx - 6, cy - size / 3, label, size, { bold: true, color: ink, align: "center", width: 12 });
}, },
image(x, y, w, h) { image(x, y, w, h) {
writer.page.push(`q ${n(w)} 0 0 ${n(h)} ${n(x)} ${n(y)} cm /Im1 Do Q`); writer.page.push(`q ${n(w)} 0 0 ${n(h)} ${n(x)} ${n(y)} cm /Im1 Do Q`);
@@ -227,7 +231,13 @@ function drawTable(writer, section, theme) {
return values.length > 0 && values.every((value) => NUMERIC.test(value)); return values.length > 0 && values.every((value) => NUMERIC.test(value));
}); });
const hasPos = POS_HEADER.test(String(section.headers[0] || "").trim()); const hasPos = POS_HEADER.test(String(section.headers[0] || "").trim());
const align = (index) => (index === 0 && numeric[0] ? "center" : numeric[index] ? "right" : "left"); const placeColumn = section.headers.map((_h, index) => {
const values = section.rows.map((row) => String(row[index] || "").trim()).filter(Boolean);
return values.length > 0 && values.every((value) => /^(TQ|[A-Z]?\d+|-)$/.test(value));
});
// The driver name is the first column that is not a place or a number; podium rows make it bold.
const nameIndex = section.headers.findIndex((_h, index) => index > 0 && !numeric[index] && !placeColumn[index]);
const align = (index) => (placeColumn[index] && index < 3 ? "center" : numeric[index] ? "right" : "left");
const headHeight = 19; const headHeight = 19;
const rowHeight = 16.5; const rowHeight = 16.5;
@@ -247,17 +257,27 @@ function drawTable(writer, section, theme) {
if (writer.ensure(rowHeight)) drawHead(); if (writer.ensure(rowHeight)) drawHead();
const top = writer.y; const top = writer.y;
if (rowIndex % 2 === 1) writer.rect(MARGIN, top - rowHeight, writer.width, rowHeight, theme.zebra); if (rowIndex % 2 === 1) writer.rect(MARGIN, top - rowHeight, writer.width, rowHeight, theme.zebra);
const podium = hasPos ? PODIUM[String(row[0] || "").trim()] : null; const place = hasPos ? /^A?([1-3])$/.exec(String(row[0] || "").trim())?.[1] : null;
if (podium) writer.rect(MARGIN, top - rowHeight, 3.5, rowHeight, podium); const podium = place ? PODIUM[place] : null;
if (podium) {
// Tinted band fading out to the right, like House of RC's result lists.
const steps = 14;
const bandWidth = writer.width * 0.7;
for (let step = 0; step < steps; step += 1) {
writer.rect(MARGIN + (bandWidth / steps) * step, top - rowHeight, bandWidth / steps + 0.5, rowHeight, mix(PODIUM_TINT[place], rowIndex % 2 ? theme.zebra : "#ffffff", step / steps));
}
writer.rect(MARGIN, top - rowHeight, 3.5, rowHeight, podium);
}
let x = MARGIN; let x = MARGIN;
section.headers.forEach((_h, index) => { section.headers.forEach((_h, index) => {
const bold = Boolean(podium) && index <= 1; const bold = Boolean(podium) && index === nameIndex;
if (podium && index === 0) { if (podium && index === 0) {
writer.medal(x + widths[0] / 2, top - rowHeight / 2, Number(String(row[0]).trim())); writer.medal(x + widths[0] / 2, top - rowHeight / 2, Number(place), String(row[0]).trim());
x += widths[0]; x += widths[0];
return; return;
} }
writer.text(x + PAD, top - 11.5, fitText(row[index], CELL_SIZE, bold, widths[index] - PAD * 2), CELL_SIZE, { bold, align: align(index), width: widths[index] - PAD * 2 }); const tq = String(row[index] || "").trim() === "TQ";
writer.text(x + PAD, top - 11.5, fitText(row[index], CELL_SIZE, bold || tq, widths[index] - PAD * 2), CELL_SIZE, { bold: bold || tq, color: tq ? "#b07d00" : TEXT, align: align(index), width: widths[index] - PAD * 2 });
x += widths[index]; x += widths[index];
}); });
writer.line(MARGIN, top - rowHeight, MARGIN + writer.width, top - rowHeight, RULE, 0.4); writer.line(MARGIN, top - rowHeight, MARGIN + writer.width, top - rowHeight, RULE, 0.4);
+31 -12
View File
@@ -1,4 +1,4 @@
import { medal } from "./medal.js"; import { medal, qualCell } from "./medal.js";
import { getSyncStatus } from "./sync_status.js"; import { getSyncStatus } from "./sync_status.js";
import { installListSorting } from "./list_sorting.js"; import { installListSorting } from "./list_sorting.js";
import { escapeHtml } from "./html_escape.js"; import { escapeHtml } from "./html_escape.js";
@@ -10,7 +10,7 @@ import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologu
import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js"; import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js";
import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js"; import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js";
import { normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate, getDueCall } from "./day_schedule_logic.js"; import { normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate, getDueCall } from "./day_schedule_logic.js";
import { buildRaceOverview, buildRaceOverviewCsvRows } from "./race_overview_logic.js"; import { buildRaceOverview, buildRaceOverviewCsvRows, withQualifyingPlaces } from "./race_overview_logic.js";
import { renderRaceOverviewPanel, bindRaceOverviewPanel } from "./race_overview_view.js"; import { renderRaceOverviewPanel, bindRaceOverviewPanel } from "./race_overview_view.js";
import { renderSpeakerPanel, bindSpeakerPanel } from "./speaker_panel_view.js"; import { renderSpeakerPanel, bindSpeakerPanel } from "./speaker_panel_view.js";
import { renderDaySchedulePanel, bindDaySchedulePanel, buildDaySchedulePrintHtml, renderDriverBoard, formatClockTime, renderDayCallBanner, bindDayCallBanner } from "./day_schedule_view.js"; import { renderDaySchedulePanel, bindDaySchedulePanel, buildDaySchedulePrintHtml, renderDriverBoard, formatClockTime, renderDayCallBanner, bindDayCallBanner } from "./day_schedule_view.js";
@@ -130,7 +130,12 @@ const buildTeamStintLog = (session, row) => buildTeamStintLogLogic(session, row,
const getSessionGridEntries = (session) => getSessionGridEntriesLogic(session, { state, t, getEventTeams, getDriverDisplayById, getSessionGridOrder }); const getSessionGridEntries = (session) => getSessionGridEntriesLogic(session, { state, t, getEventTeams, getDriverDisplayById, getSessionGridOrder });
const getSessionGridOrder = (session) => getSessionGridOrderLogic(session); const getSessionGridOrder = (session) => getSessionGridOrderLogic(session);
const ensureSessionDriverOrder = (session) => ensureSessionDriverOrderLogic(session, { getSessionEntrants }); const ensureSessionDriverOrder = (session) => ensureSessionDriverOrderLogic(session, { getSessionEntrants });
const buildFinalStandings = (event) => buildFinalStandingsLogic(event, { getSessionsForEvent, buildLeaderboard, getSessionEntrants, t }); // Final standings carry each driver's qualifying place (qual, "TQ" for the top qualifier).
const buildFinalStandings = (event) => {
const rows = buildFinalStandingsLogic(event, { getSessionsForEvent, buildLeaderboard, getSessionEntrants, t });
const qualified = rows.length && getSessionsForEvent(event.id).some((session) => session.type === "qualification" && session.status !== "ready");
return qualified ? withQualifyingPlaces(rows, buildQualifyingStandings(event)) : rows;
};
const getManualCorrectionSummary = (row) => getManualCorrectionSummaryLogic(row, { formatLap }); const getManualCorrectionSummary = (row) => getManualCorrectionSummaryLogic(row, { formatLap });
const renderTeamStintLog = (session, rows) => renderTeamStintLogHelper(session, rows, { t, escapeHtml, buildTeamStintLog, formatTeamActiveMemberLabel, renderTable, formatRaceClock }); const renderTeamStintLog = (session, rows) => renderTeamStintLogHelper(session, rows, { t, escapeHtml, buildTeamStintLog, formatTeamActiveMemberLabel, renderTable, formatRaceClock });
@@ -158,8 +163,8 @@ const bindRaceOverviewFor = (root, event) => event && bindRaceOverviewPanel(root
const renderRaceOverviewHeatsHtml = (event) => (getRaceOverview(event)?.phases || []).flatMap((phase) => phase.heats.map(({ session, rows }) => ` const renderRaceOverviewHeatsHtml = (event) => (getRaceOverview(event)?.phases || []).flatMap((phase) => phase.heats.map(({ session, rows }) => `
<section class="print-block"> <section class="print-block">
<h2>${escapeHtml(raceOverviewPhaseLabel(phase.type))} • ${escapeHtml(session.name)}</h2> <h2>${escapeHtml(raceOverviewPhaseLabel(phase.type))} • ${escapeHtml(session.name)}</h2>
${renderTable([t("table.pos"), t("table.driver"), ...(rows.some((row) => row.car) ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")], ${renderTable([t("table.pos"), ...(rows.some((row) => row.qual) ? [t("table.qual")] : []), t("table.driver"), ...(rows.some((row) => row.car) ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")],
rows.map((row) => `<tr><td>${medal(row.pos)}</td><td>${escapeHtml(row.name)}</td>${rows.some((item) => item.car) ? `<td>${escapeHtml(row.car || "-")}</td>` : ""}<td>${row.laps}</td><td>${escapeHtml(row.result)}</td><td>${row.bestLapMs ? escapeHtml(formatLap(row.bestLapMs)) : "-"}</td></tr>`))} rows.map((row) => `<tr><td>${medal(row.pos)}</td>${rows.some((item) => item.qual) ? qualCell(row.qual, escapeHtml) : ""}<td>${escapeHtml(row.name)}</td>${rows.some((item) => item.car) ? `<td>${escapeHtml(row.car || "-")}</td>` : ""}<td>${row.laps}</td><td>${escapeHtml(row.result)}</td><td>${row.bestLapMs ? escapeHtml(formatLap(row.bestLapMs)) : "-"}</td></tr>`))}
</section>`)).join(""); </section>`)).join("");
const getSessionsForEvent = (eventId) => getSessionsForEventHelper(state, eventId); const getSessionsForEvent = (eventId) => getSessionsForEventHelper(state, eventId);
const getModeLabel = (mode) => getModeLabelHelper(mode, { t }); const getModeLabel = (mode) => getModeLabelHelper(mode, { t });
@@ -2867,6 +2872,7 @@ const TRANSLATIONS = {
"table.loop": "Loop", "table.loop": "Loop",
"table.strength": "Signal", "table.strength": "Signal",
"table.pos": "Pos", "table.pos": "Pos",
"table.qual": "Kval",
"table.laps": "Varv", "table.laps": "Varv",
"table.last_lap": "Senaste varv", "table.last_lap": "Senaste varv",
"table.best_lap": "Bästa varv", "table.best_lap": "Bästa varv",
@@ -4993,6 +4999,7 @@ const TRANSLATIONS = {
"table.loop": "Loop", "table.loop": "Loop",
"table.strength": "Strength", "table.strength": "Strength",
"table.pos": "Pos", "table.pos": "Pos",
"table.qual": "Qual.",
"table.laps": "Laps", "table.laps": "Laps",
"table.last_lap": "Last Lap", "table.last_lap": "Last Lap",
"table.best_lap": "Best Lap", "table.best_lap": "Best Lap",
@@ -7438,8 +7445,8 @@ function decoratePrintTables(doc) {
}); });
if (/^(pos|plac|placering|place|#)\.?$/i.test(headers[0]?.textContent.trim() || "")) { if (/^(pos|plac|placering|place|#)\.?$/i.test(headers[0]?.textContent.trim() || "")) {
rows.forEach((row) => { rows.forEach((row) => {
const pos = row.children[0]?.textContent.trim(); const place = /^A?([1-3])$/.exec(row.children[0]?.textContent.trim() || "")?.[1];
if (["1", "2", "3"].includes(pos)) row.classList.add(`podium-${pos}`); if (place) row.classList.add(`podium-${place}`);
}); });
} }
}); });
@@ -7492,7 +7499,12 @@ function openPrintWindow(title, bodyHtml) {
tbody tr:nth-child(even) td { background: ${theme.zebra}; } tbody tr:nth-child(even) td { background: ${theme.zebra}; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; } td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.pos, th.pos { text-align: center; width: 1%; white-space: nowrap; } td.pos, th.pos { text-align: center; width: 1%; white-space: nowrap; }
tr.podium-1 td:first-child { box-shadow: inset 4px 0 #d4af37; } tr.podium-2 td:first-child { box-shadow: inset 4px 0 #a9b0bb; } tr.podium-3 td:first-child { box-shadow: inset 4px 0 #c27c3e; } tr.podium-1 { background: linear-gradient(90deg, rgba(240, 197, 63, 0.35), rgba(240, 197, 63, 0) 70%); }
tr.podium-2 { background: linear-gradient(90deg, rgba(170, 180, 192, 0.35), rgba(170, 180, 192, 0) 70%); }
tr.podium-3 { background: linear-gradient(90deg, rgba(205, 127, 60, 0.32), rgba(205, 127, 60, 0) 70%); }
tbody tr.podium-1 td, tbody tr.podium-2 td, tbody tr.podium-3 td { background: transparent !important; }
td.qual-cell, th.qual-cell { text-align: center; color: #6b7486; }
.tq-badge { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 9.5px; font-weight: 800; color: #1d2330; background: linear-gradient(135deg, #ffe58a, #f2b705); }
tr.podium-1 td, tr.podium-2 td, tr.podium-3 td { font-weight: 700; } tr.podium-1 td, tr.podium-2 td, tr.podium-3 td { font-weight: 700; }
.medal { display: inline-block; width: 20px; height: 20px; line-height: 20px; border-radius: 50%; text-align: center; font-weight: 800; font-size: 11px; color: #4a3500; background: radial-gradient(circle at 32% 28%, #fff7cf 0%, #f4cf55 38%, #c9971c 75%, #9c7210 100%); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.4); } .medal { display: inline-block; width: 20px; height: 20px; line-height: 20px; border-radius: 50%; text-align: center; font-weight: 800; font-size: 11px; color: #4a3500; background: radial-gradient(circle at 32% 28%, #fff7cf 0%, #f4cf55 38%, #c9971c 75%, #9c7210 100%); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.4); }
.medal-2 { color: #33383f; background: radial-gradient(circle at 32% 28%, #ffffff 0%, #dfe3e8 38%, #a8b0ba 75%, #7d8691 100%); } .medal-2 { color: #33383f; background: radial-gradient(circle at 32% 28%, #ffffff 0%, #dfe3e8 38%, #a8b0ba 75%, #7d8691 100%); }
@@ -7640,15 +7652,22 @@ async function exportRaceResultsPdf(event) {
), ),
buildPdfSection( buildPdfSection(
t("events.final_standings"), t("events.final_standings"),
[t("table.pos"), t("table.driver"), t("table.score")], ...(() => {
buildFinalStandings(event).map((row) => [String(row.rank), row.driverName || "-", row.score || "-"]) const rows = buildFinalStandings(event);
const withQual = rows.some((row) => row.qual);
return [
[t("table.pos"), ...(withQual ? [t("table.qual")] : []), t("table.driver"), t("table.score")],
rows.map((row) => [String(row.rank), ...(withQual ? [row.qual || "-"] : []), row.driverName || "-", row.score || "-"]),
];
})()
), ),
...(getRaceOverview(event)?.phases || []).flatMap((phase) => phase.heats.map(({ session, rows }) => { ...(getRaceOverview(event)?.phases || []).flatMap((phase) => phase.heats.map(({ session, rows }) => {
const withCar = rows.some((row) => row.car); const withCar = rows.some((row) => row.car);
const withQual = rows.some((row) => row.qual);
return buildPdfSection( return buildPdfSection(
`${raceOverviewPhaseLabel(phase.type)} • ${session.name}`, `${raceOverviewPhaseLabel(phase.type)} • ${session.name}`,
[t("table.pos"), t("table.driver"), ...(withCar ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")], [t("table.pos"), ...(withQual ? [t("table.qual")] : []), t("table.driver"), ...(withCar ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")],
rows.map((row) => [String(row.pos), row.name, ...(withCar ? [row.car || "-"] : []), String(row.laps), row.result, row.bestLapMs ? formatLap(row.bestLapMs) : "-"]) rows.map((row) => [String(row.pos), ...(withQual ? [row.qual || "-"] : []), row.name, ...(withCar ? [row.car || "-"] : []), String(row.laps), row.result, row.bestLapMs ? formatLap(row.bestLapMs) : "-"])
); );
})), })),
...buildTeamRaceStandings(event).map(({ session, rows }) => ...buildTeamRaceStandings(event).map(({ session, rows }) =>
+11 -3
View File
@@ -1,6 +1,14 @@
// Gold / silver / bronze medal for places 1-3 in result tables; other places stay a plain number. // Gold / silver / bronze medal for places 1-3 in result tables (also A1-A3 in the finals);
// The medal still holds the number, so text, CSV and the print table decoration keep working. // other places stay as they are. The medal still holds the text, so CSV, sorting and the print
// table decoration keep working.
export function medal(pos) { export function medal(pos) {
const value = String(pos ?? "").trim(); const value = String(pos ?? "").trim();
return ["1", "2", "3"].includes(value) ? `<span class="medal medal-${value}">${value}</span>` : value; const place = /^A?([1-3])$/.exec(value)?.[1];
return place ? `<span class="medal medal-${place}">${value}</span>` : value;
}
// The driver's qualifying place next to a final result; the top qualifier gets a "TQ" badge.
export function qualCell(qual, escapeHtml) {
const value = String(qual || "").trim();
return `<td class="qual-cell">${value === "TQ" ? '<span class="tq-badge">TQ</span>' : escapeHtml(value || "-")}</td>`;
} }
+26 -4
View File
@@ -3,6 +3,22 @@
// Works for race events and sponsor events (their heats carry carAssignments). // Works for race events and sponsor events (their heats carry carAssignments).
const PHASES = ["practice", "qualification", "final"]; 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) { export function buildRaceOverview(event, deps) {
const { sessions = [], cars = [], buildLeaderboard, buildPracticeStandings, buildQualifyingStandings, buildFinalStandings } = deps; const { sessions = [], cars = [], buildLeaderboard, buildPracticeStandings, buildQualifyingStandings, buildFinalStandings } = deps;
if (!event) return null; if (!event) return null;
@@ -11,6 +27,9 @@ export function buildRaceOverview(event, deps) {
return carId ? cars.find((car) => car.id === carId)?.name || "" : ""; return carId ? cars.find((car) => car.id === carId)?.name || "" : "";
}; };
const standingsOf = { practice: buildPracticeStandings, qualification: buildQualifyingStandings, final: buildFinalStandings }; 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 phases = PHASES.map((type) => {
const heats = sessions const heats = sessions
.filter((session) => session.type === type && session.status !== "ready") .filter((session) => session.type === type && session.status !== "ready")
@@ -18,6 +37,8 @@ export function buildRaceOverview(event, deps) {
session, session,
rows: buildLeaderboard(session).map((row, index) => ({ rows: buildLeaderboard(session).map((row, index) => ({
pos: index + 1, pos: index + 1,
driverId: row.driverId,
qual: type === "final" ? qualPlaces.get(row.driverId) || "" : "",
name: row.displayName || row.driverName || row.transponder || "-", name: row.displayName || row.driverName || row.transponder || "-",
car: carName(session, row.driverId), car: carName(session, row.driverId),
laps: Number(row.laps || 0), laps: Number(row.laps || 0),
@@ -26,7 +47,8 @@ export function buildRaceOverview(event, deps) {
})), })),
})); }));
const planned = sessions.filter((session) => session.type === type).length; 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); }).filter((phase) => phase.planned);
const finals = phases.find((phase) => phase.type === "final"); 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) : []; 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. // One CSV for the whole race: the standings ("Total") and every heat, one row per driver.
export function buildRaceOverviewCsvRows(overview, { t, formatLap, phaseLabel }) { 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; if (!overview) return rows;
const eventName = overview.event.name || ""; const eventName = overview.event.name || "";
overview.phases.forEach((phase) => { overview.phases.forEach((phase) => {
const label = phaseLabel(phase.type); 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([ 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; return rows;
+3 -3
View File
@@ -1,4 +1,4 @@
import { medal } from "./medal.js"; import { medal, qualCell } from "./medal.js";
// Race Day → Race overview panel: podium, then practice / qualifying / finals with standings // Race Day → Race overview panel: podium, then practice / qualifying / finals with standings
// and every heat. Logic in race_overview_logic.js; print, PDF and CSV come in as deps. // and every heat. Logic in race_overview_logic.js; print, PDF and CSV come in as deps.
const openPhases = new Set(); const openPhases = new Set();
@@ -7,8 +7,8 @@ export function renderRaceOverviewPanel(overview, { t, escapeHtml, formatLap, re
if (!overview || !overview.phases.length) return ""; if (!overview || !overview.phases.length) return "";
const { event, phases, podium } = overview; const { event, phases, podium } = overview;
const heatTable = (rows) => renderTable( const heatTable = (rows) => renderTable(
[t("table.pos"), t("table.driver"), ...(rows.some((row) => row.car) ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")], [t("table.pos"), ...(rows.some((row) => row.qual) ? [t("table.qual")] : []), t("table.driver"), ...(rows.some((row) => row.car) ? [t("race_overview.car")] : []), t("table.laps"), t("table.result"), t("table.best_lap")],
rows.map((row) => `<tr><td>${medal(row.pos)}</td><td>${escapeHtml(row.name)}</td>${rows.some((item) => item.car) ? `<td>${escapeHtml(row.car || "-")}</td>` : ""}<td>${row.laps}</td><td>${escapeHtml(row.result)}</td><td>${row.bestLapMs ? escapeHtml(formatLap(row.bestLapMs)) : "-"}</td></tr>`) rows.map((row) => `<tr><td>${medal(row.pos)}</td>${rows.some((item) => item.qual) ? qualCell(row.qual, escapeHtml) : ""}<td>${escapeHtml(row.name)}</td>${rows.some((item) => item.car) ? `<td>${escapeHtml(row.car || "-")}</td>` : ""}<td>${row.laps}</td><td>${escapeHtml(row.result)}</td><td>${row.bestLapMs ? escapeHtml(formatLap(row.bestLapMs)) : "-"}</td></tr>`)
); );
return ` return `
<section class="panel mt-16 race-overview" id="raceDayOverview"> <section class="panel mt-16 race-overview" id="raceDayOverview">
+4 -2
View File
@@ -1,4 +1,4 @@
import { medal } from "./medal.js"; import { medal, qualCell } from "./medal.js";
export function renderRaceFormatField(labelKey, hintKey, controlHtml, options = {}, { t }) { export function renderRaceFormatField(labelKey, hintKey, controlHtml, options = {}, { t }) {
const extraClass = options.checkbox ? " field-card-checkbox" : ""; const extraClass = options.checkbox ? " field-card-checkbox" : "";
return ` return `
@@ -211,12 +211,14 @@ export function renderRaceStandingsTable(rows, emptyLabel, { t, renderTable, esc
return `<p>${emptyLabel}</p>`; return `<p>${emptyLabel}</p>`;
} }
const withQual = rows.some((row) => row.qual);
return renderTable( return renderTable(
[t("table.pos"), t("table.driver"), t("table.score")], [t("table.pos"), ...(withQual ? [t("table.qual")] : []), t("table.driver"), t("table.score")],
rows.map( rows.map(
(row) => ` (row) => `
<tr> <tr>
<td>${medal(row.rank)}</td> <td>${medal(row.rank)}</td>
${withQual ? qualCell(row.qual, escapeHtml) : ""}
<td>${escapeHtml(row.driverName || t("common.unknown_driver"))}</td> <td>${escapeHtml(row.driverName || t("common.unknown_driver"))}</td>
<td> <td>
<div class="table-primary">${escapeHtml(row.score || "-")}</div> <div class="table-primary">${escapeHtml(row.score || "-")}</div>
+9
View File
@@ -4890,3 +4890,12 @@ details.event-group > summary { cursor: pointer; list-style: revert; }
.race-overview-podium .medal::before { content: ""; position: absolute; top: -12px; left: 50%; width: 18px; height: 14px; transform: translateX(-50%); background: linear-gradient(90deg, #2f6fde 0 38%, #f4cf55 38% 62%, #2f6fde 62%); clip-path: polygon(0 0, 100% 0, 75% 100%, 25% 100%); z-index: -1; } .race-overview-podium .medal::before { content: ""; position: absolute; top: -12px; left: 50%; width: 18px; height: 14px; transform: translateX(-50%); background: linear-gradient(90deg, #2f6fde 0 38%, #f4cf55 38% 62%, #2f6fde 62%); clip-path: polygon(0 0, 100% 0, 75% 100%, 25% 100%); z-index: -1; }
.race-overview-podium .podium-1 { border-color: #e2bd45; } .race-overview-podium .podium-1 { border-color: #e2bd45; }
.race-overview-podium li { position: relative; z-index: 0; } .race-overview-podium li { position: relative; z-index: 0; }
/* House of RC style: the qualifying place next to a final result, and the top three rows
tinted gold / silver / bronze, fading out to the right. */
.qual-cell { color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.tq-badge { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 0.75em; font-weight: 800; letter-spacing: 0.04em; color: #1d2330; background: linear-gradient(135deg, #ffe58a, #f2b705); }
tr:has(> td > .medal-1) { background: linear-gradient(90deg, rgba(240, 197, 63, 0.28), rgba(240, 197, 63, 0) 70%); }
tr:has(> td > .medal-2) { background: linear-gradient(90deg, rgba(190, 199, 210, 0.26), rgba(190, 199, 210, 0) 70%); }
tr:has(> td > .medal-1) > td, tr:has(> td > .medal-2) > td, tr:has(> td > .medal-3) > td { background: transparent; }
tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60, 0.26), rgba(205, 127, 60, 0) 70%); }
+9
View File
@@ -30,3 +30,12 @@ test("places 1-3 get gold, silver and bronze medals - in the app tables and draw
assert.ok(pdf.includes("0.941 0.773 0.247 rg") && pdf.includes("0.812 0.835 0.863 rg") && pdf.includes("0.827 0.541 0.298 rg"), "gold, silver and bronze medal faces"); assert.ok(pdf.includes("0.941 0.773 0.247 rg") && pdf.includes("0.812 0.835 0.863 rg") && pdf.includes("0.827 0.541 0.298 rg"), "gold, silver and bronze medal faces");
assert.ok(pdf.includes("(4) Tj"), "place 4 stays a plain number"); assert.ok(pdf.includes("(4) Tj"), "place 4 stays a plain number");
}); });
test("A-final places 1-3 also get medals, and TQ stands out", async () => {
const { medal, qualCell } = await import("../src/medal.js");
assert.equal(medal("A2"), '<span class="medal medal-2">A2</span>');
assert.equal(medal("B1"), "B1");
assert.match(qualCell("TQ", (v) => v), /tq-badge/);
const pdf = buildStyledPdf({ ...base, sections: [{ title: "", headers: ["Pos", "Kval", "Förare"], rows: [["A1", "4", "Al"], ["A2", "TQ", "Bea"]] }] }).toString("latin1");
assert.ok(pdf.includes("(A1) Tj") && pdf.includes("/F2 9 Tf") && pdf.includes("(TQ) Tj"));
});
+19 -3
View File
@@ -1,6 +1,6 @@
import test from "node:test"; import test from "node:test";
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import { buildRaceOverview, buildRaceOverviewCsvRows } from "../src/race_overview_logic.js"; import { buildRaceOverview, buildRaceOverviewCsvRows, qualifyingPlaces } from "../src/race_overview_logic.js";
const sessions = [ const sessions = [
{ id: "p1", type: "practice", status: "finished", name: "Practice G1", carAssignments: { d1: "c1", d2: "c2" } }, { id: "p1", type: "practice", status: "finished", name: "Practice G1", carAssignments: { d1: "c1", d2: "c2" } },
@@ -39,8 +39,8 @@ test("CSV has the standings and every heat row", () => {
const overview = buildRaceOverview({ id: "e1", name: "Cup" }, deps); const overview = buildRaceOverview({ id: "e1", name: "Cup" }, deps);
const rows = buildRaceOverviewCsvRows(overview, { t: (key) => key, formatLap: (ms) => (ms / 1000).toFixed(3), phaseLabel: (type) => type }); const rows = buildRaceOverviewCsvRows(overview, { t: (key) => key, formatLap: (ms) => (ms / 1000).toFixed(3), phaseLabel: (type) => type });
assert.equal(rows[0][0], "event"); assert.equal(rows[0][0], "event");
assert.deepEqual(rows[1], ["Cup", "practice", "race_overview.total", "1", "Bea", "", "", "17.180", ""]); assert.deepEqual(rows[1], ["Cup", "practice", "race_overview.total", "1", "", "Bea", "", "", "17.180", ""]);
assert.deepEqual(rows[2], ["Cup", "practice", "Practice G1", "1", "Bea", "Hyrbil 2", "10", "10/3:01.200", "17.180"]); assert.deepEqual(rows[2], ["Cup", "practice", "Practice G1", "1", "", "Bea", "Hyrbil 2", "10", "10/3:01.200", "17.180"]);
assert.equal(rows.length, 6); assert.equal(rows.length, 6);
}); });
@@ -55,3 +55,19 @@ test("results archive groups heats per event, newest event first, A final winner
]); ]);
assert.deepEqual(groups.map((group) => [group.key, group.rows.length, group.winnerName, group.driverCount]), [["e1", 2, "Al", 1], ["session:x", 1, "", 0]]); assert.deepEqual(groups.map((group) => [group.key, group.rows.length, group.winnerName, group.driverCount]), [["e1", 2, "Al", 1], ["session:x", 1, "", 0]]);
}); });
test("finals show each driver's qualifying place, with TQ for the top qualifier", () => {
assert.deepEqual([...qualifyingPlaces([{ driverId: "d1", rank: 1 }, { driverId: "d2", rank: 2 }])], [["d1", "TQ"], ["d2", "2"]]);
const finalSessions = sessions.map((session) => (session.id === "f1" ? { ...session, status: "finished" } : session));
const overview = buildRaceOverview({ id: "e1", name: "Cup" }, {
...deps,
sessions: finalSessions,
buildLeaderboard: (session) => (session.id === "f1" ? [{ driverId: "d2", displayName: "Bea", laps: 5 }, { driverId: "d1", displayName: "Al", laps: 5 }] : leaderboards[session.id] || []),
buildQualifyingStandings: () => [{ driverId: "d1", rank: 1 }, { driverId: "d2", rank: 2 }],
buildFinalStandings: () => [{ rank: "A1", driverId: "d2", driverName: "Bea" }, { rank: "A2", driverId: "d1", driverName: "Al" }],
});
const finals = overview.phases.find((phase) => phase.type === "final");
assert.deepEqual(finals.heats[0].rows.map((row) => [row.pos, row.name, row.qual]), [[1, "Bea", "2"], [2, "Al", "TQ"]]);
assert.deepEqual(finals.standings.map((row) => [row.rank, row.qual]), [["A1", "2"], ["A2", "TQ"]]);
assert.equal(overview.phases.find((phase) => phase.type === "practice").heats[0].rows[0].qual, "", "only finals get the column");
});