Project completed demo live recordings into read-only match reviews (by Codex)
This commit is contained in:
1 parent
fec4c6c7e7
commit
2c4b9d2595
7 files changed
+464
-2
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
@@ -124,7 +124,7 @@ foreach(component environment advertising toto lineup transfer stadium)
|
||||
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
|
||||
endforeach()
|
||||
|
||||
foreach(component statistics news settings desktop files entry opening career live national)
|
||||
foreach(component statistics news settings desktop files entry opening career live national post_match)
|
||||
add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp)
|
||||
target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_post_match.hpp"
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
Json failure(const char *error) { return {{"ok", false}, {"error", error}}; }
|
||||
bool unsigned_value(const Json &v, uint64_t maximum) {
|
||||
return (v.is_number_unsigned() && v.get<uint64_t>() <= maximum) ||
|
||||
(v.is_number_integer() && v.get<int64_t>() >= 0 &&
|
||||
uint64_t(v.get<int64_t>()) <= maximum);
|
||||
}
|
||||
Json provenance(const Json &fixture) {
|
||||
return {{"ok", true}, {"schema", "openbmh-post-match@1"},
|
||||
{"source", fixture.at("source")},
|
||||
{"review_id", "ui-post:" + fixture.at("fixture_id").get<std::string>()},
|
||||
{"fixture_id", fixture.at("fixture_id")},
|
||||
{"source_revision", fixture.at("source_revision")},
|
||||
{"completed_sequence", fixture.at("frames").size() - 1},
|
||||
{"world", fixture.at("world")}, {"date", fixture.at("date")},
|
||||
{"role", fixture.at("role")}, {"surface", fixture.at("surface")},
|
||||
{"duration", fixture.at("duration")}, {"field_count", fixture.at("field_count")},
|
||||
{"notice", "UI-Demo · Rückblick auf vorgegebene Ergebnisse, keine Spielsimulation"}};
|
||||
}
|
||||
Json match_events(const Json &events, const Json &match_id) {
|
||||
Json rows = Json::array();
|
||||
for (const auto &event : events)
|
||||
if (event.at("match_id") == match_id) rows.push_back(event);
|
||||
return rows;
|
||||
}
|
||||
const Json &match_snapshot(const Json &frame, const Json &match_id) {
|
||||
return *std::find_if(frame.at("matches").begin(), frame.at("matches").end(),
|
||||
[&](const auto &m) { return m.at("match_id") == match_id; });
|
||||
}
|
||||
Json report(const Json &fixture, const Json &match, int minute) {
|
||||
const auto &frames = fixture.at("frames");
|
||||
const Json *frame = &frames.front();
|
||||
for (const auto &candidate : frames) {
|
||||
if (candidate.at("minute").get<int>() > minute) break;
|
||||
frame = &candidate;
|
||||
}
|
||||
const auto ¤t = match_snapshot(*frame, match.at("id"));
|
||||
const auto &final = match_snapshot(frames.back(), match.at("id"));
|
||||
auto out = provenance(fixture);
|
||||
out["kind"] = "report";
|
||||
out["match_id"] = match.at("id");
|
||||
out["match"] = match;
|
||||
out["home"] = match.at("home"); out["away"] = match.at("away");
|
||||
out["minute"] = minute; out["recorded_minute"] = frame->at("minute");
|
||||
out["sequence"] = frame->at("sequence"); out["phase"] = frame->at("phase");
|
||||
out["final"] = final; out["final_score"] = final.at("score");
|
||||
for (auto key : {"score", "chances", "yellow", "red", "players", "standings"})
|
||||
out[key] = current.at(key);
|
||||
// Raw events retain their original IDs/text/side/score. The recording names
|
||||
// no player actor, assist or exact playing-time/ratings, so none is inferred.
|
||||
out["events"] = match_events(frame->at("events"), match.at("id"));
|
||||
out["timeline"] = match_events(frames.back().at("events"), match.at("id"));
|
||||
out["attendance"] = nullptr;
|
||||
out["attendance_reason"] = "not_recorded";
|
||||
out["actor"] = nullptr; out["assists"] = nullptr; out["ratings"] = nullptr;
|
||||
out["playing_minutes"] = nullptr;
|
||||
return out;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Json make_demo_post_match(const Json &fixture, size_t completed_sequence) {
|
||||
try {
|
||||
if (!valid_live_fixture(fixture)) return failure("invalid_post_match_fixture");
|
||||
const auto &last = fixture.at("frames").back();
|
||||
if (completed_sequence != fixture.at("frames").size() - 1 ||
|
||||
last.at("phase") != "finished" || last.at("minute") != fixture.at("duration"))
|
||||
return failure("post_match_not_finished");
|
||||
auto out = provenance(fixture);
|
||||
out["kind"] = "review";
|
||||
out["owners"] = fixture.at("owners");
|
||||
out["tabs"] = fixture.at("role") == "club" && fixture.at("surface") == "outdoor"
|
||||
? Json::array({"results", "report", "eleven", "overview", "table"})
|
||||
: Json::array({"results", "report", "overview"});
|
||||
out["matches"] = Json::array(); out["tables"] = Json::array();
|
||||
Json totals = {{"games", fixture.at("matches").size()}, {"goals", 0},
|
||||
{"yellow", 0}, {"red", 0}, {"chances", 0},
|
||||
{"attendance", nullptr}, {"attendance_reason", "not_recorded"},
|
||||
{"scope", "recorded_human_matches"}};
|
||||
for (const auto &match : fixture.at("matches")) {
|
||||
const auto &final = match_snapshot(last, match.at("id"));
|
||||
auto row = match;
|
||||
row["final"] = final;
|
||||
row["events"] = match_events(last.at("events"), match.at("id"));
|
||||
row["attendance"] = nullptr; row["attendance_reason"] = "not_recorded";
|
||||
out["matches"].push_back(std::move(row));
|
||||
for (auto key : {"yellow", "red", "chances"})
|
||||
totals[key] = totals.at(key).get<int>() + final.at(key)[0].get<int>() + final.at(key)[1].get<int>();
|
||||
totals["goals"] = totals.at("goals").get<int>() + final.at("score")[0].get<int>() + final.at("score")[1].get<int>();
|
||||
// Preserve declared final table snapshots exactly. Several human matches
|
||||
// can refer to one recorded table; do not recalculate a season standings.
|
||||
if (out.at("tabs").back() == "table" && !final.at("standings").empty()) {
|
||||
auto table = std::find_if(out["tables"].begin(), out["tables"].end(),
|
||||
[&](const auto &t) { return t.at("rows") == final.at("standings"); });
|
||||
if (table != out["tables"].end()) table->at("match_ids").push_back(match.at("id"));
|
||||
else out["tables"].push_back({{"id", "ui-table:" + match.at("id").get<std::string>()},
|
||||
{"match_ids", Json::array({match.at("id")})},
|
||||
{"rows", final.at("standings")},
|
||||
{"notice", "Vorgegebener POC-Tabellenstand der Liveaufnahme"},
|
||||
{"wins", nullptr}, {"draws", nullptr}, {"losses", nullptr}});
|
||||
}
|
||||
}
|
||||
out["overview"] = std::move(totals);
|
||||
out["eleven"] = {{"available", false}, {"reason", "not_recorded"}, {"rows", Json::array()}};
|
||||
out["unknown_fields"] = Json::array({"attendance", "actor", "assists", "ratings", "playing_minutes", "eleven", "wins", "draws", "losses"});
|
||||
return out;
|
||||
} catch (const std::exception &) { return failure("invalid_post_match_fixture"); }
|
||||
}
|
||||
|
||||
Json query_demo_post_match(const Json &fixture, const Json &q) {
|
||||
try {
|
||||
if (!q.is_object()) return failure("invalid_post_match_query");
|
||||
for (const auto &[key, value] : q.items()) {
|
||||
(void)value;
|
||||
if (key != "kind" && key != "completed_sequence" && key != "fixture_id" &&
|
||||
key != "revision" && key != "match_id" && key != "minute")
|
||||
return failure("invalid_post_match_query");
|
||||
}
|
||||
if (!q.contains("completed_sequence") ||
|
||||
!unsigned_value(q.at("completed_sequence"), std::numeric_limits<size_t>::max()))
|
||||
return failure("invalid_post_match_sequence");
|
||||
auto review = make_demo_post_match(fixture, q.at("completed_sequence").get<size_t>());
|
||||
if (!review.value("ok", false)) return review;
|
||||
if (q.contains("revision") && (!unsigned_value(q.at("revision"), UINT64_MAX) ||
|
||||
q.at("revision") != fixture.at("source_revision")))
|
||||
return failure("stale_post_match_revision");
|
||||
if (q.contains("fixture_id") && (!q.at("fixture_id").is_string() ||
|
||||
q.at("fixture_id") != fixture.at("fixture_id")))
|
||||
return failure("stale_post_match_fixture");
|
||||
const auto kind = q.value("kind", "review");
|
||||
if (kind == "review")
|
||||
return q.contains("match_id") || q.contains("minute") ? failure("invalid_post_match_query") : review;
|
||||
if (kind != "report") return failure("invalid_post_match_query");
|
||||
const auto id = q.contains("match_id") ? q.at("match_id") : fixture.at("matches").front().at("id");
|
||||
if (!id.is_string()) return failure("invalid_post_match_id");
|
||||
const auto match = std::find_if(fixture.at("matches").begin(), fixture.at("matches").end(),
|
||||
[&](const auto &m) { return m.at("id") == id; });
|
||||
if (match == fixture.at("matches").end()) return failure("invalid_post_match_id");
|
||||
const auto minute = q.contains("minute") ? q.at("minute") : fixture.at("duration");
|
||||
if (!unsigned_value(minute, fixture.at("duration").get<uint64_t>()))
|
||||
return failure("invalid_post_match_minute");
|
||||
return report(fixture, *match, minute.get<int>());
|
||||
} catch (const std::exception &) { return failure("invalid_post_match_query"); }
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Read-only review of a completed, validated UI recording. Passing its last
|
||||
// sequence acknowledges UI playback completion, never engine match completion.
|
||||
// The recording, its identities and every original outcome remain unchanged.
|
||||
Json make_demo_post_match(const Json &live_fixture, size_t completed_sequence);
|
||||
// {kind:"review"|"report", completed_sequence:uint,
|
||||
// fixture_id?:string, revision?:uint, match_id?:string, minute?:uint}
|
||||
// match_id/minute are report-only. Minute seeking selects an existing recorded
|
||||
// frame; it does not interpolate scores, calculate ratings or execute actions.
|
||||
Json query_demo_post_match(const Json &live_fixture, const Json &request);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include "modern/ui/demo_post_match.hpp"
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
@@ -247,6 +248,12 @@ Json DemoSource::read_statistics(const Json &request) const {
|
||||
Json DemoSource::read_live(const Json &request) const {
|
||||
return query_demo_live(*catalog_, state_, revision_, request);
|
||||
}
|
||||
Json DemoSource::read_post_match(const Json &request) const {
|
||||
// This is an explicit UI-fixture path. Do not promote it to engine authority.
|
||||
if (!request.is_object() || !request.contains("revision") || !request.contains("fixture_id"))
|
||||
return {{"ok", false}, {"error", "post_match_identity_required"}};
|
||||
return query_demo_post_match(make_demo_live(*catalog_, state_, revision_), request);
|
||||
}
|
||||
ActionResult DemoSource::apply(const Action &action) {
|
||||
if (action.revision != revision_)
|
||||
return {false, revision_, "stale_revision"};
|
||||
|
||||
@@ -41,6 +41,11 @@ public:
|
||||
virtual Json read_live(const Json &) const {
|
||||
return {{"ok", false}, {"error", "live_unavailable"}};
|
||||
}
|
||||
// An authoritative adapter must confirm its own completed match state.
|
||||
// Demo completion only acknowledges the final prerecorded presentation frame.
|
||||
virtual Json read_post_match(const Json &) const {
|
||||
return {{"ok", false}, {"error", "post_match_unavailable"}};
|
||||
}
|
||||
};
|
||||
class DemoSource final : public DataSource {
|
||||
public:
|
||||
@@ -53,6 +58,7 @@ public:
|
||||
Json read_almanac(const Json &) const override;
|
||||
Json read_statistics(const Json &) const override;
|
||||
Json read_live(const Json &) const override;
|
||||
Json read_post_match(const Json &) const override;
|
||||
void save(const fs::path &, const Json &desktop);
|
||||
Json load(const fs::path &);
|
||||
// UI continuation may retain the previous explicit-save clean baseline.
|
||||
|
||||
Reference in new issue
Block a user