Modern UI contract: calendar read

club_calendar projects the season calendar of a club: the competitions
of each day and the club's league matches on the day of their round, or
on the replay day when moved or postponed. The calendar read lists a
date range of it with fixtures, status and results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 14:12:57 +01:00
1 parent 6e400d708c
commit d3d526c2e4
5 files changed
+138

No files matched your search

+44
View File
@@ -370,6 +370,50 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
if (kind == "calendar") {
// the season calendar of the desk's team: days from `from` to `until` (ISO dates, default
// the current month) with the day's competitions and the team's league matches (planned
// day, or the replay day of a moved/postponed one with its original date). No draw.
const int own = team_of(g, c.manager);
const auto date_of = [&](int day) { return iso(almanac_date(g.season_start + uint32_t(day), g.display_start_year)); };
const std::string from = text_field(request, "from").empty() ? today.substr(0, 8) + "01" : text_field(request, "from");
const std::string until = text_field(request, "until").empty() ? today.substr(0, 8) + "31" : text_field(request, "until");
if (from.size() != 10 || until.size() != 10 || until < from)
return failure(request_id, "invalid_range", "from und until sind ISO-Daten, until nicht vor from.", c.state_revision);
A days, fixtures;
for (const ClubCalendarDay& d : club_calendar(g, own)) {
const std::string date = date_of(d.day);
if (date < from || date > until) continue;
A kinds, ids;
if (d.competitions & 0x1f) kinds.push_back("league");
for (int bit = 5; bit < 15; ++bit)
if (d.competitions >> bit & 1) kinds.push_back("cup:" + std::to_string(bit - 5));
if (d.competitions & 0x8000) kinds.push_back("replay");
if (d.competitions & 0x10000) kinds.push_back("indoor");
if (d.competitions & 0x40000) kinds.push_back("special");
if (d.competitions & 0x800000) kinds.push_back("national");
if (d.friendly) kinds.push_back("friendly");
for (const ClubCalendarMatch& cm : d.matches) {
const std::string id = "fixture:league-" + std::to_string(cm.league) + "-" + std::to_string(cm.round + 1) + "-" + std::to_string(cm.match);
ids.push_back(id);
const bool open = (cm.result & 0xcc) == 0xcc;
const bool past = d.day < g.season_day();
const std::string league_id = cm.league < int(g.world_league_id.size()) && !g.world_league_id[size_t(cm.league)].empty()
? g.world_league_id[size_t(cm.league)] : "league:" + std::to_string(cm.league);
fixtures.push_back(O{{"id", id}, {"competition", O{{"id", league_id}, {"kind", "league"}}},
{"round", cm.round + 1}, {"originalDate", cm.original_day >= 0 ? J(date_of(cm.original_day)) : J(date)},
{"scheduledDate", date}, {"home", team_ref(g, cm.home, date)}, {"away", team_ref(g, cm.away, date)},
{"status", !open ? "played" : cm.result == 0xcd && cm.original_day < 0 ? "postponed"
: cm.original_day >= 0 ? "rescheduled" : past ? "void" : "scheduled"},
{"result", open ? J(nullptr) : J(A{J(cm.result >> 4), J(cm.result & 0xf)})}});
}
if (kinds.empty() && ids.empty()) continue;
days.push_back(O{{"date", date}, {"seasonDay", d.day}, {"today", d.day == g.season_day()},
{"eventKinds", std::move(kinds)}, {"fixtureIds", std::move(ids)}});
}
return snapshot(request_id, std::move(m),
O{{"kind", "calendar"}, {"from", from}, {"until", until}, {"days", std::move(days)}, {"fixtures", std::move(fixtures)}});
}
if (kind == "scheduling" || kind == "friendly") {
const int own = team_of(g, c.manager);
if (own < 0 || own >= league_clubs())