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