Render Gold post-match pages from held read-only review data (by Codex)

This commit is contained in:
Codex authored and Codex committed 2026-10-27 09:12:36 +01:00
1 parent 86f248bbd5
commit 3f1a44b320
13 files changed
+1392 -13

No files matched your search

+501
View File
@@ -0,0 +1,501 @@
// SPDX-License-Identifier: GPL-3.0-only
namespace {
std::string postmatch_label(const std::string &tab) {
if (tab == "results")
return "Ergebnisse";
if (tab == "report")
return "Spielbericht";
if (tab == "eleven")
return "Elf des Tages";
if (tab == "overview")
return "Übersicht";
return "Tabelle";
}
std::string postmatch_count(const Json &v) {
return v.is_number_integer() ? number(v.get<int64_t>()) : "—";
}
std::string postmatch_kind(const std::string &kind) {
if (kind == "goal")
return "Tor";
if (kind == "yellow")
return "Gelbe Karte";
if (kind == "red")
return "Rote Karte";
if (kind == "injury")
return "Behandlung";
if (kind == "attack")
return "Angriff";
if (kind == "chance" || kind == "save")
return "Torchance";
if (kind == "kickoff")
return "Anpfiff";
if (kind == "interval")
return "Halbzeit";
if (kind == "restart")
return "Wiederanpfiff";
if (kind == "fulltime")
return "Abpfiff";
return "Ereignis";
}
} // namespace
std::string App::postmatch_icon(const std::string &kind, double size) {
const std::string color = kind == "yellow" ? "#dfbd66"
: kind == "red" ? "#e5938b"
: theme_ == "silver" ? "#42627d"
: theme_ == "matchday" ? "#d6b9bf"
: "#b4cfde";
const std::string path =
kind == "goal"
? "<circle cx='12' cy='12' r='9'/><path d='m12 7 5 4-2 6H9l-2-6z'/>"
: kind == "yellow" || kind == "red"
? "<rect x='6' y='3' width='12' height='18' rx='2'/>"
: kind == "crowd"
? "<circle cx='12' cy='7' r='3'/><path d='M6 21v-3a6 6 0 0 1 12 "
"0v3M3 10a2 2 0 0 0-2 2v7M21 10a2 2 0 0 1 2 2v7'/>"
: kind == "injury" ? "<path d='M9 3h6v6h6v6h-6v6H9v-6H3V9h6z'/>"
: "<circle cx='12' cy='12' r='8'/><path d='M12 1v6M12 "
"17v6M1 12h6M17 12h6'/>";
return picture(
renderer_.diagram("postmatch-icon-" + kind,
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 "
"24 24'><g fill='none' stroke='" +
color +
"' stroke-width='1.5' stroke-linecap='round' "
"stroke-linejoin='round'>" +
path + "</g></svg>",
int(size * 2)),
size, size);
}
std::string App::postmatch_team(const Json &team, bool home, double size) {
const auto name = live_text(team.value("name", "—"), "postmatch-team-name");
const auto badge = live_badge(team, size);
return "<span class=\"postmatch-team " + std::string(home ? "home" : "away") +
"\">" + (home ? name + badge : badge + name) + "</span>";
}
Json App::postmatch_groups() const {
Json groups = Json::array();
if (!postmatch_data_.value("ok", false))
return groups;
for (const auto &m : postmatch_data_.at("matches")) {
const auto *club = live_world_
? live_world_->find("clubs", m.at("home").at("id"))
: nullptr;
const std::string league = club ? club->value("competition", "") : "";
const auto *competition =
live_world_ ? live_world_->find("competitions", league) : nullptr;
const std::string country =
competition ? competition->value("nation", "") : "";
const auto *nation =
live_world_ ? live_world_->find("nations", country) : nullptr;
const std::string key = league.empty() ? "recording" : league;
auto group = std::find_if(groups.begin(), groups.end(),
[&](const auto &g) { return g.at("id") == key; });
if (group == groups.end()) {
groups.push_back(
{{"id", key},
{"name", competition ? live_world_->name(*competition)
: m.at("competition").get<std::string>()},
{"country", country.empty() ? "recording" : country},
{"country_name",
nation ? live_world_->name(*nation) : "Aufzeichnung"},
{"match_ids", Json::array()}});
group = groups.end() - 1;
}
(*group)["match_ids"].push_back(m.at("id"));
}
return groups;
}
Json App::postmatch_matches() const {
if (postmatch_data_.at("role") != "club" ||
postmatch_data_.at("surface") != "outdoor")
return postmatch_data_.at("matches");
const auto groups = postmatch_groups();
Json rows = Json::array();
for (const auto &group : groups)
if (group.at("id") == postmatch_league_)
for (const auto &m : postmatch_data_.at("matches"))
if (std::find(group.at("match_ids").begin(),
group.at("match_ids").end(),
m.at("id")) != group.at("match_ids").end())
rows.push_back(m);
return rows;
}
Json App::postmatch_report() const {
if (!live_.available() || !postmatch_data_.value("ok", false))
return Json();
return query_demo_post_match(
live_.fixture(),
{{"kind", "report"},
{"completed_sequence", postmatch_data_.at("completed_sequence")},
{"fixture_id", postmatch_data_.at("fixture_id")},
{"revision", postmatch_data_.at("source_revision")},
{"match_id", postmatch_match_},
{"minute", postmatch_minute_}});
}
std::string App::postmatch_events(const Json &report, const std::string &side) {
std::string out =
"<ol class=\"postmatch-event-column\" aria-label=\"Ereignisse " +
esc(report.at(side).at("name").get<std::string>()) + "\">";
size_t index = 0, shown = 0;
for (const auto &e : report.at("timeline")) {
const auto n = index++;
if (e.at("side") != side || e.at("sequence") > report.at("sequence"))
continue;
out += "<li>" +
btn("postmatch-event",
live_text(std::to_string(e.at("minute").get<int>()) + "′",
"postmatch-event-time") +
postmatch_icon(e.at("kind"), 42) +
"<span class=\"postmatch-event-copy\"><strong>" +
live_text(e.at("headline")) + "</strong><span>" +
esc(e.at("body").get<std::string>()) + "</span></span>",
"postmatch-event",
"id=\"postmatch-event-" + std::to_string(n) + "\" data-id=\"" +
esc(e.at("id").get<std::string>()) + "\"") +
"</li>";
++shown;
}
if (!shown)
out += "<li class=\"postmatch-no-events\">" +
live_text("Noch keine aufgezeichneten Ereignisse") + "</li>";
return out + "</ol>";
}
std::string App::postmatch_report_markup(const Json &report) {
const auto score = report.at("score");
std::string out = "<section class=\"postmatch-report\"><header "
"class=\"postmatch-report-teams\"><div>" +
live_badge(report.at("home"), 120) + "<strong>" +
live_text(report.at("home").at("name")) +
"</strong></div><div id=\"postmatch-score\" "
"class=\"postmatch-report-score\">" +
live_text(std::to_string(score[0].get<int>())) +
live_text(":", "separator") +
live_text(std::to_string(score[1].get<int>())) +
"</div><div>" + live_badge(report.at("away"), 120) +
"<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") +
"</p><div id=\"postmatch-events\" class=\"postmatch-event-columns\">" +
postmatch_events(report, "home") + postmatch_events(report, "away") +
"</div><section class=\"postmatch-timeline\"><div "
"class=\"postmatch-timeline-teams\">" +
live_text(report.at("home").at("name")) +
live_text(report.at("away").at("name")) +
"</div><div class=\"postmatch-timeline-tracks\">";
for (const auto *side : {"home", "away"}) {
out += "<div class=\"postmatch-track\" aria-label=\"Zeitleiste " +
esc(report.at(side).at("name").get<std::string>()) + "\">";
size_t index = 0;
for (const auto &e : report.at("timeline")) {
const auto n = index++;
if (e.at("side") != side)
continue;
const auto minute = e.at("minute").get<int>();
out +=
btn("postmatch-event", postmatch_icon(e.at("kind"), 34),
"postmatch-marker " +
std::string(e.at("sequence") <= report.at("sequence")
? "is-visible"
: ""),
"id=\"postmatch-marker-" + std::to_string(n) + "\" data-id=\"" +
esc(e.at("id").get<std::string>()) + "\" style=\"left:" +
scalar(100.0 * minute /
postmatch_data_.at("duration").get<int>()) +
"%;\" aria-label=\"" + std::to_string(minute) +
" Minute: " + esc(postmatch_kind(e.at("kind"))) + "\"");
}
out += "</div>";
}
out += "<div class=\"postmatch-ticks\">";
for (int i = 0; i < 7; ++i)
out +=
live_text(std::to_string(int(std::lround(
i * postmatch_data_.at("duration").get<int>() / 6.0))) +
"′");
out +=
"</div></div></section><div class=\"postmatch-seek\">" +
btn("postmatch-play",
postmatch_playing_ ? "Pause" : "Rückblick abspielen", {},
"id=\"postmatch-play\" aria-pressed=\"" +
std::string(postmatch_playing_ ? "true" : "false") + "\"") +
"<input id=\"postmatch-minute\" type=\"range\" min=\"0\" max=\"" +
std::to_string(postmatch_data_.at("duration").get<int>()) +
"\" step=\"1\" value=\"" + std::to_string(postmatch_minute_) +
"\" aria-label=\"Berichtsminute\"/><span id=\"postmatch-minute-label\">" +
std::to_string(postmatch_minute_) +
"′</span></div><p id=\"postmatch-recorded-note\" "
"class=\"postmatch-recorded-note\">" +
live_text("Aufgezeichneter Stand: " +
std::to_string(report.at("recorded_minute").get<int>()) +
"′ · keine Zwischenberechnung") +
"</p>";
const auto matches = postmatch_matches();
size_t at = 0;
for (size_t i = 0; i < matches.size(); ++i)
if (matches[i].at("id") == postmatch_match_)
at = i;
out += "<nav class=\"postmatch-fixture-nav\">" +
btn("postmatch-fixture-prev", "‹ Voriges Spiel", {},
"id=\"postmatch-fixture-prev\" " +
std::string(at == 0 ? "disabled" : "")) +
live_text(report.at("home").at("name").get<std::string>() + " – " +
report.at("away").at("name").get<std::string>()) +
btn("postmatch-fixture-next", "Nächstes Spiel ›", {},
"id=\"postmatch-fixture-next\" " +
std::string(at + 1 == matches.size() ? "disabled" : "")) +
"</nav></section>";
return out;
}
std::string App::render_postmatch() {
if (!postmatch_data_.value("ok", false))
return "";
for (const auto *id : {"postmatch-results", "postmatch-events",
"postmatch-eleven-list", "postmatch-table"})
if (auto *node = element(id))
postmatch_scrolls_[postmatch_rendered_scope_ + "|" + id] =
node->GetScrollTop();
postmatch_restore_scroll_ = true;
const auto &tabs = postmatch_data_.at("tabs");
const auto matches = postmatch_matches();
postmatch_rendered_scope_ = postmatch_tab_ + "|" + postmatch_match_;
const auto selected = live_match_by_id(matches, postmatch_match_);
std::set<std::string> own;
for (const auto &owner : postmatch_data_.at("owners"))
own.insert(owner.at("team").at("id"));
std::string body =
"<section id=\"postmatch-underlay\" class=\"postmatch\"><header "
"class=\"postmatch-heading\"><div><p>" +
live_text(selected.at("competition").get<std::string>() + " · " +
postmatch_data_.at("date").get<std::string>()) +
"</p><h2 id=\"postmatch-heading\" tabindex=\"-1\">" +
live_text(postmatch_label(postmatch_tab_)) + "</h2></div>";
if (postmatch_data_.at("role") == "club" &&
postmatch_data_.at("surface") == "outdoor") {
std::vector<std::pair<std::string, std::string>> countries, leagues;
for (const auto &g : postmatch_groups()) {
const auto country = g.at("country").get<std::string>();
if (std::none_of(countries.begin(), countries.end(),
[&](const auto &c) { return c.first == country; }))
countries.emplace_back(country, g.at("country_name"));
if (country == postmatch_country_)
leagues.emplace_back(g.at("id"), g.at("name"));
}
body += "<nav class=\"postmatch-pickers\" aria-label=\"Aufgezeichnete "
"Ligagruppe\">" +
select("postmatch-country", countries, postmatch_country_) +
select("postmatch-league", leagues, postmatch_league_) + "</nav>";
}
body += "</header><nav class=\"postmatch-tabs\" role=\"tablist\">";
size_t position = 0;
for (size_t i = 0; i < tabs.size(); ++i) {
const auto tab = tabs[i].get<std::string>();
if (tab == postmatch_tab_)
position = i;
body += btn("postmatch-tab", postmatch_label(tab),
tab == postmatch_tab_ ? "selected" : "",
"id=\"postmatch-tab-" + tab + "\" data-id=\"" + tab +
"\" role=\"tab\" aria-selected=\"" +
std::string(tab == postmatch_tab_ ? "true" : "false") +
"\" tabindex=\"" +
std::string(tab == postmatch_tab_ ? "0" : "-1") + "\"");
}
body += "</nav><div id=\"postmatch-panel\" class=\"postmatch-panel\" "
"role=\"tabpanel\" aria-labelledby=\"postmatch-tab-" +
postmatch_tab_ + "\">";
if (postmatch_tab_ == "results") {
body += "<div class=\"postmatch-results-head\">" +
live_text("Heim", "home") + live_text("Ergebnis", "score") +
live_text("Auswärts", "away") +
"</div><div id=\"postmatch-results\" class=\"postmatch-results\">";
for (size_t i = 0; i < matches.size(); ++i) {
const auto &m = matches[i];
const bool owned = own.contains(m.at("home").at("id")) ||
own.contains(m.at("away").at("id"));
body += btn(
"postmatch-fixture",
postmatch_team(m.at("home"), true) +
"<strong class=\"postmatch-result-score\">" +
live_text(
std::to_string(m.at("final").at("score")[0].get<int>())) +
live_text(":", "separator") +
live_text(
std::to_string(m.at("final").at("score")[1].get<int>())) +
"</strong>" + postmatch_team(m.at("away"), false),
"postmatch-result-row " + std::string(owned ? "postmatch-own" : ""),
"id=\"postmatch-result-" + std::to_string(i) + "\" data-id=\"" +
esc(m.at("id").get<std::string>()) + "\"");
}
body += "</div><p class=\"postmatch-scope-note\">" +
live_text("Vorgegebene Aufzeichnung der menschlichen Partien · "
"kein vollständiger Ligaspieltag") +
"</p>";
} else if (postmatch_tab_ == "report")
body += postmatch_report_markup(postmatch_report());
else if (postmatch_tab_ == "eleven") {
const auto color = theme_ == "silver" ? "#42627d"
: theme_ == "matchday" ? "#d2b8be"
: "#abcbbf";
const auto pitch = picture(
renderer_.diagram("postmatch-pitch", postmatch_pitch_svg(color), 1110),
740, 1110);
body += postmatch_eleven_markup(
postmatch_data_.at("eleven"),
[&](const Json &team, double size) { return live_badge(team, size); },
pitch);
} else if (postmatch_tab_ == "overview") {
auto total = postmatch_data_.at("overview");
total["games"] = matches.size();
for (const auto *key : {"goals", "yellow", "red"})
total[key] = 0;
for (const auto &m : matches)
for (const auto *key : {"goals", "yellow", "red"}) {
const auto &pair =
m.at("final").at(std::string(key) == "goals" ? "score" : key);
total[key] =
total.at(key).get<int>() + pair[0].get<int>() + pair[1].get<int>();
}
body += "<section class=\"postmatch-overview\"><div "
"class=\"postmatch-total-grid\">";
for (const auto &[key, icon, label] :
std::array<std::tuple<const char *, const char *, const char *>, 4>{
{{"yellow", "yellow", "Gelbe Karten"},
{"red", "red", "Platzverweise"},
{"attendance", "crowd", "Zuschauer"},
{"goals", "goal", "Tore"}}})
body += "<article class=\"postmatch-total\">" + postmatch_icon(icon, 70) +
"<strong>" + live_text(postmatch_count(total.at(key))) +
"</strong>" + live_text(label) + "</article>";
const int games = total.at("games");
body +=
"</div><p>" +
live_text(std::to_string(games) + " aufgezeichnete Partien · " +
(games ? scalar(double(total.at("goals").get<int>()) / games)
: "—") +
" Tore pro Partie") +
"</p><p class=\"postmatch-scope-note\">" +
live_text("Zuschauer nicht aufgezeichnet · keine Ligagesamtwertung") +
"</p></section>";
} else {
const Json *table = nullptr;
for (const auto &t : postmatch_data_.at("tables"))
if (std::find(t.at("match_ids").begin(), t.at("match_ids").end(),
Json(postmatch_match_)) != t.at("match_ids").end()) {
table = &t;
break;
}
body +=
"<p class=\"postmatch-table-note\">" +
live_text("Vorgegebener POC-Tabellenstand · Siege, Unentschieden und "
"Niederlagen nicht aufgezeichnet") +
"</p><div id=\"postmatch-table\" class=\"postmatch-table-scroll\"><div "
"class=\"postmatch-table-row heading\">";
for (const auto *label :
{"Pl.", "Verein", "Sp.", "S", "U", "N", "Tore", "Diff.", "Pkt."})
body += live_text(label);
body += "</div>";
if (table)
for (const auto &r : table->at("rows")) {
const int diff = r.at("gf").get<int>() - r.at("ga").get<int>();
body +=
"<div class=\"postmatch-table-row " +
std::string(own.contains(r.at("team").at("id")) ? "postmatch-own"
: "") +
"\">" + live_text(postmatch_count(r.at("position"))) +
postmatch_team(r.at("team"), false, 43) +
live_text(postmatch_count(r.at("played"))) + live_text("—") +
live_text("—") + live_text("—") +
live_text(postmatch_count(r.at("gf")) + ":" +
postmatch_count(r.at("ga"))) +
live_text((diff > 0 ? "+" : "") + std::to_string(diff)) +
live_text(postmatch_count(r.at("points"))) + "</div>";
}
if (!table)
body +=
"<p>" +
live_text("Für diese Partie ist kein Tabellenstand aufgezeichnet.") +
"</p>";
body += "</div>";
}
body +=
"</div><footer class=\"postmatch-actions\">" +
btn("postmatch-prev", "‹ Zurück", {},
"id=\"postmatch-prev\" " +
std::string(position == 0 ? "disabled" : "")) +
live_text(std::to_string(position + 1) + " / " +
std::to_string(tabs.size()) + " · UI-Aufzeichnung",
"postmatch-status") +
btn("postmatch-ticker", "<span id=\"live-review-back\">Zum Ticker</span>",
{}, "id=\"postmatch-ticker\"") +
btn("postmatch-next",
position + 1 == tabs.size() ? "Zum Desktop" : "Weiter ›", {},
"id=\"postmatch-next\"") +
"</footer></section>";
if (!postmatch_dialog_.empty()) {
Json team;
const Json *nominee = nullptr, *match = nullptr;
for (const auto &row : postmatch_data_.at("eleven").at("rows")) {
if (row.at("team").at("id") == postmatch_detail_team_)
team = row.at("team");
if (row.at("player").at("id") == postmatch_detail_player_)
nominee = &row;
}
for (const auto &m : postmatch_data_.at("matches"))
if (m.at("home").at("id") == postmatch_detail_team_ ||
m.at("away").at("id") == postmatch_detail_team_)
match = &m;
std::string detail;
if (nominee)
detail =
postmatch_nominee_detail(*nominee, [&](const Json &t, double size) {
return live_badge(t, size);
});
else if (team.is_object())
detail = "<header class=\"postmatch-player-summary\">" +
live_badge(team, 150) + "</header>";
if (match) {
const bool home = match->at("home").at("id") == postmatch_detail_team_;
const auto &final = match->at("final");
const size_t side = home ? 0 : 1;
detail += "<p class=\"postmatch-detail-result\">" +
live_text(match->at("home").at("name").get<std::string>() +
" · " + live_score_text(final.at("score")) + " · " +
match->at("away").at("name").get<std::string>()) +
"</p><dl class=\"postmatch-player-facts\">";
for (const auto &[key, label] :
std::array<std::pair<const char *, const char *>, 3>{
{{"yellow", "Gelbe Karten"},
{"red", "Platzverweise"},
{"score", "Tore"}}})
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>";
} else
detail += "<p>" +
live_text("Keine Partie dieses Teams in der gehaltenen "
"Aufnahme enthalten.") +
"</p>";
body +=
"<div id=\"postmatch-dialog-layer\" "
"class=\"entry-dialog-layer\"><section class=\"entry-dialog "
"postmatch-dialog\" role=\"dialog\" aria-modal=\"true\"><h2>" +
live_text(nominee ? nominee->at("player").at("name").get<std::string>()
: team.value("name", "Spieltagsinfo")) +
"</h2>" + detail + "<footer>" +
btn("postmatch-detail-close", "Schließen", {},
"id=\"postmatch-detail-close\"") +
btn("postmatch-detail-report", "Spielbericht", {},
"id=\"postmatch-detail-report\" " +
std::string(match ? "" : "disabled")) +
"</footer></section></div>";
}
return render_desktop() +
"<div class=\"fill\" style=\"z-index:100;\"><div class=\"window "
"postmatch-window\"><div class=\"titlebar\">" +
btn("postmatch-desktop", "<span>×</span>", "close",
"id=\"postmatch-close\" aria-label=\"Auswertung schließen\"") +
"<h1>Nach dem Spiel</h1></div><div class=\"content\">" + body +
"</div></div></div>";
}