// 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 += "
" + pg_stat("Spiele", std::to_string(played), "davon Liga " + std::to_string(league_played)) + pg_stat("Punkte je Ligaspiel", two(pace), "Liga-Schnitt " + two(league_pace)) + pg_stat("Tore", std::to_string(goals_for), played ? one(double(goals_for) / played) + " je Spiel" : std::string()) + pg_stat("Gegentore", std::to_string(goals_against), played ? one(double(goals_against) / played) + " je Spiel" : std::string()) + pg_stat("Chancenverwertung", one(conversion) + " %", "Liga-Schnitt " + one(league_conversion) + " %") + pg_stat("Gelbe / Rote Karten", std::to_string(data.at("cards").at("yellow").get()) + " / " + std::to_string(data.at("cards").at("red").get()), "Gegner " + std::to_string(data.at("cards").at("yellowAgainst").get()) + " / " + std::to_string(data.at("cards").at("redAgainst").get())) + "
"; const std::string line = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f", grey = theme_ == "silver" ? "#82796a" : theme_ == "matchday" ? "#6d7f5b" : "#8f95a1", faint = theme_ == "midnight" ? "#f0ece21c" : "#201e1d1a"; // --- left: the points course with every match under it, then the goals by quarter of an hour --- std::string course; if (league_played > 1) { const double top = std::max({points.back().get(), league_pace * league_played, 3.0}) * 1.12; const auto px = [&](double match) { return 20 + match * 1400.0 / league_played; }; const auto py = [&](double value) { return 300 - value / top * 280; }; std::string svg = ""; for (int row = 0; row < 4; ++row) svg += ""; std::string path = scalar(px(0)) + "," + scalar(py(0)) + " ", dots; for (int i = 0; i < league_played; ++i) { path += scalar(px(i + 1)) + "," + scalar(py(points[size_t(i)].get())) + " "; dots += "())) + "\" r=\"8\" fill=\"" + line + "\"/>"; } svg += "" + dots + ""; course = "
" + std::to_string(points.back().get()) + " PunkteLiga-Schnitt " + std::to_string(int(std::lround(league_pace * league_played))) + "
" + picture(renderer_.diagram("analysis-course-" + theme_, svg, 2880), 1070, 238) + "
1. Spieltag" + std::to_string(league_played) + ". Spieltag
"; } else course = "Der Punkteverlauf beginnt mit dem zweiten Ligaspiel."; course += "Alle Spiele · Höhe nach Tordifferenz
"; for (size_t i = matches.size() - std::min(matches.size(), 40); i < matches.size(); ++i) { const auto &m = matches[i]; const int balance = m.at("goalsFor").get() - m.at("goalsAgainst").get(); const double height = std::max(7.0, std::min(std::abs(balance), 4) * 12.0); course += "
() ? "Heim" : "Auswärts") + " gegen " + m.at("opponent").get() + " " + std::to_string(m.at("goalsFor").get()) + ":" + std::to_string(m.at("goalsAgainst").get())) + "\">
0 ? "won" : balance < 0 ? "lost" : "drawn") + "\" style=\"height:" + scalar(height) + "dp;" + (balance >= 0 ? "bottom:50%;" : "top:50%;") + "\">
"; } course += "
"; int best_bucket = 0, worst_bucket = 0; std::string minutes = "
erzieltkassiert
"; { const auto &buckets = data.at("buckets"); int greatest = 1; for (const auto &b : buckets) greatest = std::max({greatest, b.at("for").get(), b.at("against").get()}); for (size_t i = 0; i < buckets.size(); ++i) { const int scored = buckets[i].at("for"), conceded = buckets[i].at("against"); if (scored > buckets[size_t(best_bucket)].at("for").get()) best_bucket = int(i); if (conceded > buckets[size_t(worst_bucket)].at("against").get()) worst_bucket = int(i); const int from = buckets[i].at("from"); minutes += "
" + std::to_string(from) + "–" + (i + 1 == buckets.size() ? "Ende" : std::to_string(from + 14)) + "" + std::to_string(scored) + " : " + std::to_string(conceded) + "
"; } } out += "
" + panel("Punkteverlauf", course, "st-course-panel") + panel("Tore nach Spielminute", minutes + "
") + "
"; // --- 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::to_string(count) + " " + letter + "
"; if (!games) row += "
kein Spiel
"; return row + "
" + (games ? two(r.at("points").get() / games) + " Pkt./Sp." : std::string("—")) + "
"; }; const auto first = [&](const std::string &label, const Json &r) { const int games = r.at("played"); return "
" + label + "" + std::to_string(games) + (games == 1 ? " Spiel" : " Spiele") + " · " + (games ? std::to_string(int(std::lround(r.at("won").get() * 100 / games))) + " % gewonnen" : std::string("—")) + "
"; }; 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 += "
" + std::string(names[i]) + "" + pg_bar(kinds[i].at("for").get() * 100.0 / std::max(1, total)) + "" + std::to_string(kinds[i].at("for").get()) + "
"; 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 += "
" + panel("Heim und Auswärts", record("Heim", data.at("home")) + record("Auswärts", data.at("away")) + pg_kicker("Das erste Tor", "margin-top:8px;") + first("Selbst zuerst getroffen", data.at("firstFor")) + first("Gegner trifft zuerst", data.at("firstAgainst"))) + panel("Torarten", kinds_body) + "
"; // --- right: the club's scorers, goals solid and assists light --- std::string scorers_body; { const auto &scorers = data.at("scorers"); int greatest = 1; for (const auto &row : scorers) greatest = std::max(greatest, row.at("goals").get() + row.at("assists").get()); for (size_t i = 0; i < scorers.size() && i < 12; ++i) { const auto &row = scorers[i]; const int goals = row.at("goals"), assists = row.at("assists"); scorers_body += "
" + esc(row.at("name").get()) + "" + std::to_string(goals) + " T · " + std::to_string(assists) + " V
"; } if (scorers.empty()) scorers_body = "Noch kein Tor erzielt."; } out += "
" + panel("Tore und Vorlagen", scorers_body) + "
"; return out + "
"; }