Modern UI contract: live table in the ticker
Each live frame carries the league tables of the ticker's matches: the table before the matchday plus every match of that round at the frame's minute, the final whistle using the recorded result. Frames carry only changed tables; a single frame read gets the full standing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
74c1504e3a
commit
eb5c5d6211
4 files changed
+109
-6
No files matched your search
@@ -13,6 +13,8 @@
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/messages.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/table.hpp"
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/game/almanac.hpp"
|
||||
|
||||
@@ -840,6 +842,76 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
|
||||
std::stable_sort(moments.begin(), moments.end(), [](const Moment& a, const Moment& b) {
|
||||
return a.minute != b.minute ? a.minute < b.minute : a.order < b.order;
|
||||
});
|
||||
// the live tables: per league of a ticker match, the table before its matchday plus every
|
||||
// match of that round in this kickoff with its score at the frame's minute (the final
|
||||
// whistle uses the recorded result). A frame carries a league's table when it changed
|
||||
// there (all of them on the first frame).
|
||||
struct LiveLeague {
|
||||
int league = 0, round = 0;
|
||||
std::string id, name;
|
||||
LeagueTable base;
|
||||
std::vector<const AlmanacMatch*> games;
|
||||
std::vector<std::array<int, 2>> at; // draw positions of each game's clubs
|
||||
std::string last; // the scores the table was last built from
|
||||
};
|
||||
std::vector<LiveLeague> live_leagues;
|
||||
for (const Ref& r : human) {
|
||||
const AlmanacMatch& m = r.season->matches[r.index];
|
||||
if (m.type != 0 || m.league >= kLeagueCount || m.round == 0) continue;
|
||||
if (std::any_of(live_leagues.begin(), live_leagues.end(), [&](const LiveLeague& l) { return l.league == m.league; })) continue;
|
||||
LiveLeague l;
|
||||
l.league = m.league, l.round = m.round;
|
||||
const Competition c = competition_of(g, *r.season, m);
|
||||
l.id = c.id, l.name = c.name;
|
||||
if (m.round > 1) l.base = compute_league_table(g, m.league, 0, m.round - 1, 7, 1);
|
||||
else l.base.league = m.league, l.base.size = int(kLeagueSizes[m.league]);
|
||||
const int first = league_first_team(m.league);
|
||||
std::map<std::string, int> position;
|
||||
for (int c2 = 0; c2 < l.base.size; ++c2) position[ui_team_id(g, first + c2)] = c2;
|
||||
for (const std::vector<Ref>* list : {&human, &others})
|
||||
for (const Ref& o : *list) {
|
||||
const AlmanacMatch& x = o.season->matches[o.index];
|
||||
if (x.type != 0 || x.league != m.league || x.round != m.round) continue;
|
||||
const auto h = position.find(o.season->clubs[x.home].id), a = position.find(o.season->clubs[x.away].id);
|
||||
if (h == position.end() || a == position.end()) continue;
|
||||
l.games.push_back(&x);
|
||||
l.at.push_back({h->second, a->second});
|
||||
}
|
||||
live_leagues.push_back(std::move(l));
|
||||
}
|
||||
const auto live_table = [&](LiveLeague& l, int minute, bool final_whistle) -> J {
|
||||
LeagueTable t = l.base;
|
||||
std::string key;
|
||||
for (size_t k = 0; k < l.games.size(); ++k) {
|
||||
const AlmanacMatch& x = *l.games[k];
|
||||
uint8_t goals[2] = {0, 0};
|
||||
if (final_whistle) goals[0] = x.home_goals, goals[1] = x.away_goals;
|
||||
else
|
||||
for (const auto& e : x.events)
|
||||
if (e.kind == AlmanacEventKind::Goal && e.minute <= minute) ++goals[e.side ? 1 : 0];
|
||||
const int club[2] = {l.at[k][0], l.at[k][1]};
|
||||
if (minute > 0) add_result(t, club, goals, 3, 1);
|
||||
key += std::to_string(goals[0]) + ":" + std::to_string(goals[1]) + ",";
|
||||
}
|
||||
if (key == l.last) return nullptr;
|
||||
l.last = key;
|
||||
sort_table(t, 0);
|
||||
std::vector<int> order(size_t(t.size));
|
||||
for (int i = 0; i < t.size; ++i) order[size_t(i)] = i;
|
||||
std::stable_sort(order.begin(), order.end(), [&](int a, int b) { return t.rank(a) < t.rank(b); });
|
||||
const int first = league_first_team(l.league);
|
||||
A rows;
|
||||
for (int i : order) {
|
||||
const int games = t.games(i), won = t.wins[size_t(i)], lost = t.defeats[size_t(i)];
|
||||
std::string name = size_t(first + i) < g.world_club_name.size() ? g.world_club_name[size_t(first + i)] : std::string{};
|
||||
if (name.empty()) name = almanac_utf8(g.club_name(first + i));
|
||||
rows.push_back(O{{"rank", t.rank(i) + 1}, {"previousRank", l.round > 1 ? J(l.base.rank(i) + 1) : J(nullptr)},
|
||||
{"team", O{{"id", ui_team_id(g, first + i)}, {"name", name}}}, {"played", games}, {"won", won},
|
||||
{"drawn", std::max(0, games - won - lost)}, {"lost", lost}, {"goalsFor", int(t.goals_for[size_t(i)])},
|
||||
{"goalsAgainst", int(t.goals_against[size_t(i)])}, {"points", int(t.points[size_t(i)])}});
|
||||
}
|
||||
return O{{"competitionId", l.id}, {"name", l.name}, {"round", l.round}, {"rows", std::move(rows)}};
|
||||
};
|
||||
struct Tally { int score[2] = {0, 0}, chances[2] = {0, 0}, yellow[2] = {0, 0}, red[2] = {0, 0}, shootout[2] = {0, 0}; };
|
||||
std::vector<Tally> tally(human.size());
|
||||
A frames, events;
|
||||
@@ -870,12 +942,17 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
|
||||
{"score", A{J(t.score[0]), J(t.score[1])}}, {"chances", A{J(t.chances[0]), J(t.chances[1])}},
|
||||
{"yellow", A{J(t.yellow[0]), J(t.yellow[1])}}, {"red", A{J(t.red[0]), J(t.red[1])}},
|
||||
{"shootout", A{J(t.shootout[0]), J(t.shootout[1])}},
|
||||
{"players", A{J(11 - t.red[0]), J(11 - t.red[1])}}, {"standings", A{}}});
|
||||
{"players", A{J(11 - t.red[0]), J(11 - t.red[1])}}});
|
||||
}
|
||||
const char* phase = mo.phase ? mo.phase : mo.minute <= 45 ? "first_half" : mo.minute <= 90 ? "second_half"
|
||||
: mo.minute <= 120 ? "extra_time" : "shootout";
|
||||
A standings;
|
||||
const bool final_whistle = mo.phase && (std::string(mo.phase) == "fulltime" || std::string(mo.phase) == "shootout_end");
|
||||
for (LiveLeague& l : live_leagues)
|
||||
if (J table = live_table(l, mo.minute, final_whistle); !std::holds_alternative<std::nullptr_t>(table.value))
|
||||
standings.push_back(std::move(table));
|
||||
frames.push_back(O{{"sequence", int64_t(frames.size())}, {"minute", mo.minute}, {"phase", phase},
|
||||
{"matches", std::move(scores)}, {"events", events}});
|
||||
{"matches", std::move(scores)}, {"events", events}, {"standings", std::move(standings)}});
|
||||
}
|
||||
const AlmanacSeason& first = *human.front().season;
|
||||
return O{{"ok", true}, {"schema", "openbmh-live-fixture@1"}, {"source", "engine-recording"},
|
||||
|
||||
Reference in new issue
Block a user