The statistics as five pages of the notebook with markers of their own
Analysis (the club's season as figures and charts), course (the recorded series as curves, the seasons' finances), winners under their trophies, records (all-time table, series and records, world cups) and players (transfer history, minutes, chances). A page with several kinds shows them as tabs; the old list of kinds in the foot is gone in a career. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
9d94d05db1
commit
9f164b4d61
8 files changed
+239
-173
No files matched your search
@@ -1,35 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The club's running season as 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.
|
||||
// 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 = "<nav class=\"bank-tabs an-tabs\" aria-label=\"Statistikansicht\">";
|
||||
std::string out = "<nav class=\"pg-tabs\" aria-label=\"Statistikansicht\">";
|
||||
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 2>{{{"analysis", "Vereinsanalyse"}, {"archive", "Archiv"}}})
|
||||
out += btn("statistics-mode", label, std::string("bank-tab") + (current == id ? " selected" : ""),
|
||||
"id=\"statistics-mode-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (current == id ? "true" : "false") + "\"");
|
||||
out += btn("statistics-mode", "<span>" + std::string(label) + "</span>", current == id ? "on" : "", "id=\"statistics-mode-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (current == id ? "true" : "false") + "\"");
|
||||
return out + "</nav>";
|
||||
};
|
||||
std::string out = "<section class=\"statistics-native an-screen\"><div class=\"an-head\"><div class=\"bank-brand\"><strong>Statistiken</strong><span>Vereinsanalyse</span></div>" + tabs("analysis") + "</div>";
|
||||
(void)tabs;
|
||||
std::string out = "<section class=\"pg-page statistics-native\"><div class=\"pg-row\">";
|
||||
const auto &data = engine_analysis_value_;
|
||||
if (!data.is_object() || !data.value("available", false))
|
||||
return out + "<p class=\"an-empty\">" + std::string(engine_busy_ ? "Die Auswertung wird geladen …" : "In dieser Saison ist noch kein Spiel aufgezeichnet.") + "</p></section>";
|
||||
const auto one = [](double value) {
|
||||
return out + "</div><div class=\"pg-empty\">" + std::string(engine_busy_ ? "Die Auswertung wird geladen …" : "In dieser Saison ist noch kein Spiel aufgezeichnet.") + "</div></section>";
|
||||
const auto fixed = [](double value, int digits) {
|
||||
std::ostringstream text;
|
||||
text << std::fixed << std::setprecision(1) << value;
|
||||
text << std::fixed << std::setprecision(digits) << value;
|
||||
auto result = text.str();
|
||||
std::replace(result.begin(), result.end(), '.', ',');
|
||||
return result;
|
||||
};
|
||||
const auto two = [](double value) {
|
||||
std::ostringstream text;
|
||||
text << std::fixed << std::setprecision(2) << value;
|
||||
auto result = text.str();
|
||||
std::replace(result.begin(), result.end(), '.', ',');
|
||||
return result;
|
||||
};
|
||||
const auto card = [](const std::string &css, double x, double y, double w, double h, const std::string &title, const std::string &body) {
|
||||
return "<div class=\"an-card " + css + "\" style=\"" + rect(x, y, w, h) + "\"><h3>" + title + "</h3>" + body + "</div>";
|
||||
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 "<div class=\"pg-panel pg-col " + css + "\" style=\"" + pg_css("gap:6px;padding:10px 14px;") + "\">" + pg_kicker(title) + body + "</div>";
|
||||
};
|
||||
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());
|
||||
@@ -40,119 +35,85 @@ std::string App::render_statistics_analysis() {
|
||||
const double conversion = chances_for ? goals_for * 100.0 / chances_for : 0;
|
||||
const double league_conversion = league.at("chances").get<int64_t>() ? league.at("goals").get<double>() * 100.0 / league.at("chances").get<double>() : 0;
|
||||
const int year = data.value("year", 0);
|
||||
out += "<p class=\"an-sub\">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<std::string>())) + " · alle Pflicht- und Testspiele aus dem Spielarchiv</p>";
|
||||
out += "<span class=\"pg-mut pg-grow\">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<std::string>())) + " · alle Pflicht- und Testspiele aus dem Spielarchiv</span></div>";
|
||||
|
||||
// the figures a manager asks for first
|
||||
const std::array<std::array<std::string, 3>, 6> tiles{{
|
||||
{std::to_string(played), "Spiele", std::to_string(league_played) + " in der Liga"},
|
||||
{two(pace), "Punkte je Ligaspiel", "Liga-Schnitt " + two(league_pace)},
|
||||
{std::to_string(goals_for), "Tore", played ? one(double(goals_for) / played) + " je Spiel" : ""},
|
||||
{std::to_string(goals_against), "Gegentore", played ? one(double(goals_against) / played) + " je Spiel" : ""},
|
||||
{one(conversion) + " %", "Chancenverwertung", "Liga-Schnitt " + one(league_conversion) + " %"},
|
||||
{std::to_string(data.at("cards").at("yellow").get<int>()) + " / " + std::to_string(data.at("cards").at("red").get<int>()), "Gelbe / Rote Karten",
|
||||
"Gegner " + std::to_string(data.at("cards").at("yellowAgainst").get<int>()) + " / " + std::to_string(data.at("cards").at("redAgainst").get<int>())}}};
|
||||
for (size_t i = 0; i < tiles.size(); ++i)
|
||||
out += "<div class=\"an-tile\" style=\"" + rect(30 + double(i) * 428.666, 230, 408.666, 230) + "\"><strong>" + tiles[i][0] + "</strong><span>" + tiles[i][1] + "</span><small>" + tiles[i][2] + "</small></div>";
|
||||
out += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;") + "align-items:stretch;\">" + 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<int>()) + " / " + std::to_string(data.at("cards").at("red").get<int>()),
|
||||
"Gegner " + std::to_string(data.at("cards").at("yellowAgainst").get<int>()) + " / " + std::to_string(data.at("cards").at("redAgainst").get<int>())) + "</div><div class=\"pg-body\" style=\"" + pg_css("gap:10px;") + "\">";
|
||||
const std::string line = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f", grey = theme_ == "silver" ? "#82796a" : theme_ == "matchday" ? "#6d7f5b" : "#8f95a1", faint = theme_ == "midnight" ? "#f0ece21c" : "#201e1d1a";
|
||||
|
||||
// points after each league match beside the league's average pace; below it every match
|
||||
{
|
||||
std::string body;
|
||||
if (league_played > 1) {
|
||||
const double top = std::max({points.back().get<double>(), 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; };
|
||||
const std::string line = theme_ == "silver" ? "#25617a" : "#9ac7d8", gold = theme_ == "silver" ? "#9a7a3a" : "#d9bd7c", faint = theme_ == "silver" ? "#4a433430" : "#dfeaf530";
|
||||
std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1440 320\"><defs><linearGradient id=\"under\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"" + line +
|
||||
"\" stop-opacity=\".30\"/><stop offset=\"1\" stop-color=\"" + line + "\" stop-opacity=\".02\"/></linearGradient></defs>";
|
||||
for (int row = 0; row < 4; ++row) svg += "<line x1=\"20\" y1=\"" + scalar(20 + row * 93.3) + "\" x2=\"1420\" y2=\"" + scalar(20 + row * 93.3) + "\" stroke=\"" + faint + "\" stroke-width=\"2\"/>";
|
||||
std::string course = scalar(px(0)) + "," + scalar(py(0)) + " ";
|
||||
for (int i = 0; i < league_played; ++i) course += scalar(px(i + 1)) + "," + scalar(py(points[size_t(i)].get<double>())) + " ";
|
||||
svg += "<polygon points=\"" + course + scalar(px(league_played)) + ",300\" fill=\"url(#under)\"/><line x1=\"" + scalar(px(0)) + "\" y1=\"" + scalar(py(0)) + "\" x2=\"" + scalar(px(league_played)) + "\" y2=\"" +
|
||||
scalar(py(league_pace * league_played)) + "\" stroke=\"" + gold + "\" stroke-width=\"5\" stroke-dasharray=\"16 12\"/><polyline points=\"" + course + "\" fill=\"none\" stroke=\"" + line +
|
||||
"\" stroke-width=\"7\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><circle cx=\"" + scalar(px(league_played)) + "\" cy=\"" + scalar(py(points.back().get<double>())) + "\" r=\"11\" fill=\"" + line + "\"/></svg>";
|
||||
body += "<div class=\"an-course\">" + picture(renderer_.diagram("analysis-course", svg, 2880), 1440, 320) + "</div><div class=\"an-axis\"><span>1. Spieltag</span><div class=\"an-legend\"><span class=\"key own\"></span><span>" +
|
||||
std::to_string(points.back().get<int>()) + " Punkte</span><span class=\"key pace\"></span><span>Liga-Schnitt " + std::to_string(int(std::lround(league_pace * league_played))) + "</span></div><span>" +
|
||||
std::to_string(league_played) + ". Spieltag</span></div>";
|
||||
} else body += "<p class=\"an-none\">Der Punkteverlauf beginnt mit dem zweiten Ligaspiel.</p>";
|
||||
body += "<h4>Alle Spiele · Höhe nach Tordifferenz</h4><div class=\"an-strip\">";
|
||||
const size_t shown = std::min<size_t>(matches.size(), 40), start = matches.size() - shown;
|
||||
for (size_t i = start; i < matches.size(); ++i) {
|
||||
const auto &m = matches[i];
|
||||
const int balance = m.at("goalsFor").get<int>() - m.at("goalsAgainst").get<int>();
|
||||
const double height = std::min(std::abs(balance), 4) * 22.0;
|
||||
const auto label = esc(std::string(m.at("home").get<bool>() ? "Heim" : "Auswärts") + " gegen " + m.at("opponent").get<std::string>() + " " + std::to_string(m.at("goalsFor").get<int>()) + ":" + std::to_string(m.at("goalsAgainst").get<int>()));
|
||||
body += "<div class=\"an-strip-column\" title=\"" + label + "\"><div class=\"rise\">" + (balance > 0 ? "<div class=\"bar won\" style=\"height:" + scalar(height) + "dp;\"></div>" : std::string()) +
|
||||
"</div><div class=\"mid " + (balance ? "" : "drawn") + "\"></div><div class=\"fall\">" + (balance < 0 ? "<div class=\"bar lost\" style=\"height:" + scalar(height) + "dp;\"></div>" : std::string()) + "</div></div>";
|
||||
// --- 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<double>(), 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 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1440 320\">";
|
||||
for (int row = 0; row < 4; ++row) svg += "<line x1=\"20\" y1=\"" + scalar(20 + row * 93.3) + "\" x2=\"1420\" y2=\"" + scalar(20 + row * 93.3) + "\" stroke=\"" + faint + "\" stroke-width=\"2\"/>";
|
||||
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<double>())) + " ";
|
||||
dots += "<circle cx=\"" + scalar(px(i + 1)) + "\" cy=\"" + scalar(py(points[size_t(i)].get<double>())) + "\" r=\"8\" fill=\"" + line + "\"/>";
|
||||
}
|
||||
out += card("an-points", 30, 490, 1500, 710, "Punkteverlauf", body + "</div>");
|
||||
svg += "<line x1=\"" + scalar(px(0)) + "\" y1=\"" + scalar(py(0)) + "\" x2=\"" + scalar(px(league_played)) + "\" y2=\"" + scalar(py(league_pace * league_played)) + "\" stroke=\"" + grey + "\" stroke-width=\"5\" stroke-dasharray=\"14 12\"/><polyline points=\"" + path +
|
||||
"\" fill=\"none\" stroke=\"" + line + "\" stroke-width=\"7\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/>" + dots + "</svg>";
|
||||
course = "<div class=\"pg-legend\"><span class=\"pg-legend-item\"><span class=\"pg-legend-mark\" style=\"height:9dp;background-color:" + line + ";\"></span><span>" + std::to_string(points.back().get<int>()) +
|
||||
" Punkte</span></span><span class=\"pg-legend-item\"><span class=\"pg-legend-mark\" style=\"height:9dp;background-color:" + grey + ";\"></span><span>Liga-Schnitt " + std::to_string(int(std::lround(league_pace * league_played))) +
|
||||
"</span></span></div><div class=\"st-course\">" + picture(renderer_.diagram("analysis-course-" + theme_, svg, 2880), 1070, 238) + "</div><div class=\"pg-row pg-mut\" style=\"justify-content:space-between;font-size:" + pg(11) + ";\"><span>1. Spieltag</span><span>" +
|
||||
std::to_string(league_played) + ". Spieltag</span></div>";
|
||||
} else course = "<span class=\"pg-mut\" style=\"display:block;\">Der Punkteverlauf beginnt mit dem zweiten Ligaspiel.</span>";
|
||||
course += "<span class=\"pg-mut\" style=\"display:block;font-size:" + pg(11.5) + ";\">Alle Spiele · Höhe nach Tordifferenz</span><div class=\"st-strip\">";
|
||||
for (size_t i = matches.size() - std::min<size_t>(matches.size(), 40); i < matches.size(); ++i) {
|
||||
const auto &m = matches[i];
|
||||
const int balance = m.at("goalsFor").get<int>() - m.at("goalsAgainst").get<int>();
|
||||
const double height = std::max(7.0, std::min(std::abs(balance), 4) * 12.0);
|
||||
course += "<div class=\"st-strip-column\" title=\"" + esc(std::string(m.at("home").get<bool>() ? "Heim" : "Auswärts") + " gegen " + m.at("opponent").get<std::string>() + " " + std::to_string(m.at("goalsFor").get<int>()) + ":" + std::to_string(m.at("goalsAgainst").get<int>())) +
|
||||
"\"><div class=\"" + (balance > 0 ? "won" : balance < 0 ? "lost" : "drawn") + "\" style=\"height:" + scalar(height) + "dp;" + (balance >= 0 ? "bottom:50%;" : "top:50%;") + "\"></div></div>";
|
||||
}
|
||||
|
||||
// home and away, and what the first goal decided
|
||||
{
|
||||
const auto bar = [&](const std::string &label, const Json &r, const std::string &extra) {
|
||||
const int games = r.at("played");
|
||||
std::string row = "<div class=\"an-record\"><div class=\"an-record-head\"><span>" + label + "</span><strong>" + extra + "</strong></div><div class=\"an-stack\">";
|
||||
for (const auto &[key, css, letter] : std::array<std::tuple<const char *, const char *, const char *>, 3>{{{"won", "won", "S"}, {"drawn", "drawn", "U"}, {"lost", "lost", "N"}}}) {
|
||||
const int count = r.at(key);
|
||||
if (count) row += "<div class=\"" + std::string(css) + "\" style=\"width:" + scalar(count * 100.0 / std::max(1, games)) + "%;\"><span>" + std::to_string(count) + " " + letter + "</span></div>";
|
||||
}
|
||||
if (!games) row += "<div class=\"none\" style=\"width:100%;\"><span>kein Spiel</span></div>";
|
||||
return row + "</div></div>";
|
||||
};
|
||||
const auto ppg = [&](const Json &r) { return r.at("played").get<int>() ? two(r.at("points").get<double>() / r.at("played").get<double>()) + " Punkte je Spiel · " + std::to_string(r.at("goalsFor").get<int>()) + ":" + std::to_string(r.at("goalsAgainst").get<int>()) + " Tore" : std::string("—"); };
|
||||
const auto share = [&](const Json &r) { return r.at("played").get<int>() ? std::to_string(int(std::lround(r.at("won").get<double>() * 100 / r.at("played").get<double>()))) + " % gewonnen" : std::string("—"); };
|
||||
out += card("an-records", 1550, 490, 1032, 710, "Heim und Auswärts",
|
||||
bar("Heim", data.at("home"), ppg(data.at("home"))) + bar("Auswärts", data.at("away"), ppg(data.at("away"))) +
|
||||
"<h4>Das erste Tor</h4>" + bar("Selbst zuerst getroffen", data.at("firstFor"), share(data.at("firstFor"))) +
|
||||
bar("Gegner trifft zuerst", data.at("firstAgainst"), share(data.at("firstAgainst"))));
|
||||
}
|
||||
|
||||
// goals by quarter of an hour: scored upwards, conceded downwards
|
||||
course += "</div>";
|
||||
int best_bucket = 0, worst_bucket = 0;
|
||||
std::string minutes = "<div class=\"pg-legend\"><span class=\"pg-legend-item\"><span class=\"pg-legend-mark st-won\"></span><span>erzielt</span></span><span class=\"pg-legend-item\"><span class=\"pg-legend-mark st-lost\"></span><span>kassiert</span></span></div><div class=\"st-minutes\">";
|
||||
{
|
||||
const auto &buckets = data.at("buckets");
|
||||
int greatest = 1;
|
||||
for (const auto &b : buckets) greatest = std::max({greatest, b.at("for").get<int>(), b.at("against").get<int>()});
|
||||
std::string body = "<div class=\"an-minutes\">";
|
||||
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<int>()) best_bucket = int(i);
|
||||
if (conceded > buckets[size_t(worst_bucket)].at("against").get<int>()) worst_bucket = int(i);
|
||||
const int from = buckets[i].at("from");
|
||||
body += "<div class=\"an-minute\"><div class=\"rise\"><span>" + std::to_string(scored) + "</span><div class=\"bar won\" style=\"height:" + scalar(scored * 190.0 / greatest) + "dp;\"></div></div><strong>" +
|
||||
std::to_string(from) + "–" + (i + 1 == buckets.size() ? "Ende" : std::to_string(from + 14)) + "</strong><div class=\"fall\"><div class=\"bar lost\" style=\"height:" + scalar(conceded * 190.0 / greatest) +
|
||||
"dp;\"></div><span>" + std::to_string(conceded) + "</span></div></div>";
|
||||
minutes += "<div class=\"st-minute\"><div class=\"st-minute-bars\"><div class=\"st-won\" style=\"height:" + scalar(std::max(4.0, scored * 250.0 / greatest)) + "dp;\"></div><div class=\"st-lost\" style=\"height:" + scalar(std::max(4.0, conceded * 250.0 / greatest)) +
|
||||
"dp;\"></div></div><small>" + std::to_string(from) + "–" + (i + 1 == buckets.size() ? "Ende" : std::to_string(from + 14)) + "</small><strong>" + std::to_string(scored) + " : " + std::to_string(conceded) + "</strong></div>";
|
||||
}
|
||||
out += card("an-minutes-card", 30, 1230, 960, 620, "Tore nach Spielminute", body + "</div><div class=\"an-axis\"><div class=\"an-legend\"><span class=\"key won\"></span><span>erzielt</span><span class=\"key lost\"></span><span>kassiert</span></div></div>");
|
||||
}
|
||||
out += "<div class=\"pg-col\" style=\"flex:1.5;" + pg_css("gap:10px;") + "\">" + panel("Punkteverlauf", course, "st-course-panel") + panel("Tore nach Spielminute", minutes + "</div>") + "</div>";
|
||||
|
||||
// the club's scorers: goals solid, assists light
|
||||
{
|
||||
const auto &scorers = data.at("scorers");
|
||||
int greatest = 1;
|
||||
for (const auto &row : scorers) greatest = std::max(greatest, row.at("goals").get<int>() + row.at("assists").get<int>());
|
||||
std::string body;
|
||||
for (size_t i = 0; i < scorers.size() && i < 7; ++i) {
|
||||
const auto &row = scorers[i];
|
||||
const int goals = row.at("goals"), assists = row.at("assists");
|
||||
body += "<div class=\"an-scorer\"><span class=\"name\">" + esc(row.at("name").get<std::string>()) + "</span><div class=\"an-scorer-bar\"><div class=\"goals\" style=\"width:" + scalar(goals * 100.0 / greatest) +
|
||||
"%;\"></div><div class=\"assists\" style=\"width:" + scalar(assists * 100.0 / greatest) + "%;\"></div></div><span class=\"sum\">" + std::to_string(goals) + " T · " + std::to_string(assists) + " V</span></div>";
|
||||
}
|
||||
if (scorers.empty()) body = "<p class=\"an-none\">Noch kein Tor erzielt.</p>";
|
||||
out += card("an-scorers", 1010, 1230, 800, 620, "Tore und Vorlagen", body);
|
||||
}
|
||||
|
||||
// how the goals came about, and a reading of the season
|
||||
// --- 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 = "<div class=\"pg-row\" style=\"" + pg_css("gap:10px;") + "\"><strong style=\"display:block;flex:none;width:" + pg(74) + ";\">" + label + "</strong><div class=\"st-stack\">";
|
||||
for (const auto &[key, css, letter] : std::array<std::tuple<const char *, const char *, const char *>, 3>{{{"won", "won", "S"}, {"drawn", "drawn", "U"}, {"lost", "lost", "N"}}})
|
||||
if (const int count = r.at(key); count) row += "<div class=\"" + std::string(css) + "\" style=\"flex:" + std::to_string(count) + ";\"><span>" + std::to_string(count) + " " + letter + "</span></div>";
|
||||
if (!games) row += "<div class=\"none\" style=\"flex:1;\"><span>kein Spiel</span></div>";
|
||||
return row + "</div><span class=\"pg-r\" style=\"display:block;flex:none;width:" + pg(96) + ";\">" + (games ? two(r.at("points").get<double>() / games) + " Pkt./Sp." : std::string("—")) + "</span></div>";
|
||||
};
|
||||
const auto first = [&](const std::string &label, const Json &r) {
|
||||
const int games = r.at("played");
|
||||
return "<div class=\"pg-kv\"><span>" + label + "</span><strong>" + std::to_string(games) + (games == 1 ? " Spiel" : " Spiele") + " · " + (games ? std::to_string(int(std::lround(r.at("won").get<double>() * 100 / games))) + " % gewonnen" : std::string("—")) + "</strong></div>";
|
||||
};
|
||||
std::string kinds_body;
|
||||
{
|
||||
const auto &kinds = data.at("kinds");
|
||||
constexpr std::array<const char *, 4> names{"Aus dem Spiel", "Elfmeter / Freistoß", "Nachschuss", "Nach Ecke"};
|
||||
int greatest = 1;
|
||||
for (const auto &k : kinds) greatest = std::max(greatest, k.at("for").get<int>());
|
||||
std::string body;
|
||||
int total = 0;
|
||||
for (const auto &k : kinds) total += k.at("for").get<int>();
|
||||
for (size_t i = 0; i < kinds.size() && i < 4; ++i)
|
||||
body += "<div class=\"an-kind\"><span class=\"name\">" + std::string(names[i]) + "</span><div class=\"bank-part-track\"><div style=\"width:" + scalar(kinds[i].at("for").get<int>() * 100.0 / greatest) +
|
||||
"%;\"></div></div><span class=\"sum\">" + std::to_string(kinds[i].at("for").get<int>()) + "</span></div>";
|
||||
kinds_body += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;") + "\"><span style=\"display:block;flex:none;width:" + pg(140) + ";\">" + std::string(names[i]) + "</span>" + pg_bar(kinds[i].at("for").get<int>() * 100.0 / std::max(1, total)) +
|
||||
"<strong class=\"pg-r\" style=\"display:block;flex:none;width:" + pg(28) + ";\">" + std::to_string(kinds[i].at("for").get<int>()) + "</strong></div>";
|
||||
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 (") +
|
||||
@@ -160,7 +121,26 @@ std::string App::render_statistics_analysis() {
|
||||
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) + ".";
|
||||
out += card("an-kinds", 1830, 1230, 752, 620, "Torarten", body + "<div class=\"an-reading\"><h4>Analyse</h4><p>" + reading + "</p></div>");
|
||||
kinds_body += pg_kicker("Analyse", "margin-top:6px;") + "<span class=\"st-reading\">" + esc(reading) + "</span>";
|
||||
}
|
||||
return out + "</section>";
|
||||
out += "<div class=\"pg-col\" style=\"flex:1;" + pg_css("gap:10px;") + "\">" +
|
||||
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) + "</div>";
|
||||
|
||||
// --- 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<int>() + row.at("assists").get<int>());
|
||||
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 += "<div class=\"st-scorer\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-nowrap\">" + esc(row.at("name").get<std::string>()) + "</strong><span style=\"display:block;flex:none;\">" + std::to_string(goals) + " T · " +
|
||||
std::to_string(assists) + " V</span></div><div class=\"st-scorer-bar\"><div class=\"goals\" style=\"width:" + scalar(goals * 100.0 / greatest) + "%;\"></div><div class=\"assists\" style=\"width:" + scalar(assists * 100.0 / greatest) + "%;\"></div></div></div>";
|
||||
}
|
||||
if (scorers.empty()) scorers_body = "<span class=\"pg-mut\" style=\"display:block;\">Noch kein Tor erzielt.</span>";
|
||||
}
|
||||
out += "<div class=\"pg-col\" style=\"flex:1;\">" + panel("Tore und Vorlagen", scorers_body) + "</div>";
|
||||
return out + "</div></section>";
|
||||
}
|
||||
Reference in new issue
Block a user