// SPDX-License-Identifier: GPL-3.0-only
// The club's running season as a page of figures and charts, counted by the engine from the
// almanac (read "analysis", modern::club_analysis). Bars are plain boxes so that every figure
// is type; only the points course is a drawing.
std::string App::render_statistics_analysis() {
const auto tabs = [&](const std::string ¤t) {
std::string out = "";
};
(void)tabs;
std::string out = "
";
const auto &data = engine_analysis_value_;
if (!data.is_object() || !data.value("available", false))
return out + "
" + std::string(engine_busy_ ? "Die Auswertung wird geladen …" : "In dieser Saison ist noch kein Spiel aufgezeichnet.") + "
";
const auto fixed = [](double value, int digits) {
std::ostringstream text;
text << std::fixed << std::setprecision(digits) << value;
auto result = text.str();
std::replace(result.begin(), result.end(), '.', ',');
return result;
};
const auto one = [&](double value) { return fixed(value, 1); };
const auto two = [&](double value) { return fixed(value, 2); };
const auto panel = [&](const std::string &title, const std::string &body, const std::string &css = "pg-grow") {
return "
" + pg_kicker(title) + body + "
";
};
const auto &matches = data.at("matches"), &points = data.at("points"), &league = data.at("league");
const int played = int(matches.size()), league_played = int(points.size());
const int goals_for = data.at("goals").at("for"), goals_against = data.at("goals").at("against");
const int chances_for = data.at("chances").at("for"), chances_against = data.at("chances").at("against");
const double pace = league_played ? points.back().get() / league_played : 0;
const double league_pace = league.at("matches").get() ? league.at("points").get() / (2.0 * league.at("matches").get()) : 0;
const double conversion = chances_for ? goals_for * 100.0 / chances_for : 0;
const double league_conversion = league.at("chances").get() ? league.at("goals").get() * 100.0 / league.at("chances").get() : 0;
const int year = data.value("year", 0);
out += "Saison " + std::to_string(year) + "/" + (year % 100 + 1 < 10 ? "0" : "") + std::to_string((year + 1) % 100) +
(data.value("leagueName", std::string()).empty() ? "" : " · " + esc(data.at("leagueName").get())) + " · alle Pflicht- und Testspiele aus dem Spielarchiv";
// the figures a manager asks for first
out += "
";
// --- middle: home and away with what the first goal decided, then how the goals came about ---
const auto record = [&](const std::string &label, const Json &r) {
const int games = r.at("played");
std::string row = "
" + label + "
";
for (const auto &[key, css, letter] : std::array, 3>{{{"won", "won", "S"}, {"drawn", "drawn", "U"}, {"lost", "lost", "N"}}})
if (const int count = r.at(key); count) row += "
";
};
std::string kinds_body;
{
const auto &kinds = data.at("kinds");
constexpr std::array names{"Aus dem Spiel", "Elfmeter / Freistoß", "Nachschuss", "Nach Ecke"};
int total = 0;
for (const auto &k : kinds) total += k.at("for").get();
for (size_t i = 0; i < kinds.size() && i < 4; ++i)
kinds_body += "
";
const auto &buckets = data.at("buckets");
const auto span = [&](int index) { const int from = buckets[size_t(index)].at("from"); return std::to_string(from) + ". bis " + (index == 5 ? std::string("letzten") : std::to_string(from + 14) + ".") + " Minute"; };
std::string reading = league_played ? (pace > league_pace + .15 ? "Die Mannschaft punktet über dem Liga-Schnitt (" : pace < league_pace - .15 ? "Die Mannschaft punktet unter dem Liga-Schnitt (" : "Die Mannschaft punktet im Liga-Schnitt (") +
two(pace) + " gegen " + two(league_pace) + " je Spiel). " : std::string();
if (chances_for) reading += "Aus " + std::to_string(chances_for) + " Chancen wurden " + std::to_string(goals_for) + " Tore; der Gegner kam zu " + std::to_string(chances_against) + " Chancen. ";
if (goals_for) reading += "Die meisten Tore fielen von der " + span(best_bucket) + ". ";
if (goals_against) reading += "Die meisten Gegentore fielen von der " + span(worst_bucket) + ".";
kinds_body += pg_kicker("Analyse", "margin-top:6px;") + "" + esc(reading) + "";
}
out += "