Files
Dreierpack-Manager/src/modern/ui/statistics_screens.inc
T
MichaelandClaude Fable 5.2 8f607a9d89 A club analysis in the statistics: the season as charts; larger trophies
The engine counts the manager's club's running season from the almanac (read
"analysis"): matches, the points course beside the league's pace, records by venue,
what the first goal decided, goals by quarter of an hour, scorers and goal kinds. The
statistics open with it; the archive tables keep their place with larger type and
trophies.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 23:10:50 +01:00

189 lines
15 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
namespace {
std::string statistics_text(const std::string &text) {
return "<span class=\"statistics-cell-text\">"+esc(text)+"</span>";
}
std::string statistics_scroll_key(const Json &data) {
return std::to_string(data.value("section",7))+":"+std::to_string(data.value("category",0))+":"+std::to_string(data.value("country",0))+":"+data.value("winner_country","");
}
} // namespace
std::vector<std::pair<std::string,std::string>> App::statistics_picker_items(const std::string &kind) const {
std::vector<std::pair<std::string,std::string>> result;
if(!source_&&!engine_mode_)return result;
const auto data=statistics_data();
if(!data.value("ok",false))return result;
const int section=data.at("section").get<int>();
if(kind=="stat-section") {
const auto &names=data.at("sections");
for(size_t i=0;i<names.size();++i)result.emplace_back(std::to_string(i),names[i].get<std::string>());
} else if(kind=="stat-category"&&section==7)result={{"0","National"},{"1","International"},{"5","Hallenmasters"}};
else if(kind=="winner-country"&&section==7&&data.at("category")==0) {
for(const auto &nation:data.at("countries"))result.emplace_back(nation.at("id").get<std::string>(),nation.at("name").get<std::string>());
} else if(kind=="stat-country"&&section==3) {
for(const auto &nation:data.at("eternal_countries"))
result.emplace_back(std::to_string(nation.at("value").get<int>()),nation.at("name").get<std::string>());
} else if(kind=="stat-country"&&section==4) {
const auto &names=data.at("world_views");
for(size_t i=0;i<names.size();++i)result.emplace_back(std::to_string(i),names[i].get<std::string>());
}
return result;
}
std::string App::statistics_picker_value(const std::string &kind) const {
if(!source_&&!engine_mode_)return {};
const auto data=statistics_data();
if(!data.value("ok",false))return {};
if(kind=="winner-country")return data.value("winner_country","");
const auto key=kind=="stat-section"?"section":kind=="stat-category"?"category":"country";
return std::to_string(data.value(key,0));
}
void App::statistics_remember_scroll() {
if(auto *list=element("statistics-list")) {
const auto key=list->GetAttribute<Rml::String>("data-scroll-key","");
if(!key.empty())statistics_scrolls_[key]=list->GetScrollTop();
}
}
void App::statistics_restore_scroll() {
if(menu_!="statistics"||!statistics_restore_pending_)return;
statistics_restore_pending_=false;
if(auto *list=element("statistics-list")) {
const auto key=list->GetAttribute<Rml::String>("data-scroll-key","");
if(const auto i=statistics_scrolls_.find(key);i!=statistics_scrolls_.end()&&i->is_number())list->SetScrollTop(i->get<float>());
}
}
std::string App::statistics_trophy_asset(const std::string &id) const {
if(id.empty())return {};
// Competition pictures belong to world content. The deterministic demo uses
// semantic trophy roles; an engine adapter can supply a logical asset key.
// Fixed prototype artwork is only a fallback, never an OBW requirement.
if (world_) {
if (id.starts_with("asset:")) {
if (world_->find("assets", id)) return id;
if (world_->find("assets", "asset:comp/generic/trophy"))
return "asset:comp/generic/trophy";
return {};
}
const auto key = "asset:comp/" + id + "/trophy";
if (world_->find("assets", key)) return key;
}
if(gui_.contains("trophy."+id))return "trophy."+id;
for(const auto &[key,item]:gui_.items().items()) {
if(!item.is_object())continue;
const auto file=item.value("file","");
const auto base=fs::path(file).filename().string();
if(base==id+"-v1.png"||base==id+"-v2.png")return key;
}
return {};
}
std::string App::render_statistics() {
statistics_remember_scroll();
if((!source_&&!engine_mode_)||!world_)return "<p>Statistiken sind nicht verfügbar.</p>";
if(engine_mode_&&statistics_mode_=="analysis")return render_statistics_analysis()+render_report_detail();
const auto data=statistics_data();
if(!data.value("ok",false))return "<p>Statistiken sind nicht verfügbar.</p>";
const int section=data.at("section").get<int>(),category=data.at("category").get<int>();
const bool winners=section==7,minutes=section==8,finals=section==4&&data.at("country")==3;
std::string out="<section class=\"statistics-native statistics-section-"+std::to_string(section)+(finals?" statistics-finals":"")+"\"><div class=\"statistics-panel\">"+(engine_mode_?btn("statistics-mode","‹ Vereinsanalyse","statistics-back","id=\"statistics-mode-analysis\" data-id=\"analysis\""):std::string())+"<h2 class=\"statistics-heading\">"+esc(data.at("title").get<std::string>())+"</h2>";
if(winners)out+="<p class=\"statistics-winner-note\">"+statistics_text(data.value("note",""))+"</p>";
if(engine_mode_&&!data.value("available",false)){out+="<p class=\"statistics-empty\">"+statistics_text(data.value("reason","")=="not_recorded"?"Diese Auswertung wurde in der Karriere noch nicht aufgezeichnet.":"Keine Statistikdaten für diese Auswahl vorhanden.")+"</p>";}
else if(section==2) {
std::string svg="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3400 780' width='2496' height='812' preserveAspectRatio='none'><path d='M30 10V730H3380' fill='none' stroke='"+std::string(theme_=="silver"?"#627c8f":"#7d9aae")+"' stroke-width='3'/>";
const auto &series=data.at("series");
for(const auto &curve:series)if(curve.at("active")==true) {
svg+="<polyline points='";
for(const auto &point:curve.at("points"))svg+=scalar(point[0].get<double>())+","+scalar(point[1].get<double>())+" ";
svg+="' fill='none' stroke='"+curve.at("color").get<std::string>()+"' stroke-width='7'/>";
}
svg+="</svg>";
out+="<div class=\"statistics-graph\" role=\"img\" aria-label=\""+std::string(engine_mode_?"Aufgezeichnete Verlaufsreihen · ":"Sechs fiktive Verlaufsreihen · ")+std::string(data.at("absolute")==true?"absolut":"relativ")+"\">"+picture(renderer_.diagram("statistics-analytics",svg,5100),2496,812)+"</div><div class=\"statistics-series\">";
for(size_t k=0;k<series.size();++k) {
const auto &curve=series[k];const bool active=curve.at("active").get<bool>();
out+=btn("statistics-curve","<span class=\"statistics-series-dot\" style=\"background-color:"+curve.at("color").get<std::string>()+";\"></span><span class=\"statistics-series-label\">"+esc(curve.at("name").get<std::string>())+"</span>","statistics-action statistics-series-button",
"id=\"statistics-curve-"+std::to_string(k)+"\" data-index=\""+std::to_string(k)+"\" aria-pressed=\""+(active?"true":"false")+"\" style=\""+rect(double(k%3)*854.666666667,double(k/3)*100,836.666666667,82)+"\"");
}
out+="</div>";
} else {
const auto &columns=data.at("columns"),&rows=data.at("rows");
const size_t count=columns.size();
const double table_width=2548;
const double first=minutes?table_width*.12:winners?190:table_width*.4;
const double rest=count>1?(table_width-first)/double(count-1):0;
const auto width=[&](size_t column){return finals?(column==1?160:1194):column?rest:first;};
const bool trophies=winners&&std::any_of(columns.begin(),columns.end(),[](const Json &column){return !column.value("trophy","").empty();});
const double head_height=trophies?400:winners?78:76;
out+="<div id=\"statistics-list\" class=\"statistics-list "+std::string(winners?"statistics-winners ":"")+(minutes?"statistics-minutes ":"")+"\" data-scroll-key=\""+esc(statistics_scroll_key(data))+"\"><div class=\"statistics-table\" role=\"table\"><div class=\"statistics-row statistics-head\" role=\"row\" style=\"height:"+scalar(head_height)+"dp;\">";
for(size_t c=0;c<count;++c) {
const auto &column=columns[c];
const auto trophy=column.value("trophy","");const auto asset=statistics_trophy_asset(trophy);
std::string heading=statistics_text(column.at("text").get<std::string>());
if(column.contains("round"))heading="<span class=\"statistics-fixture-round\"><span>"+esc(column.at("round").get<std::string>())+"</span></span>"+heading;
if(!trophy.empty()) {
const auto art=asset.empty()?std::string():"<span class=\"statistics-trophy-icon\">"+img(asset,290,290,asset.starts_with("asset:"),false,640)+"</span>";
heading=btn("statistics-trophy",art+"<span class=\"statistics-trophy-label\">"+esc(column.at("text").get<std::string>())+"</span>","statistics-trophy-heading",
"id=\"statistics-trophy-heading-"+std::to_string(c)+"\" data-column=\""+std::to_string(c)+"\" data-row=\"-1\" aria-label=\""+esc(column.at("text").get<std::string>()+" · Siegerbild ansehen")+"\" "+(asset.empty()||!column.contains("winner")?"disabled":""));
}
out+="<div class=\"statistics-cell statistics-col-"+std::to_string(c)+"\" role=\"columnheader\" style=\"width:"+scalar(width(c))+"dp;height:"+scalar(head_height)+"dp;\">"+heading+"</div>";
}
out+="</div>";
for(size_t r=0;r<rows.size();++r) {
const auto &cells=rows[r].at("cells");
const bool world_trophies=section==4&&(data.at("country")==0||data.at("country")==5);
const double row_height=minutes?200:winners?120:world_trophies?110:76;
out+="<div class=\"statistics-row "+std::string(r%2==0?"striped":"")+"\" role=\"row\" style=\"height:"+scalar(row_height)+"dp;\">";
for(size_t c=0;c<cells.size();++c) {
const auto &value=cells[c];const auto title=value.value("text","");const auto token=std::to_string(r)+"-"+std::to_string(c);
std::string content;
if(value.contains("player")) {
content="<span class=\"statistics-player-prefix\">"+esc(value.value("prefix",""))+"</span>"+btn("player-detail",statistics_text(title),"statistics-player-link","id=\"statistics-player-"+token+"\" data-id=\""+esc(value.at("player").get<std::string>())+"\" data-club=\""+esc(value.value("club",""))+"\" title=\""+esc(title)+"\"");
} else if(value.contains("club")) {
const auto id=value.at("club").get<std::string>();const auto *club=world_->find("clubs",id);const bool reverse=section==1&&c==1;
const auto name="<span class=\"report-club-name\">"+esc(title)+"</span>",badge=crest(club,42);
content=btn("club-detail",reverse?name+badge:badge+name,"report-club-button statistics-club "+std::string(reverse?"name-first ":"")+(data.at("club")==id?"current":""),"id=\"statistics-club-"+token+"\" data-id=\""+esc(id)+"\" title=\""+esc(title)+"\"");
} else if(value.contains("trophy")) {
const auto asset=statistics_trophy_asset(value.at("trophy").get<std::string>());
content=btn("statistics-trophy",(asset.empty()?std::string():"<span class=\"statistics-world-trophy-art\">"+img(asset,92,92,asset.starts_with("asset:"),false,256)+"</span>")+statistics_text(title),"statistics-world-trophy","id=\"statistics-trophy-row-"+token+"\" data-row=\""+std::to_string(r)+"\" data-column=\""+std::to_string(c)+"\" "+(asset.empty()?"disabled":""));
} else content=statistics_text(value.value("prefix","")+title);
if(value.contains("round"))content="<span class=\"statistics-fixture-round\"><span>"+esc(value.at("round").get<std::string>())+"</span></span>"+content;
out+="<div class=\"statistics-cell statistics-col-"+std::to_string(c)+" "+esc(value.value("tone",""))+"\" role=\"cell\" style=\"width:"+scalar(width(c))+"dp;height:"+scalar(row_height)+"dp;\">"+content+"</div>";
}
out+="</div>";
}
if(rows.empty())out+="<p class=\"statistics-empty\">"+statistics_text("Keine Statistikdaten für diese Auswahl vorhanden.")+"</p>";
out+="</div></div>";
}
out+="</div><nav class=\"report-footer statistics-footer\" aria-label=\"Statistik und Auswahl\">";
const bool extra=winners||section==2||section==3||section==4;
const bool three=winners&&category==0;
const double width=three?854.666666667:extra?1294:2612;
out+=report_picker("stat-section",0,width);
if(winners) {
out+=report_picker("stat-category",three?878.666666667:1318,width);
if(three)out+=report_picker("winner-country",1757.333333333,width);
} else if(section==3||section==4)out+=report_picker("stat-country",1318,1294);
else if(section==2)out+=btn("statistics-absolute",statistics_text(data.at("absolute")==true?"ABS.":"REL."),"statistics-action statistics-absolute","id=\"statistics-absolute\" aria-label=\""+std::string(data.at("absolute")==true?"Absolute":"Relative")+" Darstellung; zum Umschalten klicken\" style=\""+rect(1318,0,1294,94)+"\"");
statistics_restore_pending_=true;
return out+"</nav></section>"+render_report_detail();
}
std::string App::render_statistics_trophy() {
if(!statistics_trophy_.contains("asset"))return {};
const auto asset=statistics_trophy_.at("asset").get<std::string>();
const bool world_image = asset.starts_with("asset:");
if(world_image ? (!world_ || !world_->find("assets", asset)) : !gui_.contains(asset))return {};
const auto winner=statistics_trophy_.value("winner","");
const auto *club=world_?world_->find("clubs",winner):nullptr;
const auto name=club?world_->name(*club):world_?world_->nation_name(winner):"—";
const auto viewport=context_->GetDimensions();
const double w=viewport.x/scale_,h=viewport.y/scale_,stage=std::min(w,h*16/9);
const double art=std::min({h*.61,1200/scale_,w*.82});
const double heading=std::clamp(h*.022,17/scale_,48/scale_),team=std::clamp(h*.035,25/scale_,76/scale_);
const double season_font=std::clamp(h*.0145,13/scale_,30/scale_),button_font=std::clamp(h*.0165,14/scale_,36/scale_);
const double heading_h=heading*1.25,team_h=team*1.5,season_h=season_font*1.25;
const double button_h=std::max(h*.046,button_font*1.25+h*.018+2/scale_);
const double gap=h*.018,copy_gap=h*.012;
const double total=art+heading_h+team_h+season_h+2*copy_gap+button_h+2*gap+h*.008;
const double top=(h-total)/2,heading_top=top+art+gap,team_top=heading_top+heading_h+copy_gap;
const double season_top=team_top+team_h+copy_gap,button_top=season_top+season_h+gap+h*.008;
return "<div id=\"statistics-trophy-layer\" class=\"statistics-trophy-layer\" style=\""+rect(-canvas_left_/scale_,-canvas_top_/scale_,w,h)+"\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"statistics-trophy-title\"><div class=\"statistics-trophy-backdrop\">"+img("background",w,h,false,true,2048)+"</div><div class=\"statistics-trophy-shade\"></div><div class=\"statistics-trophy-large\" style=\""+rect((w-art)/2,top,art,art)+"\">"+img(asset,art,art,world_image,false,1600)+"</div><h2 id=\"statistics-trophy-title\" style=\""+rect((w-stage)/2,heading_top,stage,heading_h)+"font-size:"+scalar(heading)+"dp;line-height:"+scalar(heading_h)+"dp;\">"+esc(statistics_trophy_.value("title","Sieger"))+"</h2><div class=\"statistics-trophy-winner\" style=\""+rect((w-stage)/2,team_top,stage,team_h)+"font-size:"+scalar(team)+"dp;\">"+(club?crest(club,team_h):"")+"<span>"+esc(name)+"</span></div><p class=\"statistics-trophy-season\" style=\""+rect((w-stage)/2,season_top,stage,season_h)+"font-size:"+scalar(season_font)+"dp;line-height:"+scalar(season_h)+"dp;\">"+statistics_text(statistics_trophy_.value("season",""))+"</p>"+btn("statistics-trophy-close","<span>Weiter</span>","statistics-trophy-close","id=\"statistics-trophy-close\" style=\""+rect((w-h*.17)/2,button_top,h*.17,button_h)+"font-size:"+scalar(button_font)+"dp;border-radius:"+scalar(h*.011)+"dp;\"")+"</div>";
}