Modern UI contract: live table in the paused kickoff
live_league_table is shared by the recording and the paused live state; a paused league match now reports its league with the running scores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb5c5d6211
commit
6e400d708c
5 files changed
+92
-38
No files matched your search
@@ -8809,7 +8809,25 @@ cli::Json ModernSession::read_live(const cli::Json& request) const {
|
||||
{"awayManagerId", am >= 0 ? cli::Json(modern::ui_manager_id(g_, am)) : cli::Json(nullptr)},
|
||||
{"score", cli::Json::Array{cli::Json(h), cli::Json(a)}}});
|
||||
}
|
||||
return O{{"ok", true}, {"live", true}, {"status", "paused"}, {"minute", live_->minute}, {"matches", std::move(matches)}};
|
||||
// the live tables: each league group with a live match, its matches at their score so far
|
||||
// (the group's results reach the season's result bytes only after its final whistle)
|
||||
cli::Json::Array standings;
|
||||
for (const MatchGroup& grp : *live_->groups) {
|
||||
const uint32_t league = grp.desc.size() >= 0xd0 ? le32(grp.desc, 0xcc) : 0xffffffffu;
|
||||
if (league >= uint32_t(kLeagueCount) || grp.results.size() != size_t(grp.matches())) continue;
|
||||
std::vector<modern::LiveGame> games;
|
||||
bool live = false;
|
||||
for (int m = 0; m < grp.matches(); ++m) {
|
||||
const int home = grp.fixtures.at(size_t(m) * 2), away = grp.fixtures.at(size_t(m) * 2 + 1);
|
||||
live |= std::find(g_.live_matches.begin(), g_.live_matches.end(), home) != g_.live_matches.end();
|
||||
const int h = grp.results[size_t(m)] >> 4, a = grp.results[size_t(m)] & 0xf;
|
||||
if (h < 0xc && a < 0xc) games.push_back({home, away, h, a});
|
||||
}
|
||||
if (live && league < g_.league_rounds.size())
|
||||
standings.push_back(modern::live_league_table(g_, int(league), int(g_.league_rounds[league]) + 1, games));
|
||||
}
|
||||
return O{{"ok", true}, {"live", true}, {"status", "paused"}, {"minute", live_->minute}, {"matches", std::move(matches)},
|
||||
{"standings", std::move(standings)}};
|
||||
}
|
||||
if (!ui_last_advance_) return fail("live_unavailable");
|
||||
if (const cli::Json* r = ui_field(request, "revision"); r && (!r->integer() || uint64_t(*r->integer()) != ui_last_advance_revision_))
|
||||
|
||||
@@ -784,6 +784,36 @@ const char* event_kind(AlmanacEventKind k) {
|
||||
|
||||
} // namespace
|
||||
|
||||
cli::Json live_league_table(const ModernState& g, int league, int round, const std::vector<LiveGame>& games) {
|
||||
LeagueTable base;
|
||||
if (round > 1) base = compute_league_table(g, league, 0, round - 1, 7, 1);
|
||||
else base.league = league, base.size = int(kLeagueSizes[league]);
|
||||
const int first = league_first_team(league);
|
||||
LeagueTable t = base;
|
||||
for (const LiveGame& game : games) {
|
||||
const int club[2] = {game.home - first, game.away - first};
|
||||
if (club[0] < 0 || club[0] >= t.size || club[1] < 0 || club[1] >= t.size) continue;
|
||||
const uint8_t goals[2] = {uint8_t(game.home_goals), uint8_t(game.away_goals)};
|
||||
add_result(t, club, goals, 3, 1);
|
||||
}
|
||||
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); });
|
||||
A rows;
|
||||
for (int i : order) {
|
||||
const int played = 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", round > 1 ? J(base.rank(i) + 1) : J(nullptr)},
|
||||
{"team", O{{"id", ui_team_id(g, first + i)}, {"name", name}}}, {"played", played}, {"won", won},
|
||||
{"drawn", std::max(0, played - 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)])}});
|
||||
}
|
||||
const Competition c = league_competition(g.almanac.current, league);
|
||||
return O{{"competitionId", c.id}, {"name", c.name}, {"round", round}, {"rows", std::move(rows)}};
|
||||
}
|
||||
|
||||
cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until_date, uint64_t revision) {
|
||||
// the matches of the last kickoff (dates after_date <= d < until_date) from the almanac: the
|
||||
// ones with a human manager are the ticker's matches (at most four), all others the conference
|
||||
@@ -848,11 +878,9 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
|
||||
// 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<std::array<int, 2>> teams; // runtime teams of each game
|
||||
std::string last; // the scores the table was last built from
|
||||
};
|
||||
std::vector<LiveLeague> live_leagues;
|
||||
for (const Ref& r : human) {
|
||||
@@ -861,56 +889,36 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
|
||||
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;
|
||||
std::map<std::string, int> team;
|
||||
for (int t = first; t < first + int(kLeagueSizes[m.league]); ++t) team[ui_team_id(g, t)] = t;
|
||||
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;
|
||||
const auto h = team.find(o.season->clubs[x.home].id), a = team.find(o.season->clubs[x.away].id);
|
||||
if (h == team.end() || a == team.end()) continue;
|
||||
l.games.push_back(&x);
|
||||
l.at.push_back({h->second, a->second});
|
||||
l.teams.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::vector<LiveGame> games;
|
||||
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;
|
||||
LiveGame game{l.teams[k][0], l.teams[k][1], 0, 0};
|
||||
if (final_whistle) game.home_goals = x.home_goals, game.away_goals = 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 (e.kind == AlmanacEventKind::Goal && e.minute <= minute) ++(e.side ? game.away_goals : game.home_goals);
|
||||
if (minute > 0) games.push_back(game);
|
||||
key += std::to_string(game.home_goals) + ":" + std::to_string(game.away_goals) + ",";
|
||||
}
|
||||
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)}};
|
||||
return live_league_table(g, l.league, l.round, games);
|
||||
};
|
||||
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());
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// goals, assists, cards per player in one competition,
|
||||
// of one season ("2026/27") or all seasons
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "cli/json.hpp"
|
||||
#include "modern/game/modern_state.hpp"
|
||||
|
||||
@@ -42,6 +44,13 @@ cli::Json query_statistics_screen(const ModernState& g, int manager, const cli::
|
||||
// day as the conference. source: "engine-recording".
|
||||
cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until_date, uint64_t revision);
|
||||
|
||||
// A game of a matchday under way: runtime teams and goals so far.
|
||||
struct LiveGame { int home = 0, away = 0, home_goals = 0, away_goals = 0; };
|
||||
// The live table of a league during matchday `round` (1-based): the table before it plus the
|
||||
// given games. {competitionId, name, round, rows: [{rank, previousRank, team, played, won,
|
||||
// drawn, lost, goalsFor, goalsAgainst, points}]}.
|
||||
cli::Json live_league_table(const ModernState& g, int league, int round, const std::vector<LiveGame>& games);
|
||||
|
||||
// All recorded matches with from_date <= date < until_date in the almanac form (the matches of a kickoff).
|
||||
cli::Json almanac_matches_between(const ModernState& g, uint32_t from_date, uint32_t until_date);
|
||||
|
||||
|
||||
Reference in new issue
Block a user