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:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:59:02 +01:00
1 parent 74c1504e3a
commit eb5c5d6211
4 files changed
+109 -6

No files matched your search

+2 -2
View File
@@ -25,7 +25,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| Read | Inhalt |
|---|---|
| `session` | `sessionState`, `activeManagerId`, alle menschlichen Manager (ID, Platz, Name, Team, Porträt, `active`/`waiting`) |
| `desktop` | Manager, Team (`TeamRef`), Kontostand (`accounts.cash`; Sparguthaben und Kredit folgen mit dem Bank-Read), nächstes Spiel, `menuAvailability` |
| `desktop` | Manager, Team (`TeamRef`), Kontostand (`accounts.cash`; Festgeld und Kredit im Read `bank` bzw. `credit`), nächstes Spiel, `menuAvailability` |
| `squad` | ein Kader (`teamId`, sonst der eigene Verein; auch Nationalteams mit Kader): Spieler-ID, Name, Nation, Position, Rolle (`starter`/`bench`/`reserve`), Verfügbarkeit, Verletzung und Sperre in Wochen, Alter, Werte (Stärke, Kondition, Technik, Form), Fähigkeiten; für den eigenen Verein Monatsgehalt und Restlaufzeit in Monaten (fremde Vereine: `null`) |
| `camps` | Karten und Lager (Qualität 0–6, Ort, Nation, Exklusiv-Sponsor-Chance), je Lager ein bindendes Angebot für den eigenen Kader (Grundpreis + Kaderzuschlag, ohne Zufall; `allowed`, `reasonCode` `booked_this_week`/`visit_limit`/`no_club`, `exceedsCash`), Schwerpunkte, Aufenthalte der Saison, Buchung dieser Woche |
| `lineup` | die Kaderzeilen in Reihenfolge (die ersten elf spielen) mit Rolle, die Plätze der Startelf auf der Taktiktafel (`depth` 0–19, `lane` 0–8; das JSON hat keine Kommazahlen), `manual` (Aufstellung von Hand) |
@@ -61,7 +61,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
- `matches`: die Spiele mit menschlichem Manager (höchstens vier), `owners`: die Manager mit Team und `match_id` (`view` ist `null`; die Aufstellung kommt aus dem `lineup`-Read).
- `frames` in Minutenfolge: Anpfiff, jedes Ereignis (Tor, Chance, Karten, Verletzung, Wechsel, Elfmeter), Halbzeit, Wiederanpfiff, Abpfiff; je Spiel Stand, Chancen, Gelb, Rot, Elfmeter, Spieler auf dem Feld. `events` (fortlaufend) mit Überschrift und Satz, Spieler, Seite, Stand.
- `conference`: die übrigen Spiele des Tages im Almanach-Format.
- Noch leer: `standings` (Live-Tabelle). Fehler: `live_unavailable` (noch kein Anstoß), `live_no_human_match`, `stale_live_revision`, `stale_live_fixture`, `invalid_live_sequence`.
- `standings` (Live-Tabelle) je Frame: pro Liga eines Ticker-Spiels die Tabelle vor dem Spieltag plus alle Spiele dieser Runde im Anstoß mit dem Stand der Minute (beim Abpfiff das gewertete Ergebnis); Zeilen mit `rank`, `previousRank`, `team`, `played`, `won`, `drawn`, `lost`, `goalsFor`, `goalsAgainst`, `points`. In der Aufzeichnung trägt ein Frame nur die Tabellen, die sich in ihm geändert haben (der erste alle); `kind: frame` liefert den vollständigen Stand bis dahin. Im angehaltenen Live-Anstoß noch ohne Tabelle. Fehler: `live_unavailable` (noch kein Anstoß), `live_no_human_match`, `stale_live_revision`, `stale_live_fixture`, `invalid_live_sequence`.
- **Live mit Eingriffen:** `session.advance {live: true}` startet den Anstoß in einem eigenen Ablauf, der nach der ersten Minute eines laufenden Live-Spiels eines Menschen anhält (eine gewertete Partie, z. B. ein Forfeit, läuft ohne Halt durch). Solange er steht, liefert `read_live` `{live: true, status: "paused", minute, matches}`: je Live-Spiel Stand, Manager je Seite und die bisherigen Ereignisse (`goal`, `miss`, `yellow`, `second_yellow`, `red`, `injury` mit Minute, Seite, Spieler, Vorlage); Wechsel zeigt der `lineup`-Read. Die vollständige Aufzeichnung folgt nach dem Abpfiff. Alle anderen Befehle antworten `live_running`, bis der Spieltag vorbei ist.
## Commands
+11 -1
View File
@@ -8825,7 +8825,17 @@ cli::Json ModernSession::read_live(const cli::Json& request) const {
const cli::Json* seq = ui_field(request, "sequence");
const auto& frames = *f->at("frames").array();
if (!seq || !seq->integer() || *seq->integer() < 0 || size_t(*seq->integer()) >= frames.size()) return fail("invalid_live_sequence");
return O{{"ok", true}, {"fixture_id", f->at("fixture_id")}, {"frame", frames[size_t(*seq->integer())]}};
// a frame of the recording carries only the tables that changed in it; read alone it gets the
// standing table of every league (the latest frame up to it that carried one)
cli::Json frame = frames[size_t(*seq->integer())];
std::map<std::string, cli::Json> tables;
for (size_t k = 0; k <= size_t(*seq->integer()); ++k)
for (const auto& t : *frames[k].object()->at("standings").array())
tables[*t.object()->at("competitionId").string()] = t;
cli::Json::Array standings;
for (auto& [id, t] : tables) standings.push_back(std::move(t));
std::get<O>(frame.value)["standings"] = std::move(standings);
return O{{"ok", true}, {"fixture_id", f->at("fixture_id")}, {"frame", std::move(frame)}};
}
cli::Json ModernSession::read_statistics_screen(const cli::Json& request) const {
+79 -2
View File
@@ -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"},
+17 -1
View File
@@ -3,6 +3,7 @@
// envelope, identities, money, errors and that a read changes nothing. Needs game data
// (a Modern session on the Classic data).
#include <cstdio>
#include <map>
#include <string>
#include <variant>
@@ -510,6 +511,7 @@ int main(int argc, char** argv) {
// the live ticker: advance until a kickoff played a match of the human manager, then its recording
{
J fixture;
J live_final;
for (int k = 0; k < 12; ++k) {
fixture = session.read_live(O{{"kind", "fixture"}});
if (truth(at(fixture, "ok"))) break;
@@ -524,7 +526,8 @@ int main(int argc, char** argv) {
if (frames && frames->size() >= 4) {
const J& last = frames->back();
const J one = session.read_live(O{{"kind", "frame"}, {"sequence", int64_t(frames->size() - 1)}});
check(truth(at(one, "ok")) && cli::dump_json(at(one, "frame")) == cli::dump_json(last), "one frame by sequence");
check(truth(at(one, "ok")) && cli::dump_json(at(at(one, "frame"), "matches")) == cli::dump_json(at(last, "matches")), "one frame by sequence");
live_final = at(at(one, "frame"), "standings");
// the last frame's score is the recorded result of the match
const J m = at(at(last, "matches").array()->front(), "score");
std::printf("(live: %zu frames, %zu matches, conference %zu, final %s)\n", frames->size(), matches->size(),
@@ -538,6 +541,19 @@ int main(int argc, char** argv) {
check(s(at(post, "messageType")) == "snapshot" && steps && steps->size() == 5 && truth(at((*steps)[0], "available")) &&
at(pd, "matches").array() && !at(pd, "matches").array()->empty() && at(pd, "reportMatchIds").array() &&
!at(pd, "reportMatchIds").array()->empty(), "postmatch with results and report");
// the live table at the final whistle is the league table after the matchday
if (const auto* lt = live_final.array(); lt && !lt->empty() && at(pd, "tables").array()) {
std::map<std::string, int64_t> points;
for (const auto& t : *at(pd, "tables").array())
for (const auto& r : *at(t, "rows").array()) points[s(at(at(r, "club"), "id"))] = *at(r, "points").integer();
bool same = true;
for (const auto& r : *at(lt->front(), "rows").array()) {
const auto p = points.find(s(at(at(r, "team"), "id")));
same &= p != points.end() && p->second == *at(r, "points").integer();
}
std::printf("(live table: %zu leagues, %zu rows)\n", lt->size(), at(lt->front(), "rows").array()->size());
check(same, "live table at the final whistle equals the league table");
}
std::printf("(postmatch: %zu matches, %zu tables, %zu elevens)\n", at(pd, "matches").array()->size(),
at(pd, "tables").array() ? at(pd, "tables").array()->size() : 0,
at(pd, "teamOfTheDay").array() ? at(pd, "teamOfTheDay").array()->size() : 0);