Connect native indoor standings to real season points and extend CI coverage (by Codex)
This commit is contained in:
1 parent
d30e83c0a5
commit
0842cb3458
19 files changed
+296
-20
No files matched your search
@@ -0,0 +1,77 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <set>
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void ensure(bool v, const char *message) {
|
||||
if (!v)
|
||||
throw editor::Error(message);
|
||||
}
|
||||
} // namespace
|
||||
Json engine_indoor_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &read = bundle.at("indoor-standings");
|
||||
ensure(read.value("messageType", "") == "snapshot" &&
|
||||
read.at("data").value("kind", "") == "indoor-standings",
|
||||
"Hallentabellen sind hier nicht verfügbar.");
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
for (auto *key : {"contractVersion", "careerId", "worldId", "worldRevision",
|
||||
"stateRevision", "scope"})
|
||||
ensure(read.at("meta").at(key) == meta.at(key),
|
||||
"Die Hallentabelle ist veraltet.");
|
||||
const auto &d = read.at("data");
|
||||
ensure(meta.at("scope").at("role") == "club" &&
|
||||
d.at("teamId") == meta.at("scope").at("teamId"),
|
||||
"Die Hallentabelle gehört einem anderen Verein.");
|
||||
ensure(d.at("tournaments").is_number_integer() && d.at("tournaments") >= 0 &&
|
||||
d.at("tournaments") <= 255 && d.at("rows").is_array() &&
|
||||
d.at("rows").size() == (d.at("tournaments") == 0 ? 0 : 16),
|
||||
"Unvollständige Hallenrangliste.");
|
||||
Json rows = Json::array();
|
||||
std::set<std::string> ids;
|
||||
std::set<int> ranks;
|
||||
for (const auto &row : d.at("rows")) {
|
||||
ensure(row.at("rank").is_number_integer() && row.at("rank") >= 1 &&
|
||||
row.at("rank") <= 16 &&
|
||||
ranks.insert(row.at("rank").get<int>()).second &&
|
||||
row.at("points").is_number_integer() && row.at("points") >= 0 &&
|
||||
row.at("points") <= 65535,
|
||||
"Ungültige Hallenpunkte oder Platzierung.");
|
||||
const auto &team = row.at("team");
|
||||
ensure(team.at("id").is_string() &&
|
||||
!team.at("id").get<std::string>().empty() &&
|
||||
ids.insert(team.at("id").get<std::string>()).second &&
|
||||
team.at("name").is_string(),
|
||||
"Fremde oder doppelte Hallenmannschaft.");
|
||||
rows.push_back({{"original", row.at("rank").get<int>() - 1},
|
||||
{"rank", row.at("rank")},
|
||||
{"points", row.at("points")},
|
||||
{"club", team.at("id")},
|
||||
{"team", team}});
|
||||
}
|
||||
ensure(d.at("footer").is_string() && d.at("indoor").is_boolean(),
|
||||
"Unvollständige Turnierinformation.");
|
||||
const auto &scoring = d.at("scoring");
|
||||
ensure(d.at("indoor") == scoring.is_object(),
|
||||
"Unvollständige Turnierwertung.");
|
||||
if (!scoring.is_null()) {
|
||||
ensure(scoring.at("value").is_number_integer() &&
|
||||
scoring.at("value") >= 0 && scoring.at("value") <= 255 &&
|
||||
scoring.at("places").is_array() &&
|
||||
scoring.at("places").size() == 4,
|
||||
"Ungültige Turnierwertung.");
|
||||
std::set<int> places;
|
||||
for (const auto &place : scoring.at("places"))
|
||||
ensure(place.at("rank").is_number_integer() && place.at("rank") >= 1 &&
|
||||
place.at("rank") <= 4 &&
|
||||
places.insert(place.at("rank").get<int>()).second &&
|
||||
place.at("points").is_number_integer() &&
|
||||
place.at("points") >= 0 && place.at("points") <= 65535,
|
||||
"Ungültige Platzpunkte.");
|
||||
}
|
||||
return {{"rows", rows},
|
||||
{"tournaments", d.at("tournaments")},
|
||||
{"footer", d.at("footer")},
|
||||
{"scoring", scoring}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
Reference in new issue
Block a user