Show attendance and weather before live ticker kickoff (by Codex)

This commit is contained in:
Codex committed 2026-10-27 10:59:45 +01:00
1 parent ef25407484
commit b845bbfcbc
10 files changed
+144 -14

No files matched your search

+22
View File
@@ -196,6 +196,14 @@ Json make_demo_live(const Catalog &world, const Json &state, uint64_t revision)
}
const auto identity = Json{{"world", world.manifest().value("id", "")}, {"date", state.at("date")},
{"role", role}, {"surface", surface}, {"matches", matches}};
// Explicit presentation examples, separate from the authored event tape.
// Add after identity construction so existing fixture/match/event IDs stay
// compatible. Real providers supply their own recorded conditions.
for (size_t i = 0; i < matches.size(); ++i) {
matches[i]["attendance"] = indoor ? 2200 + int(i) * 350 : 26400 + int(i) * 4750;
matches[i]["weather"] = indoor ? Json() : Json{{"temperature", 18 + int(i)},
{"rain", std::array<int,4>{0,2,4,1}[i]}};
}
return {{"ok", true}, {"schema", "openbmh-live-fixture@1"}, {"source", "ui-demo-fixture"},
{"fixture_id", "ui-live:" + fingerprint(identity.dump())}, {"source_revision", revision},
{"world", world.manifest().value("id", "")}, {"date", state.at("date")},
@@ -243,6 +251,20 @@ bool valid_live_fixture(const Json &v) {
}
}
for (const auto &match : v.at("matches")) {
if (match.contains("attendance") && !match.at("attendance").is_null() &&
!uint_value(match.at("attendance"), INT32_MAX)) return false;
if (match.contains("weather") && !match.at("weather").is_null()) {
const auto &weather = match.at("weather");
if (!weather.is_object()) return false;
if (weather.contains("temperature") && !weather.at("temperature").is_null() &&
(!weather.at("temperature").is_number_integer() ||
(weather.at("temperature").is_number_unsigned() &&
weather.at("temperature").get<uint64_t>() > 127) ||
weather.at("temperature").get<int64_t>() < -128 ||
weather.at("temperature").get<int64_t>() > 127)) return false;
if (weather.contains("rain") && !weather.at("rain").is_null() &&
!uint_value(weather.at("rain"), 7)) return false;
}
if (!string_value(match.at("id")) || !match_ids.insert(match.at("id")).second ||
!match.at("owners").is_array() || match.at("owners").empty()) return false;
for (auto side : {"home", "away"})
+16 -5
View File
@@ -121,8 +121,9 @@ Json report(const Json &fixture, const Json &match, int minute) {
// no player actor, assist or exact playing-time/ratings, so none is inferred.
out["events"] = match_events(frame->at("events"), match.at("id"));
out["timeline"] = match_events(frames.back().at("events"), match.at("id"));
out["attendance"] = nullptr;
out["attendance_reason"] = "not_recorded";
out["attendance"] = match.value("attendance", Json());
out["attendance_reason"] = out["attendance"].is_null() ? "not_recorded" : "recorded";
out["weather"] = match.value("weather", Json());
out["actor"] = nullptr; out["assists"] = nullptr; out["ratings"] = nullptr;
out["playing_minutes"] = nullptr;
return out;
@@ -145,14 +146,19 @@ Json make_demo_post_match(const Json &fixture, size_t completed_sequence, const
out["matches"] = Json::array(); out["tables"] = Json::array();
Json totals = {{"games", fixture.at("matches").size()}, {"goals", 0},
{"yellow", 0}, {"red", 0}, {"chances", 0},
{"attendance", nullptr}, {"attendance_reason", "not_recorded"},
{"attendance", int64_t(0)}, {"attendance_reason", "recorded"},
{"scope", "recorded_human_matches"}};
bool crowds_known = true;
for (const auto &match : fixture.at("matches")) {
const auto &final = match_snapshot(last, match.at("id"));
auto row = match;
row["final"] = final;
row["events"] = match_events(last.at("events"), match.at("id"));
row["attendance"] = nullptr; row["attendance_reason"] = "not_recorded";
row["attendance"] = match.value("attendance", Json());
row["attendance_reason"] = row["attendance"].is_null() ? "not_recorded" : "recorded";
row["weather"] = match.value("weather", Json());
if (row["attendance"].is_null()) crowds_known = false;
else totals["attendance"] = totals.at("attendance").get<int64_t>() + row.at("attendance").get<int64_t>();
out["matches"].push_back(std::move(row));
for (auto key : {"yellow", "red", "chances"})
totals[key] = totals.at(key).get<int>() + final.at(key)[0].get<int>() + final.at(key)[1].get<int>();
@@ -170,9 +176,14 @@ Json make_demo_post_match(const Json &fixture, size_t completed_sequence, const
{"wins", nullptr}, {"draws", nullptr}, {"losses", nullptr}});
}
}
if (!crowds_known) {
totals["attendance"] = nullptr;
totals["attendance_reason"] = "not_recorded";
}
out["overview"] = std::move(totals);
out["eleven"] = {{"available", false}, {"reason", "not_recorded"}, {"rows", Json::array()}};
out["unknown_fields"] = Json::array({"attendance", "actor", "assists", "ratings", "playing_minutes", "eleven", "wins", "draws", "losses"});
out["unknown_fields"] = Json::array({"actor", "assists", "ratings", "playing_minutes", "eleven", "wins", "draws", "losses"});
if (!crowds_known) out["unknown_fields"].push_back("attendance");
if (const auto *error = attach_records(out, fixture, records)) return failure(error);
return out;
} catch (const std::exception &) { return failure("invalid_post_match_fixture"); }
+33
View File
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "modern/ui/catalog.hpp"
#include <array>
namespace bmh::modern_ui {
// The rain code selects the original eight weather pictograms. It is not a
// precipitation percentage or a temperature-based forecast.
inline std::string live_weather_label(int code) {
static constexpr std::array<const char *, 8> labels{
"sonnig", "heiter", "wolkig", "bedeckt", "Regen", "Regen", "Schnee", "Schnee"};
return code >= 0 && code < int(labels.size()) ? labels[size_t(code)] : "Wetter —";
}
inline std::string live_attendance_text(const Json &match) {
if (!match.contains("attendance") || !match.at("attendance").is_number_integer())
return "Zuschauer —";
const auto count = match.at("attendance").get<int64_t>();
if (count < 0) return "Zuschauer —";
auto text = std::to_string(count);
for (int at = int(text.size()) - 3; at > 0; at -= 3) text.insert(size_t(at), ".");
return text + " Zuschauer";
}
inline std::string live_match_info_text(const Json &match, bool indoor) {
auto text = live_attendance_text(match);
if (indoor) return text + " · Halle";
const auto weather = match.value("weather", Json());
if (!weather.is_object()) return text + " · Wetter —";
if (weather.contains("temperature") && weather.at("temperature").is_number_integer())
text += " · " + std::to_string(weather.at("temperature").get<int>()) + " °C";
const auto rain = weather.value("rain", Json());
return text + " · " + (rain.is_number_integer() ? live_weather_label(rain.get<int>()) : "Wetter —");
}
} // namespace bmh::modern_ui
+1 -1
View File
@@ -162,7 +162,7 @@ std::string App::render_live() {
if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue;
std::string names;
for (const auto &id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == id) { if (!names.empty()) names += " · "; names += person.at("name").get<std::string>(); }
out += "<button data-action=\"live-match\" class=\"live-game " + std::string(match.at("id") == live_selected_match_ ? "active" : "") + "\" data-live-match=\"" + esc(match.at("id").get<std::string>()) + "\" data-id=\"" + esc(match.at("id").get<std::string>()) + "\">" + live_text(names, "live-owners") + scoreline(match) + live_text(std::to_string(minute) + "′ · " + (match.at("owners").size() > 1 ? "Zwei menschliche Manager" : "Eine menschliche Mannschaft"), "live-card-caption") + "</button>";
out += "<button data-action=\"live-match\" class=\"live-game " + std::string(match.at("id") == live_selected_match_ ? "active" : "") + "\" data-live-match=\"" + esc(match.at("id").get<std::string>()) + "\" data-id=\"" + esc(match.at("id").get<std::string>()) + "\">" + live_text(names, "live-owners") + scoreline(match) + live_text(std::to_string(minute) + "′ · " + (match.at("owners").size() > 1 ? "Zwei menschliche Manager" : "Eine menschliche Mannschaft"), "live-card-caption") + live_text(live_match_info_text(match, fixture.at("surface") == "indoor"), "live-match-info") + "</button>";
}
out += "</div></section><section class=\"live-panel live-ticker\"><header class=\"live-panel-heading\"><h2>" + live_text("Gemeinsamer Live-Ticker") + "</h2>" + live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small") + "</header><nav class=\"live-filters\">";
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 4>{{{"all", "Alles"}, {"highlights", "Highlights"}, {"goal", "Tore"}, {"yellow", "Karten"}}}) out += btn("live-filter", label, live_filter_ == id ? "selected" : "", "id=\"live-filter-" + std::string(id) + "\" data-id=\"" + id + "\"");
+11 -4
View File
@@ -175,8 +175,8 @@ std::string App::postmatch_report_markup(const Json &report) {
"<strong>" + live_text(report.at("away").at("name")) +
"</strong></div></header>";
out += "<p class=\"postmatch-report-meta\">" +
live_text("Spielort und Zuschauer nicht aufgezeichnet · "
"Spielerzuordnung nicht aufgezeichnet") +
live_text(live_match_info_text(report, postmatch_data_.at("surface") == "indoor") +
" · Spielort und Spielerzuordnung nicht aufgezeichnet") +
"</p><div id=\"postmatch-events\" class=\"postmatch-event-columns\">" +
postmatch_events(report, "home") + postmatch_events(report, "away") +
"</div><section class=\"postmatch-timeline\"><div "
@@ -347,6 +347,11 @@ std::string App::render_postmatch() {
} else if (postmatch_tab_ == "overview") {
auto total = postmatch_data_.at("overview");
total["games"] = matches.size();
total["attendance"] = int64_t(0);
for (const auto &m : matches) {
if (m.at("attendance").is_null()) { total["attendance"] = nullptr; break; }
total["attendance"] = total.at("attendance").get<int64_t>() + m.at("attendance").get<int64_t>();
}
for (const auto *key : {"goals", "yellow", "red"})
total[key] = 0;
for (const auto &m : matches)
@@ -375,7 +380,9 @@ std::string App::render_postmatch() {
: "—") +
" Tore pro Partie") +
"</p><p class=\"postmatch-scope-note\">" +
live_text("Zuschauer nicht aufgezeichnet · keine Ligagesamtwertung") +
live_text(total.at("attendance").is_null()
? "Zuschauer nicht aufgezeichnet · keine Ligagesamtwertung"
: "Aufgezeichnete menschliche Partien · keine Ligagesamtwertung") +
"</p></section>";
} else {
const Json *table = nullptr;
@@ -471,7 +478,7 @@ std::string App::render_postmatch() {
detail += "<div><dt>" + live_text(label) + "</dt><dd>" +
live_text(postmatch_count(final.at(key)[side])) +
"</dd></div>";
detail += "<div><dt>Zuschauer</dt><dd>—</dd></div></dl>";
detail += "<div><dt>Zuschauer</dt><dd>" + live_text(postmatch_count(match->at("attendance"))) + "</dd></div></dl>";
} else
detail += "<p>" +
live_text("Keine Partie dieses Teams in der gehaltenen "
+1
View File
@@ -5,6 +5,7 @@
#include "launch/rml_path.hpp"
#include "launch/rml_video.hpp"
#include "modern/ui/controls.hpp"
#include "modern/ui/live_match_info.hpp"
#include "modern/ui/script_locator.hpp"
#include "modern/ui/select_menu.hpp"
#include "modern/ui/demo_calendar.hpp"