// 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()) : "—"; } 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) { // the report uses the pictures of the match sheet, so they read on every skin const bool whistle = kind == "kickoff" || kind == "interval" || kind == "fulltime" || kind == "restart"; return live_icon(whistle ? "time" : kind, size); } // The pictures of the day's totals: drawn large and filled, in the sheet's colours. std::string App::postmatch_art(const std::string &kind, double size) { const bool dark = theme_ != "silver" && theme_ != "matchday"; const std::string ink = dark ? "#f0ece2" : "#2a211a", paper = dark ? "#2a2d34" : "#fffdf6"; const auto card = [&](const char *fill, const char *turn) { return std::string(""; }; std::string g; if (kind == "yellow") g = card("#e9c53a", "-12"); else if (kind == "red") g = card("#c8372d", "12"); else if (kind == "crowd") { const auto person = [&](double x, double y, double k, const char *fill) { return ""; }; g = person(26, 46, .8, "#7a8a5e") + person(74, 46, .8, "#7a8a5e") + person(50, 52, 1.05, "#c67139"); } else { g = ""; } return picture(renderer_.diagram("postmatch-art-" + kind + (dark ? "-d" : "-l"), "" + g + "", 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 "" + (home ? name + badge : badge + name) + ""; } 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()}, {"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 = "
    ()) + "\">"; 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 += "
  1. " + btn("postmatch-event", live_text(std::to_string(e.at("minute").get()) + "′", "postmatch-event-time") + postmatch_icon(e.at("kind"), 42) + "" + live_text(e.at("headline")) + "" + esc(e.at("body").get()) + "", "postmatch-event", "id=\"postmatch-event-" + std::to_string(n) + "\" data-id=\"" + esc(e.at("id").get()) + "\"") + "
  2. "; ++shown; } if (!shown) out += "
  3. " + live_text("Noch keine Ereignisse") + "
  4. "; return out + "
"; } std::string App::postmatch_report_markup(const Json &report) { const auto score = report.at("score"); std::string out = "
" + live_badge(report.at("home"), 120) + "" + live_text(report.at("home").at("name")) + "
" + live_text(std::to_string(score[0].get())) + live_text(":", "separator") + live_text(std::to_string(score[1].get())) + "
" + live_badge(report.at("away"), 120) + "" + live_text(report.at("away").at("name")) + "
"; out += "

" + live_text(live_match_info_text(report, postmatch_data_.at("surface") == "indoor")) + "

" + postmatch_events(report, "home") + postmatch_events(report, "away") + "
" + live_text(report.at("home").at("name")) + live_text(report.at("away").at("name")) + "
"; for (const auto *side : {"home", "away"}) { out += "
()) + "\">"; 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(); 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()) + "\" style=\"left:" + scalar(100.0 * minute / postmatch_data_.at("duration").get()) + "%;\" aria-label=\"" + std::to_string(minute) + " Minute: " + esc(postmatch_kind(e.at("kind"))) + "\""); } out += "
"; } out += "
"; for (int i = 0; i < 7; ++i) out += live_text(std::to_string(int(std::lround( i * postmatch_data_.at("duration").get() / 6.0))) + "′"); out += "
" + btn("postmatch-play", postmatch_playing_ ? "Pause" : "Rückblick abspielen", {}, "id=\"postmatch-play\" aria-pressed=\"" + std::string(postmatch_playing_ ? "true" : "false") + "\"") + "()) + "\" step=\"1\" value=\"" + std::to_string(postmatch_minute_) + "\" aria-label=\"Berichtsminute\"/>" + std::to_string(postmatch_minute_) + "′

" + live_text("Stand nach " + std::to_string(report.at("recorded_minute").get()) + "′") + "

"; 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 += "
"; 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 own; for (const auto &owner : postmatch_data_.at("owners")) own.insert(owner.at("team").at("id")); size_t position = 0; for (size_t i = 0; i < tabs.size(); ++i) if (tabs[i].get() == postmatch_tab_) position = i; std::string steps; for (size_t i = 0; i < tabs.size(); ++i) { const auto tab = tabs[i].get(); steps += btn("postmatch-tab", std::to_string(i + 1) + ". " + postmatch_label(tab), tab == postmatch_tab_ ? "selected" : i < position ? "done" : "", "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") + "\""); } std::string pickers; if (postmatch_data_.at("role") == "club" && postmatch_data_.at("surface") == "outdoor") { std::vector> countries, leagues; for (const auto &g : postmatch_groups()) { const auto country = g.at("country").get(); 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")); } pickers = ""; } std::string body = "
" + esc(pg_upper("Auswertung · Schritt " + std::to_string(position + 1) + " von " + std::to_string(tabs.size()))) + "

" + live_text(postmatch_label(postmatch_tab_)) + "

" + esc(selected.at("competition").get() + " · " + ui_long_date(postmatch_data_.at("date").get())) + "" + pickers + "
"; body += "
"; if (postmatch_tab_ == "results") { // the fewer matches, the larger each is shown: one fills the note, a full match day is a list const size_t shown = matches.size(); const std::string scale = shown <= 1 ? "one" : shown == 2 ? "two" : shown <= 4 ? "few" : "many"; const double badge = shown <= 1 ? 300 : shown == 2 ? 210 : shown <= 4 ? 130 : 68; const bool hall = postmatch_data_.at("surface") == "indoor" || live_indoor(); body += std::string(scale == "many" ? "
" + live_text("Heim", "home") + live_text("Ergebnis", "score") + live_text("Auswärts", "away") + "
" : std::string()) + "
"; 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, badge) + "" + live_text( std::to_string(m.at("final").at("score")[0].get())) + live_text(":", "separator") + live_text( std::to_string(m.at("final").at("score")[1].get())) + "" + postmatch_team(m.at("away"), false, badge), "postmatch-result-row " + std::string(owned ? "postmatch-own" : ""), "id=\"postmatch-result-" + std::to_string(i) + "\" data-id=\"" + esc(m.at("id").get()) + "\""); if (shown <= 2) body += "

" + esc(m.at("competition").get() + " · " + live_match_info_text(m, hall)) + "

"; } body += "

" + live_text(postmatch_data_.at("source") == "engine-recording" ? "Partien mit eigener Beteiligung · alle Ergebnisse stehen unter Ligaspiele und Übrige Spiele" : "Vorgegebene Aufzeichnung der menschlichen Partien · " "kein vollständiger Ligaspieltag") + "

"; } 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(); 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() + m.at("attendance").get(); } 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() + pair[0].get() + pair[1].get(); } body += "
"; for (const auto &[key, icon, label] : std::array, 4>{ {{"yellow", "yellow", "Gelbe Karten"}, {"red", "red", "Platzverweise"}, {"attendance", "crowd", "Zuschauer"}, {"goals", "goal", "Tore"}}}) body += "
" + postmatch_art(icon, 310) + "
" + live_text(postmatch_count(total.at(key))) + "" + live_text(label) + "
"; const int games = total.at("games"); body += "

" + live_text(std::to_string(games) + (games == 1 ? " Partie · " : " Partien · ") + (games ? scalar(double(total.at("goals").get()) / games) : "—") + " Tore pro Partie") + "

" + live_text(total.at("attendance").is_null() ? "Zuschauerzahl unbekannt · nur Partien mit eigener Beteiligung" : "Nur Partien mit eigener Beteiligung") + "

"; } 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 += "

" + live_text(postmatch_data_.at("source") == "engine-recording" ? "Tabellenstand nach diesem Spieltag" : "Vorgegebener POC-Tabellenstand · Siege, Unentschieden und " "Niederlagen nicht aufgezeichnet") + "

"; for (const auto *label : {"Pl.", "Verein", "Sp.", "S", "U", "N", "Tore", "Diff.", "Pkt."}) body += live_text(label); body += "
"; if (table) for (const auto &r : table->at("rows")) { const int diff = r.at("gf").get() - r.at("ga").get(); body += "
" + live_text(postmatch_count(r.at("position"))) + postmatch_team(r.at("team"), false, 43) + live_text(postmatch_count(r.at("played"))) + live_text(postmatch_count(r.value("won", Json()))) + live_text(postmatch_count(r.value("drawn", Json()))) + live_text(postmatch_count(r.value("lost", Json()))) + 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"))) + "
"; } if (!table) body += "

" + live_text("Zu dieser Partie gehört keine Tabelle.") + "

"; body += "
"; } body += "
" + btn("postmatch-prev", "Zurück", "mv-btn", "id=\"postmatch-prev\" " + std::string(position == 0 ? "disabled" : "")) + btn("postmatch-ticker", "Zum Ticker", "mv-btn", "id=\"postmatch-ticker\"") + live_text(engine_mode_ ? std::string() : std::string("UI-Aufzeichnung"), "postmatch-status") + btn("postmatch-next", position + 1 == tabs.size() ? (engine_mode_ ? "Zum Schreibtisch" : "Zum Desktop") : "Weiter", "mv-btn primary", "id=\"postmatch-next\"") + "
"; std::string dialog; 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 = "
" + live_badge(team, 150) + "
"; 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 += "

" + live_text("Teamwerte der Partie") + "

" + live_text(match->at("home").at("name").get() + " · " + live_score_text(final.at("score")) + " · " + match->at("away").at("name").get()) + "

"; for (const auto &[key, label] : std::array, 3>{ {{"yellow", "Gelbe Karten"}, {"red", "Platzverweise"}, {"score", "Tore"}}}) detail += "
" + live_text(label) + "
" + live_text(postmatch_count(final.at(key)[side])) + "
"; detail += "
Zuschauer
" + live_text(postmatch_count(match->at("attendance"))) + "
"; } else detail += "

" + live_text("Dieser Verein spielte in keiner deiner Partien, deshalb gibt es keinen Spielbericht.") + "

"; dialog = "

" + live_text(nominee ? nominee->at("player").at("name").get() : team.value("name", "Spieltagsinfo")) + "

" + detail + "
" + btn("postmatch-detail-close", "Schließen", "mv-btn", "id=\"postmatch-detail-close\"") + btn("postmatch-detail-report", "Spielbericht", "mv-btn primary", "id=\"postmatch-detail-report\" " + std::string(match ? "" : "disabled")) + "
"; } // the evaluation is a note laid on the match sheet; the sheet beneath is not operated meanwhile const std::string note = "
" + body + "
" + dialog; const std::string sheet = live_sheet(note); return sheet.empty() ? "
" + note + "
" : sheet; }