Liven up the match day: varied ticker wording, whistles, results of the day, eleven of the day
The ticker picks its sentence from several variants by the event's facts and names equalisers, leads and late goals; kickoff, half time and the final whistle are reported, with the same wording while the kickoff runs live. The ticker's third tab lists the other results of the day. Modern chooses an eleven of the day per league from the recorded match facts and the review shows it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
333bc57526
commit
1732a2477b
11 files changed
+288
-24
No files matched your search
@@ -48,6 +48,7 @@ void App::engine_kickoff() {
|
||||
return EngineReply{link, desk, response, nullptr};
|
||||
}
|
||||
response["liveRecording"] = state;
|
||||
response["postmatch"] = link->read({{"kind", "postmatch"}});
|
||||
auto after = link->snapshot();
|
||||
engine_attach_opening(*link, engine_season_id(desk), after, response);
|
||||
return EngineReply{link, std::move(after), response, nullptr};
|
||||
@@ -148,6 +149,8 @@ void App::engine_accept(EngineReply result) {
|
||||
engine_live_begin(state, engine_response_.value("newRevision", std::string()));
|
||||
}
|
||||
if (engine_response_.contains("liveRecording")) {
|
||||
engine_postmatch_read_ = engine_response_.value("postmatch", Json());
|
||||
engine_response_.erase("postmatch");
|
||||
const Json recording = engine_response_.at("liveRecording");
|
||||
engine_response_.erase("liveRecording");
|
||||
engine_advance_payload_ = Json::object();
|
||||
|
||||
@@ -207,7 +207,40 @@ Json engine_live_command(const Json &bundle, const std::string &revision, const
|
||||
{"kind", kind}, {"payload", payload.is_object() ? payload : Json::object()}};
|
||||
}
|
||||
|
||||
Json engine_post_match_records(const Json &read, const Json &fixture) {
|
||||
try {
|
||||
if (!read.is_object() || read.value("messageType", "") != "snapshot") return Json();
|
||||
const auto &elevens = read.at("data").at("teamOfTheDay");
|
||||
if (!elevens.is_array() || elevens.empty()) return Json();
|
||||
// club names as the recording spells them (its matches and final tables)
|
||||
std::map<std::string, std::string> clubs;
|
||||
for (const auto &match : fixture.at("matches"))
|
||||
for (auto side : {"home", "away"}) clubs[match.at(side).at("id")] = match.at(side).at("name");
|
||||
for (const auto &snapshot : fixture.at("frames").back().at("matches"))
|
||||
for (const auto &row : snapshot.at("standings")) clubs[row.at("team").at("id")] = row.at("team").at("name");
|
||||
for (const auto &eleven : elevens) {
|
||||
if (!eleven.contains("players") || !eleven.at("players").is_array() || eleven.at("players").size() != 11) continue;
|
||||
Json rows = Json::array();
|
||||
for (const auto &p : eleven.at("players")) {
|
||||
const auto club = clubs.find(p.value("teamId", std::string()));
|
||||
if (club == clubs.end()) break;
|
||||
rows.push_back({{"player", {{"id", p.at("playerId")}, {"name", p.at("name")}}},
|
||||
{"team", {{"id", club->first}, {"name", club->second}, {"role", "club"}}},
|
||||
{"position", p.at("position")}, {"rating", nullptr}});
|
||||
}
|
||||
if (rows.size() != 11) continue;
|
||||
return {{"schema", "openbmh-post-match-records@1"}, {"fixture_id", fixture.at("fixture_id")},
|
||||
{"source_revision", fixture.at("source_revision")},
|
||||
{"eleven", {{"available", true}, {"source", "supplied-records"},
|
||||
{"notice", eleven.value("competition", std::string("Liga")) + " · nach Toren, Vorlagen, Karten und Ergebnis des Spieltags"},
|
||||
{"formation", "3-4-3"}, {"rows", rows}}}};
|
||||
}
|
||||
return Json();
|
||||
} catch (const std::exception &) { return Json(); }
|
||||
}
|
||||
|
||||
Json engine_live_roster(const Json &bundle) {
|
||||
|
||||
Json rows = Json::array();
|
||||
try {
|
||||
const auto &players = bundle.at("squad").at("data").at("players");
|
||||
@@ -324,6 +357,10 @@ Json engine_live_progress(const Json &previous, const Json &state, const Json &b
|
||||
} else if (kind == "injury") {
|
||||
headline = "Verletzung"; body = (player.empty() ? "Ein Spieler" : player) + " (" + team + ") muss behandelt werden.";
|
||||
} else continue;
|
||||
if (e.contains("headline") && e.at("headline").is_string() && e.contains("body") && e.at("body").is_string() &&
|
||||
!e.at("headline").get<std::string>().empty()) {
|
||||
headline = e.at("headline").get<std::string>(); body = e.at("body").get<std::string>();
|
||||
}
|
||||
const std::string event_id = id + ":event:" + std::to_string(index++);
|
||||
const auto at = known.find(event_id);
|
||||
events.push_back(at != known.end() ? at->second
|
||||
@@ -332,6 +369,24 @@ Json engine_live_progress(const Json &previous, const Json &state, const Json &b
|
||||
{"headline", headline}, {"body", body}, {"score", {goals[0], goals[1]}},
|
||||
{"side", side ? "away" : "home"}, {"player", e.at("player")}, {"other", e.value("other", Json())}});
|
||||
}
|
||||
{
|
||||
// the whistle, as in the recording: kickoff, and half time once the second half runs
|
||||
const auto whistle = [&](const char *suffix, int64_t at, const char *kind, const std::string &headline, const std::string &body, int h, int a) {
|
||||
const std::string event_id = id + suffix;
|
||||
const auto known_at = known.find(event_id);
|
||||
events.push_back(known_at != known.end() ? known_at->second
|
||||
: Json{{"id", event_id}, {"sequence", sequence}, {"match_id", id}, {"minute", at}, {"kind", kind},
|
||||
{"headline", headline}, {"body", body}, {"score", {h, a}}, {"side", "home"},
|
||||
{"player", nullptr}, {"other", nullptr}});
|
||||
};
|
||||
whistle(":kickoff", 0, "kickoff", "Anpfiff", m.at("home").at("name").get<std::string>() + " gegen " + m.at("away").at("name").get<std::string>() + ": Der Ball rollt.", 0, 0);
|
||||
if (minute > 45) {
|
||||
int h = 0, a = 0;
|
||||
for (const auto &e : m.at("events"))
|
||||
if (e.value("kind", std::string()) == "goal" && e.value("minute", int64_t(0)) <= 45) ++(e.value("side", std::string("home")) == "away" ? a : h);
|
||||
whistle(":interval", 45, "interval", "Halbzeit", "Zur Pause steht es " + std::to_string(h) + ":" + std::to_string(a) + ".", h, a);
|
||||
}
|
||||
}
|
||||
Json score = m.value("score", Json::array({goals[0], goals[1]}));
|
||||
Json standings = Json::array();
|
||||
if (role == "club" && state.contains("standings"))
|
||||
|
||||
@@ -17,6 +17,9 @@ Json engine_live_command(const Json &bundle, const std::string &revision, const
|
||||
const std::string &kind, const Json &payload);
|
||||
// The desk manager's squad in line-up order, as the ticker's team tab lists it.
|
||||
Json engine_live_roster(const Json &bundle);
|
||||
// The engine's eleven of the day (post-match read) as review records for this recording;
|
||||
// null when the read has none for the league of the ticker's match.
|
||||
Json engine_post_match_records(const Json &postmatch_read, const Json &fixture);
|
||||
// One more frame for the standing kickoff (`state` is the paused read_live answer).
|
||||
Json engine_live_progress(const Json &previous, const Json &state, const Json &bundle, const Json &roster);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -167,7 +167,7 @@ void App::engine_live_poll() {
|
||||
engine_live_at_end_ = true;
|
||||
const std::string season = engine_season_id(engine_data_);
|
||||
engine_start("Abpfiff …", [link, state, season] {
|
||||
Json finished = {{"messageType", "live_finished"}, {"liveRecording", state}};
|
||||
Json finished = {{"messageType", "live_finished"}, {"liveRecording", state}, {"postmatch", link->read({{"kind", "postmatch"}})}};
|
||||
auto after = link->snapshot();
|
||||
engine_attach_opening(*link, season, after, finished);
|
||||
return EngineReply{link, std::move(after), finished, nullptr};
|
||||
|
||||
@@ -128,6 +128,27 @@ std::string App::live_detail(const Json &owner, const Json &frame) {
|
||||
btn("live-intervene-tactics", "Taktik als Demo bearbeiten", "", "id=\"live-tactics-edit\" " + std::string(live_.finished() ? "disabled" : "")) +
|
||||
"<p>" + live_text("Die Vorschau verändert weder diese feste Ereignisfolge noch Spiel- oder Saisonwerte.") + "</p></div>";
|
||||
}
|
||||
if (live_tab_ == "opponent" && recorded) {
|
||||
// the other matches of the day, own competition first; known once the day is played
|
||||
if (!live_.finished() || !fixture.contains("conference") || !fixture.at("conference").is_array() || fixture.at("conference").empty())
|
||||
return "<p class=\"live-note\">" + live_text(live_.finished() ? "An diesem Tag gab es keine weiteren Spiele." : "Die Ergebnisse der anderen Spiele stehen nach dem Abpfiff hier.") + "</p>";
|
||||
const std::string own = match.value("competition", std::string());
|
||||
std::vector<std::string> order;
|
||||
std::map<std::string, std::string> groups;
|
||||
for (const auto &other : fixture.at("conference")) {
|
||||
const std::string name = other.at("competition").value("name", std::string("Weitere Spiele"));
|
||||
if (!groups.contains(name)) order.push_back(name);
|
||||
const auto &result = other.at("result").at("final");
|
||||
groups[name] += "<div class=\"live-roster-row\">" +
|
||||
live_text(other.at("home").value("name", std::string()) + " – " + other.at("away").value("name", std::string()), "live-roster-name") +
|
||||
live_text(std::to_string(result[0].get<int>()) + ":" + std::to_string(result[1].get<int>()), "live-roster-stat") + "</div>";
|
||||
}
|
||||
std::stable_sort(order.begin(), order.end(), [&](const std::string &a, const std::string &b) { return (a == own) > (b == own); });
|
||||
std::string list = "<div class=\"live-roster\">";
|
||||
for (const auto &name : order)
|
||||
list += "<div class=\"live-roster-row heading\">" + live_text(name, "live-roster-name") + live_text("", "live-roster-stat") + "</div>" + groups.at(name);
|
||||
return list + "</div>";
|
||||
}
|
||||
std::string out;
|
||||
if (live_tab_ == "opponent") {
|
||||
const auto &opponent = match.at(owner.at("team").at("id") == match.at("home").at("id") ? "away" : "home");
|
||||
@@ -170,11 +191,11 @@ std::string App::live_ticker_events(const Json &frame, size_t &shown) {
|
||||
const auto &event = *i; const auto kind = event.value("kind", "");
|
||||
if (live_coverage_ == "single" && event.at("match_id") != live_selected_match_) continue;
|
||||
if (live_filter_ == "goal" && kind != "goal") continue;
|
||||
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red") continue;
|
||||
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "red") continue;
|
||||
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red" && kind != "second_yellow") continue;
|
||||
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "miss" && kind != "red" && kind != "second_yellow") continue;
|
||||
const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id"));
|
||||
out += "<article class=\"live-event " + std::string(kind == "goal" ? "is-goal" : "") + "\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\">" + live_text(std::to_string(event.at("minute").get<int>()) + "′", "live-event-time") + live_badge(match.at(event.at("side").get<std::string>()), 54) +
|
||||
"<div class=\"live-event-copy\">" + live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>(), "live-event-owners") + "<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" + live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
|
||||
"<div class=\"live-event-copy\">" + (fixture.at("source") == "engine-recording" && fixture.at("matches").size() == 1 ? std::string() : live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>(), "live-event-owners")) + "<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" + live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
|
||||
++shown;
|
||||
}
|
||||
if (!shown) out += "<p class=\"live-note\">" + live_text(fixture.at("source") == "engine-recording" ? "Noch keine Meldungen." : "Für diesen Filter liegt noch keine Demomeldung vor.") + "</p>";
|
||||
@@ -217,7 +238,7 @@ std::string App::render_live() {
|
||||
out += live_ticker_events(frame, shown);
|
||||
out += "</div><footer class=\"live-ticker-footer\">" "<span id=\"live-event-count\" class=\"live-small\">" + esc(std::to_string(shown) + (live_.fixture().at("source") == "engine-recording" ? (shown == 1 ? " Meldung" : " Meldungen") : " Meldungen · feste Aufzeichnung")) + "</span>" + "<span id=\"live-phase-status\" class=\"live-small\">" + esc(phase_text) + "</span></footer></section></div><aside id=\"live-detail\" class=\"live-detail live-panel\"><header class=\"live-panel-heading\"><div class=\"live-detail-heading\"><h2>" + "<span id=\"live-owner-team\">" + esc(owner.at("team").at("name").get<std::string>()) + "</span></h2><p><span id=\"live-owner-name\">" + esc(owner.at("name").get<std::string>()) + "</span>" + "</p></div><nav class=\"live-team-switch\" aria-label=\"Managerdetails wechseln\">" +
|
||||
btn("live-owner-prev", arrow(false), "", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + btn("live-owner-next", arrow(true), "", "id=\"live-owner-next\" aria-label=\"Nächster Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + "</nav></header><nav class=\"live-tabs\">";
|
||||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", "Gegner"}, {"table", "Live-Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
|
||||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", recorded ? "Ergebnisse" : "Gegner"}, {"table", "Live-Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
|
||||
out += "</nav><div id=\"live-detail-body\" class=\"live-detail-body\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"live-detail-footer\">" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() || (recorded && !live_.running()) ? "disabled" : "")) + "</footer></aside></div>";
|
||||
out += "<div class=\"live-speed\">" + live_text("+") + "<input id=\"live-speed\" type=\"range\" orientation=\"vertical\" min=\"0\" max=\"4\" step=\"1\" value=\"" + std::to_string(4 - live_.speed()) + "\" aria-label=\"Wiedergabegeschwindigkeit; unten Pause\" aria-valuenow=\"" + std::to_string(live_.speed()) + "\" " + (live_.finished() ? "disabled" : "") + "/><span id=\"live-speed-value\" class=\"live-speed-value\">" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "</span></div>";
|
||||
out += "<footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", live_.running() ? "Zu Ende spielen" : recorded ? "Zum Schreibtisch" : "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "</div><span id=\"live-playback-status\" class=\"live-bottom-note\">" + esc(live_feedback_.empty() ? std::string(phase_text) + " · " + std::to_string(minute) + (recorded ? "′" : "′ · keine Spielwertänderung") : live_feedback_) + "</span>" +
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
bool engine_live_open(const Json &recording);
|
||||
std::string live_return_scene_;
|
||||
Json engine_advance_payload_ = Json::object();
|
||||
Json engine_postmatch_read_; // the engine's post-match read of the last kickoff
|
||||
std::string engine_expiry_player_;
|
||||
void engine_kickoff();
|
||||
// A kickoff of the engine that is played minute by minute while the ticker is open.
|
||||
|
||||
@@ -7,6 +7,14 @@ bool App::postmatch_open() {
|
||||
message("Die Auswertung dieser Aufnahme ist nicht verfügbar.");
|
||||
return false;
|
||||
}
|
||||
if (live_.fixture().at("source") == "engine-recording") {
|
||||
// the eleven of the day as the engine chose it for this league
|
||||
const auto records = engine_post_match_records(engine_postmatch_read_, live_.fixture());
|
||||
if (records.is_object()) {
|
||||
auto with_eleven = make_demo_post_match(live_.fixture(), live_.sequence(), records);
|
||||
if (with_eleven.value("ok", false)) data = std::move(with_eleven);
|
||||
}
|
||||
}
|
||||
if (live_.fixture().at("source") != "engine-recording") try {
|
||||
const auto current = snap();
|
||||
if (source_.get() != live_source_ || current.world != live_world_ ||
|
||||
|
||||
Reference in new issue
Block a user