feat(houseofrc): send heats automatically after every heat, show send status, warn before sending (1.85.0)
This commit is contained in:
1 parent
38cfa7ff2d
commit
3870510d8c
15 files changed
+189
-18
No files matched your search
+43
-2
@@ -6,6 +6,8 @@ import { getOverlayModeLabel, buildOverlayPanels, renderOverlaySidePanel, render
|
||||
|
||||
import { renderSettings, openSettingsTab } from "./settings.js";
|
||||
import { buildRaceDayQueue, buildRaceDayPreflight, getRaceDriverIds, shouldOfferFinals } from "./race_day_logic.js";
|
||||
import { findHouseOfRcAutoSends } from "./houseofrc_logic.js";
|
||||
import { sendHouseOfRcResults, renderHouseOfRcSendStatus } from "./houseofrc_view.js";
|
||||
import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologueRemainingMs, holdPrologue, resumePrologue, setPrologueRemaining, takeDuePrologueCall, formatPrologueTime, getPrologueHandoverMs, normalizePrologueSec, getPrologueMarks } from "./prologue_logic.js";
|
||||
import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js";
|
||||
import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay, refreshRaceDayLive } from "./race_day_view.js";
|
||||
@@ -518,6 +520,23 @@ function buildHeatCallDrivers(session) {
|
||||
function getDueCallFor(date) {
|
||||
return getDueCall(buildDayRows(date), { day: getDayPlan(date), snoozedUntil: (id) => callSnoozes.get(id) || 0 });
|
||||
}
|
||||
// House of RC "send heats automatically": the race controller sends heats and qualifying of
|
||||
// every race where a heat has finished since the last send; never the final placings.
|
||||
// A failed send is tried again a minute later (findHouseOfRcAutoSends).
|
||||
let houseOfRcAutoSendBusy = false;
|
||||
async function tickHouseOfRcAutoSend() {
|
||||
if (overlayMode || houseOfRcAutoSendBusy || !isRaceMaster()) return;
|
||||
const due = findHouseOfRcAutoSends(state);
|
||||
if (!due.length) return;
|
||||
houseOfRcAutoSendBusy = true;
|
||||
try {
|
||||
for (const event of due) await sendHouseOfRcResults({ event, overview: getRaceOverview(event), state, final: false });
|
||||
saveState();
|
||||
if (currentView === "race_day") renderView();
|
||||
} finally {
|
||||
houseOfRcAutoSendBusy = false;
|
||||
}
|
||||
}
|
||||
function tickDayCalls() {
|
||||
if (overlayMode || !isRaceMaster()) return;
|
||||
if (autopilotDate) {
|
||||
@@ -755,6 +774,7 @@ const renderRaceDay = () => renderRaceDayView({
|
||||
setCompetitorLapStatus,
|
||||
...speakerPanelDeps,
|
||||
shouldOfferFinals: (eventId) => shouldOfferFinals(state, eventId),
|
||||
renderHouseOfRcStatus: (eventId) => renderHouseOfRcSendStatus(state.events.find((event) => event.id === eventId), { t, escapeHtml }),
|
||||
createFinalsForEvent: (eventId) => {
|
||||
const event = state.events.find((item) => item.id === eventId);
|
||||
if (!event || !generateFinalsForRace(event)) return null;
|
||||
@@ -2223,6 +2243,17 @@ const TRANSLATIONS = {
|
||||
"houseofrc.entries_class": "Klass hos oss",
|
||||
"houseofrc.entries_hor_class": "Klass på House of RC",
|
||||
"houseofrc.refresh_button": "Hämta ändringar från House of RC",
|
||||
"houseofrc.auto_send": "Skicka heat automatiskt",
|
||||
"houseofrc.auto_send_hint": "Efter varje heat skickar race controller-datorn heat och kval till House of RC (inte slutplaceringen). Utan internet försöker den igen varje minut.",
|
||||
"houseofrc.status_auto_waiting": "Skickas efter nästa heat",
|
||||
"houseofrc.status_sent_heats": "Skickat {time} · heat",
|
||||
"houseofrc.status_sent_final": "Skickat {time} · slutresultat",
|
||||
"houseofrc.status_failed": "Kunde inte skicka {time}",
|
||||
"houseofrc.status_failed_retry": "Väntar på att skicka ({time}) – försöker igen",
|
||||
"houseofrc.warn_running": "Ett heat körs just nu – dess resultat är inte klart.",
|
||||
"houseofrc.warn_finals_left": "Finaler som inte är körda: {names}.",
|
||||
"houseofrc.warn_missing": "{count} deltagare saknar anmälan på House of RC och kommer inte med.",
|
||||
"houseofrc.warn_unchanged": "Inget har ändrats sedan senaste utskicket.",
|
||||
"houseofrc.refresh_link_only": "Kör redan – kopplas till anmälan",
|
||||
"houseofrc.results_button": "Skicka resultat till House of RC",
|
||||
"houseofrc.results_hint": "Förhandsgranska och skicka resultatet till {name}",
|
||||
@@ -2240,7 +2271,6 @@ const TRANSLATIONS = {
|
||||
"houseofrc.results_send": "Skicka ({count})",
|
||||
"houseofrc.results_sending": "Skickar …",
|
||||
"houseofrc.results_sent": "{count} anmälningar uppdaterade på House of RC.",
|
||||
"houseofrc.results_last": "senast skickat {time}",
|
||||
"houseofrc.results_close": "Stäng",
|
||||
"houseofrc.err_rejected": "House of RC tog inte emot resultatet, inget skrevs: {message}",
|
||||
"houseofrc.refresh_hint": "Nya anmälningar och avanmälningar sedan racet skapades ({name})",
|
||||
@@ -4467,6 +4497,17 @@ const TRANSLATIONS = {
|
||||
"houseofrc.entries_class": "Our class",
|
||||
"houseofrc.entries_hor_class": "Class on House of RC",
|
||||
"houseofrc.refresh_button": "Fetch changes from House of RC",
|
||||
"houseofrc.auto_send": "Send heats automatically",
|
||||
"houseofrc.auto_send_hint": "After every heat the race controller sends heats and qualifying to House of RC (not the final placings). Without internet it tries again every minute.",
|
||||
"houseofrc.status_auto_waiting": "Sent after the next heat",
|
||||
"houseofrc.status_sent_heats": "Sent {time} · heats",
|
||||
"houseofrc.status_sent_final": "Sent {time} · final results",
|
||||
"houseofrc.status_failed": "Could not send {time}",
|
||||
"houseofrc.status_failed_retry": "Waiting to send ({time}) – trying again",
|
||||
"houseofrc.warn_running": "A heat is running – its result isn't complete yet.",
|
||||
"houseofrc.warn_finals_left": "Finals not run yet: {names}.",
|
||||
"houseofrc.warn_missing": "{count} participants have no House of RC entry and are left out.",
|
||||
"houseofrc.warn_unchanged": "Nothing has changed since the last send.",
|
||||
"houseofrc.refresh_link_only": "Already racing – linked to the entry",
|
||||
"houseofrc.results_button": "Send results to House of RC",
|
||||
"houseofrc.results_hint": "Preview and send the results to {name}",
|
||||
@@ -4484,7 +4525,6 @@ const TRANSLATIONS = {
|
||||
"houseofrc.results_send": "Send ({count})",
|
||||
"houseofrc.results_sending": "Sending …",
|
||||
"houseofrc.results_sent": "{count} entries updated on House of RC.",
|
||||
"houseofrc.results_last": "last sent {time}",
|
||||
"houseofrc.results_close": "Close",
|
||||
"houseofrc.err_rejected": "House of RC did not accept the results, nothing was written: {message}",
|
||||
"houseofrc.refresh_hint": "New entries and withdrawals since the race was created ({name})",
|
||||
@@ -6016,6 +6056,7 @@ async function init() {
|
||||
setInterval(tickClock, 1000);
|
||||
updateSyncStatus();
|
||||
setInterval(updateSyncStatus, 1000);
|
||||
setInterval(tickHouseOfRcAutoSend, 10000);
|
||||
document.getElementById("syncStatusRetry")?.addEventListener("click", async () => {
|
||||
if (backend.pendingWrites) return;
|
||||
if (localStateDirty || backend.writeError || backend.passingError) {
|
||||
|
||||
@@ -614,6 +614,13 @@ export function renderEventManagerView(context) {
|
||||
},
|
||||
}));
|
||||
|
||||
// Send heats and qualifying to House of RC by itself after every heat (see app.js).
|
||||
document.getElementById("houseOfRcAutoSend")?.addEventListener("change", (change) => {
|
||||
event.houseOfRc.autoSend = change.currentTarget.checked;
|
||||
saveState();
|
||||
refreshManager();
|
||||
});
|
||||
|
||||
// Race made from House of RC: preview and send the results to its entries.
|
||||
document.getElementById("houseOfRcSendResults")?.addEventListener("click", () => openHouseOfRcResultsPost({
|
||||
event, overview: getRaceOverview(event), state, t, escapeHtml, saveState,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { renderHouseOfRcSendStatus } from "./houseofrc_view.js";
|
||||
import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
|
||||
import { groupSessionsBySteps } from "./race_list_logic.js";
|
||||
|
||||
@@ -190,6 +191,7 @@ export function renderEventManagerMarkup(context) {
|
||||
<button id="clearParticipants" class="btn btn-danger" type="button">${t("events.clear_participants")}</button>
|
||||
${event.houseOfRc?.eventId ? `<button id="houseOfRcRefreshEntries" class="btn" type="button" title="${escapeHtml(t("houseofrc.refresh_hint", { name: event.houseOfRc.name || "" }))}">🔄 ${t("houseofrc.refresh_button")}</button>` : ""}
|
||||
${event.houseOfRc?.eventId ? `<button id="houseOfRcSendResults" class="btn" type="button" title="${escapeHtml(t("houseofrc.results_hint", { name: event.houseOfRc.name || "" }))}">📤 ${t("houseofrc.results_button")}</button>` : ""}
|
||||
${event.houseOfRc?.eventId ? `<label class="toggle hor-auto-send" title="${escapeHtml(t("houseofrc.auto_send_hint"))}"><input type="checkbox" id="houseOfRcAutoSend" ${event.houseOfRc.autoSend ? "checked" : ""} /><span>${t("houseofrc.auto_send")}</span></label> ${renderHouseOfRcSendStatus(event, { t, escapeHtml })}` : ""}
|
||||
</div>
|
||||
${(() => {
|
||||
const card = (driver) => {
|
||||
|
||||
@@ -233,3 +233,46 @@ const toMs = (text) => {
|
||||
const [minutes, seconds] = String(text).includes(":") ? String(text).split(":") : ["0", text];
|
||||
return Number(minutes) * 60000 + Number(seconds) * 1000;
|
||||
};
|
||||
|
||||
// What the results are built from: every finished qualifying heat and final, with when it
|
||||
// ended. A change means there is something new to send.
|
||||
export function houseOfRcResultsSignature(event, sessions = []) {
|
||||
return sessions
|
||||
.filter((session) => session.eventId === event?.id && ["qualification", "final"].includes(session.type) && ["finished", "stopped"].includes(session.status))
|
||||
.map((session) => `${session.id}:${Number(session.endedAt) || 0}`)
|
||||
.sort()
|
||||
.join("|");
|
||||
}
|
||||
|
||||
// Races with "send heats automatically" on that have a finished heat not sent yet. A failed
|
||||
// try waits retryMs before the next one (no internet at the track: it keeps trying).
|
||||
export const HOUSE_OF_RC_RETRY_MS = 60000;
|
||||
export function findHouseOfRcAutoSends(state, now = Date.now()) {
|
||||
return (state?.events || []).filter((event) => {
|
||||
const link = event.houseOfRc;
|
||||
if (!link?.eventId || !link.autoSend) return false;
|
||||
const signature = houseOfRcResultsSignature(event, state.sessions);
|
||||
if (!signature) return false;
|
||||
const last = link.lastSend || {};
|
||||
if (last.ok && last.signature === signature) return false;
|
||||
if (!last.ok && last.at && now - Date.parse(last.at) < HOUSE_OF_RC_RETRY_MS) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Before sending: what might not be what you want. [{ key, params }] for houseofrc.warn_<key>.
|
||||
export function checkHouseOfRcResults(event, overview, { final = false, sessions = [], missing = [] } = {}) {
|
||||
const warnings = [];
|
||||
const ofEvent = sessions.filter((session) => session.eventId === event?.id);
|
||||
const done = (session) => ["finished", "stopped"].includes(session.status);
|
||||
if (ofEvent.some((session) => ["running", "paused"].includes(session.status))) warnings.push({ key: "running" });
|
||||
if (final) {
|
||||
const finals = ofEvent.filter((session) => session.type === "final");
|
||||
const left = finals.filter((session) => !done(session));
|
||||
if (left.length) warnings.push({ key: "finals_left", params: { names: left.map((session) => session.name).join(", ") } });
|
||||
}
|
||||
if (missing.length) warnings.push({ key: "missing", params: { count: missing.length } });
|
||||
const last = event?.houseOfRc?.lastSend;
|
||||
if (last?.ok && last.signature === houseOfRcResultsSignature(event, sessions) && Boolean(last.final) === Boolean(final)) warnings.push({ key: "unchanged" });
|
||||
return warnings;
|
||||
}
|
||||
+29
-6
@@ -1,4 +1,4 @@
|
||||
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass, rememberHouseOfRcClass, diffHouseOfRcEntries, applyHouseOfRcEntryChanges, buildHouseOfRcResults } from "./houseofrc_logic.js";
|
||||
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass, rememberHouseOfRcClass, diffHouseOfRcEntries, applyHouseOfRcEntryChanges, buildHouseOfRcResults, houseOfRcResultsSignature, checkHouseOfRcResults } from "./houseofrc_logic.js";
|
||||
|
||||
// Settings → System → House of RC: save the club's API key on the server and test it.
|
||||
// The key is never read back; the server only tells whether one is set (and its last 4 chars).
|
||||
@@ -360,9 +360,10 @@ export function openHouseOfRcResultsPost({ event, overview, state, t, escapeHtml
|
||||
let final = hasFinals && Boolean(overview?.finished);
|
||||
const render = () => {
|
||||
const { entries, rows, missing } = buildHouseOfRcResults(event, overview, { final, drivers: state.drivers });
|
||||
const warnings = checkHouseOfRcResults(event, overview, { final, sessions: state.sessions, missing });
|
||||
const where = [event.houseOfRc.name, event.houseOfRc.className].filter(Boolean).join(" – ");
|
||||
body.innerHTML = `
|
||||
<p><strong>${escapeHtml(where)}</strong>${event.houseOfRc.resultsSentAt ? ` <span class="hint">· ${escapeHtml(t("houseofrc.results_last", { time: new Date(event.houseOfRc.resultsSentAt).toLocaleString() }))}</span>` : ""}</p>
|
||||
<p><strong>${escapeHtml(where)}</strong> ${renderHouseOfRcSendStatus(event, { t, escapeHtml })}</p>
|
||||
<div class="hor-modes">
|
||||
<label class="hor-choice"><input type="radio" name="horResultsMode" value="heats" ${final ? "" : "checked"} /> ${escapeHtml(t("houseofrc.results_mode_heats"))}</label>
|
||||
<label class="hor-choice"><input type="radio" name="horResultsMode" value="final" ${final ? "checked" : ""} ${hasFinals ? "" : "disabled"} /> ${escapeHtml(t("houseofrc.results_mode_final"))}</label>
|
||||
@@ -377,6 +378,7 @@ export function openHouseOfRcResultsPost({ event, overview, state, t, escapeHtml
|
||||
<td>${row.heats}</td><td>${escapeHtml(row.bestLap || "–")}</td>
|
||||
</tr>`).join("")}</tbody></table></div>
|
||||
${missing.length ? `<p class="hint">⚠️ ${escapeHtml(t("houseofrc.results_missing", { names: missing.join(", ") }))}</p>` : ""}
|
||||
${warnings.length ? `<ul class="hor-warnings">${warnings.map((warning) => `<li>⚠️ ${escapeHtml(t(`houseofrc.warn_${warning.key}`, warning.params || {}))}</li>`).join("")}</ul>` : ""}
|
||||
<p data-hor-result-status></p>
|
||||
<div class="actions mt-16">
|
||||
<button class="btn btn-primary" type="button" data-hor-send ${entries.length ? "" : "disabled"}>📤 ${escapeHtml(t("houseofrc.results_send", { count: entries.length }))}</button>
|
||||
@@ -388,16 +390,14 @@ export function openHouseOfRcResultsPost({ event, overview, state, t, escapeHtml
|
||||
const statusLine = body.querySelector("[data-hor-result-status]");
|
||||
button.disabled = true;
|
||||
statusLine.textContent = t("houseofrc.results_sending");
|
||||
const { status: code, body: data } = await postJson("/api/houseofrc/results", { eventId: event.houseOfRc.eventId, entries });
|
||||
const { code, data } = await sendHouseOfRcResults({ event, overview, state, final });
|
||||
saveState();
|
||||
if (code !== 200 || !data.ok) {
|
||||
statusLine.className = "error";
|
||||
statusLine.textContent = describeHouseOfRcError(t, code, data);
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
event.houseOfRc.resultsSentAt = new Date().toISOString();
|
||||
event.houseOfRc.resultsSentFinal = final;
|
||||
saveState();
|
||||
statusLine.className = "";
|
||||
statusLine.textContent = `✅ ${t("houseofrc.results_sent", { count: data.updated })}`;
|
||||
});
|
||||
@@ -405,3 +405,26 @@ export function openHouseOfRcResultsPost({ event, overview, state, t, escapeHtml
|
||||
render();
|
||||
return { close };
|
||||
}
|
||||
|
||||
// One write of the race's results; remembers how it went on the race (event.houseOfRc.lastSend)
|
||||
// for the status shown in Manage and Race Day, and for the automatic sending after each heat.
|
||||
// The caller saves the state.
|
||||
export async function sendHouseOfRcResults({ event, overview, state, final = false }) {
|
||||
const { entries } = buildHouseOfRcResults(event, overview, { final, drivers: state.drivers });
|
||||
const signature = houseOfRcResultsSignature(event, state.sessions);
|
||||
if (!entries.length) return { code: 400, data: { error: "invalid_entries" } };
|
||||
const { status: code, body: data } = await postJson("/api/houseofrc/results", { eventId: event.houseOfRc.eventId, entries });
|
||||
const ok = code === 200 && Boolean(data.ok);
|
||||
event.houseOfRc.lastSend = { at: new Date().toISOString(), final, ok, signature, count: ok ? Number(data.updated) || 0 : 0, error: ok ? "" : String(data.error || code) };
|
||||
return { code, data };
|
||||
}
|
||||
|
||||
// "🏠 Sent 21:19 · heats", "⚠️ Waiting to send – trying again" or nothing.
|
||||
export function renderHouseOfRcSendStatus(event, { t, escapeHtml }) {
|
||||
const last = event?.houseOfRc?.lastSend;
|
||||
if (!last?.at) return event?.houseOfRc?.autoSend ? `<span class="pill" data-hor-send-status>🏠 ${escapeHtml(t("houseofrc.status_auto_waiting"))}</span>` : "";
|
||||
const time = new Date(last.at).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
||||
return last.ok
|
||||
? `<span class="pill pill-green" data-hor-send-status>🏠 ${escapeHtml(t(last.final ? "houseofrc.status_sent_final" : "houseofrc.status_sent_heats", { time }))}</span>`
|
||||
: `<span class="pill pill-warn" data-hor-send-status title="${escapeHtml(last.error || "")}">⚠️ ${escapeHtml(t(event.houseOfRc.autoSend ? "houseofrc.status_failed_retry" : "houseofrc.status_failed", { time }))}</span>`;
|
||||
}
|
||||
@@ -267,6 +267,7 @@ export function renderRaceDayView(deps) {
|
||||
renderRaceOverview = () => "", bindRaceOverview = () => {},
|
||||
renderSpeakerPanel = () => "", bindSpeakerPanel = () => {},
|
||||
shouldOfferFinals = () => false, createFinalsForEvent = () => null,
|
||||
renderHouseOfRcStatus = () => "",
|
||||
} = deps;
|
||||
const queue = buildRaceDayQueue(state);
|
||||
const session = queue.current;
|
||||
@@ -317,7 +318,7 @@ export function renderRaceDayView(deps) {
|
||||
<div>
|
||||
<span class="race-day-kicker">${t("race_day.current")}</span>
|
||||
<h2>${session ? escapeHtml(session.name) : t("race_day.no_session")}</h2>
|
||||
<p>${session ? `${escapeHtml(getEventName(session.eventId))} · ${escapeHtml(getSessionTypeLabel(session.type))} · ${escapeHtml(getStartModeLabel(session.startMode))}` : t("race_day.no_session_hint")}</p>
|
||||
<p>${session ? `${escapeHtml(getEventName(session.eventId))} · ${escapeHtml(getSessionTypeLabel(session.type))} · ${escapeHtml(getStartModeLabel(session.startMode))} ${renderHouseOfRcStatus(session.eventId)}` : t("race_day.no_session_hint")}</p>
|
||||
${renderTrackLayoutBar({ state, t, escapeHtml, showNewButton: false })}
|
||||
</div>
|
||||
${prologue
|
||||
|
||||
@@ -4947,6 +4947,8 @@ tr:has(> td > .medal-3) { background: linear-gradient(90deg, rgba(205, 127, 60,
|
||||
.hor-import-table { width: 100%; }
|
||||
.hor-import-table th { text-align: left; }
|
||||
.hor-import-table td { vertical-align: middle; }
|
||||
.hor-warnings { margin: 8px 0; padding-left: 18px; color: var(--warn, #f5b942); }
|
||||
.hor-auto-send { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.hor-modes { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 8px 0; }
|
||||
.hor-modes .hor-choice { flex-direction: row; white-space: nowrap; }
|
||||
.hor-modes .hor-choice input { width: auto; min-height: 0; margin: 0; }
|
||||
|
||||
Reference in new issue
Block a user