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
@@ -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"))
|
||||
|
||||
Reference in new issue
Block a user