Modern UI contract: press events from the almanac
The news read lists a team's press events derived from the almanac, so they are the same on every read with stable occurrence ids: match and cup results (final, extra time, penalties), send-offs and injuries, runs, league position, champion and titles, with typed facts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d943494ef4
commit
9c436c753e
5 files changed
+173
No files matched your search
@@ -696,6 +696,30 @@ int main(int argc, char** argv) {
|
||||
std::printf("(date now %s)\n", s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date")).c_str());
|
||||
std::printf("(%d contract decisions answered)\n", decisions);
|
||||
}
|
||||
// the press events of the desk's team: stable ids, typed facts, the season's end
|
||||
{
|
||||
const J news = session.ui_read(O{{"kind", "news"}, {"limit", 5000}}, rev);
|
||||
const J again = session.ui_read(O{{"kind", "news"}, {"limit", 5000}}, rev);
|
||||
const auto* events = at(at(news, "data"), "events").array();
|
||||
std::set<std::string> ids;
|
||||
std::map<std::string, int> types;
|
||||
bool facts = true;
|
||||
if (events)
|
||||
for (const auto& e : *events) {
|
||||
ids.insert(s(at(e, "id")));
|
||||
++types[s(at(e, "type"))];
|
||||
if (s(at(e, "type")) == "match.result")
|
||||
facts &= at(at(at(e, "data"), "score"), "for").integer() && !s(at(at(at(e, "data"), "opponent"), "id")).empty();
|
||||
}
|
||||
std::string summary;
|
||||
for (const auto& [t, n] : types) summary += t + " " + std::to_string(n) + ", ";
|
||||
std::printf("(news: %zu events: %s)\n", events ? events->size() : 0, summary.c_str());
|
||||
check(s(at(news, "messageType")) == "snapshot" && events && ids.size() == events->size(), "news with unique ids");
|
||||
check(cli::dump_json(at(news, "data")) == cli::dump_json(at(again, "data")), "news the same on every read");
|
||||
check(types["match.result"] > 0 && types["league.position"] > 0 && facts, "match results and the season's end in the news");
|
||||
const J few = session.ui_read(O{{"kind", "news"}, {"limit", 3}}, rev);
|
||||
check(at(at(few, "data"), "events").array() && at(at(few, "data"), "events").array()->size() == 3, "news limit");
|
||||
}
|
||||
// almanac view after the kickoffs: index, calendar, day, match
|
||||
{
|
||||
const J index = session.read_almanac(O{{"kind", "index"}});
|
||||
|
||||
Reference in new issue
Block a user