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

+38 -7
View File
@@ -15,6 +15,7 @@ import { flagHtml, driverCountryCode, countryChoices, setDriverCountryResolver,
import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js";
import { assignMarshals, normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate, getDueCall, withRaceSetupStart, eventScheduleFromDayRows } from "./day_schedule_logic.js";
import { buildRaceOverview, buildRaceOverviewCsvRows, withQualifyingPlaces, qualifyingPlaces } from "./race_overview_logic.js";
import { buildRaceDayCsvRows, raceDayCsvFilename } from "./race_day_export_logic.js";
import { renderLapChartSvg } from "./lap_chart_logic.js";
import { participantCopySources } from "./participant_picker.js";
import { renderRaceOverviewPanel, bindRaceOverviewPanel } from "./race_overview_view.js";
@@ -1225,9 +1226,9 @@ const exportSeriesPdf = async (series, tables) => {
)),
});
};
const renderSeries = () => renderSeriesView({ mergeDrivers, state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries, getSeriesRounds, deleteSeriesRaces, runSeriesSession, runSeriesSeeding, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound });
const renderSeries = () => renderSeriesView({ mergeDrivers, exportRaceDayCsv, state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries, getSeriesRounds, deleteSeriesRaces, runSeriesSession, runSeriesSeeding, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound });
const renderArchive = () => renderResultsArchiveView({
getBackendUrl,
getBackendUrl, exportRaceDayCsv,
state, dom, t, escapeHtml, formatLap, formatRaceClock, renderTable,
getClassName, getEventName, buildLeaderboard, getCompetitorPassings,
exportRaceResultsPdf, buildRacePackagePayload, downloadJsonFile, sanitizeFilenameSegment,
@@ -1637,6 +1638,15 @@ const TRANSLATIONS = {
"archive.all_drivers": "Alla förare",
"archive.date_from": "Från datum",
"archive.date_to": "Till datum",
"archive.day_csv": "CSV för racedagen",
"archive.day_csv_hint": "Välj samma datum i Från och Till (och ev. en klass) för att exportera hela dagens varv.",
"archive.day_csv_empty": "Inga avslutade heat det datumet.",
"series.day_csv": "CSV för dagen",
"export.class": "Klass", "export.race": "Race", "export.order": "Ordning", "export.session": "Heat",
"export.lap": "Varv", "export.lap_time": "Varvtid", "export.time_of_day": "Klockslag", "export.counted": "Räknat",
"export.position": "Placering", "export.laps": "Varv", "export.total_time": "Totaltid", "export.best_lap": "Bästa varv",
"export.average_lap": "Snittvarv", "export.summary": "Sammanfattning per heat", "export.laps_all": "Alla varv",
"export.yes": "Ja", "export.no": "Nej",
"archive.date": "Datum",
"archive.event": "Event",
"archive.session": "Session",
@@ -4026,6 +4036,15 @@ const TRANSLATIONS = {
"archive.all_drivers": "All drivers",
"archive.date_from": "From date",
"archive.date_to": "To date",
"archive.day_csv": "CSV for the race day",
"archive.day_csv_hint": "Pick the same date in From and To (and a class if you like) to export every lap of that day.",
"archive.day_csv_empty": "No finished heats on that date.",
"series.day_csv": "CSV for the day",
"export.class": "Class", "export.race": "Race", "export.order": "Order", "export.session": "Heat",
"export.lap": "Lap", "export.lap_time": "Lap time", "export.time_of_day": "Time of day", "export.counted": "Counted",
"export.position": "Position", "export.laps": "Laps", "export.total_time": "Total time", "export.best_lap": "Best lap",
"export.average_lap": "Average lap", "export.summary": "Summary per heat", "export.laps_all": "All laps",
"export.yes": "Yes", "export.no": "No",
"archive.date": "Date",
"archive.event": "Event",
"archive.session": "Session",
@@ -7180,13 +7199,25 @@ function downloadJsonFile(filename, payload) {
downloadBlobFile(filename, new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" }));
}
function rowToCsv(row) {
return row.map((value) => `"${String(value || "").replaceAll('"', '""')}"`).join(",");
function rowToCsv(row, separator = ",") {
return row.map((value) => `"${String(value || "").replaceAll('"', '""')}"`).join(separator);
}
function downloadCsvFile(filename, rows) {
const csv = rows.map((row) => rowToCsv(row)).join("\n");
downloadBlobFile(filename, new Blob([csv], { type: "text/csv;charset=utf-8" }));
// excel: semicolons and a BOM, so Excel with Swedish settings opens it in columns with å/ä/ö.
function downloadCsvFile(filename, rows, { excel = false } = {}) {
const csv = rows.map((row) => rowToCsv(row, excel ? ";" : ",")).join(excel ? "\r\n" : "\n");
downloadBlobFile(filename, new Blob([excel ? "\uFEFF" + csv : csv], { type: "text/csv;charset=utf-8" }));
}
// Every lap of a race day (one class or all) plus a summary per heat, as one CSV.
function exportRaceDayCsv(date, classId = "") {
const rows = buildRaceDayCsvRows(state, {
date, classId, t, formatLap, getClassName, buildLeaderboard,
getPassings: (session, row) => getCompetitorPassings(session, row, { includeInvalid: true }),
invalidLabel: (passing) => getPassingValidationLabel(passing),
});
if (rows.length <= 5) { window.alert(t("archive.day_csv_empty")); return; }
downloadCsvFile(raceDayCsvFilename(date, classId ? getClassName(classId) : ""), rows, { excel: true });
}
function buildDataExportPayload() {