// SPDX-License-Identifier: GPL-3.0-only namespace { std::string statistics_text(const std::string &text) { return ""+esc(text)+""; } 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> App::statistics_picker_items(const std::string &kind) const { std::vector> 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(); if(kind=="stat-section") { const auto &names=data.at("sections"); for(size_t i=0;i()); } else if(kind=="stat-category"&§ion==7)result={{"0","National"},{"1","International"},{"5","Hallenmasters"}}; else if(kind=="winner-country"&§ion==7&&data.at("category")==0) { for(const auto &nation:data.at("countries"))result.emplace_back(nation.at("id").get(),nation.at("name").get()); } else if(kind=="stat-country"&§ion==3) { for(const auto &nation:data.at("eternal_countries")) result.emplace_back(std::to_string(nation.at("value").get()),nation.at("name").get()); } else if(kind=="stat-country"&§ion==4) { const auto &names=data.at("world_views"); for(size_t i=0;i()); } 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("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("data-scroll-key",""); if(const auto i=statistics_scrolls_.find(key);i!=statistics_scrolls_.end()&&i->is_number())list->SetScrollTop(i->get()); } } 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 "

Statistiken sind nicht verfügbar.

"; if(engine_mode_&&statistics_mode_=="analysis")return render_statistics_analysis()+render_report_detail(); const auto data=statistics_data(); if(!data.value("ok",false))return "

Statistiken sind nicht verfügbar.

"; const int section=data.at("section").get(),category=data.at("category").get(); const bool winners=section==7,minutes=section==8,finals=section==4&&data.at("country")==3; std::string out="
"+(engine_mode_?btn("statistics-mode","‹ Vereinsanalyse","statistics-back","id=\"statistics-mode-analysis\" data-id=\"analysis\""):std::string())+"

"+esc(data.at("title").get())+"

"; if(winners)out+="

"+statistics_text(data.value("note",""))+"

"; if(engine_mode_&&!data.value("available",false)){out+="

"+statistics_text(data.value("reason","")=="not_recorded"?"Diese Auswertung wurde in der Karriere noch nicht aufgezeichnet.":"Keine Statistikdaten für diese Auswahl vorhanden.")+"

";} else if(section==2) { std::string svg=""; const auto &series=data.at("series"); for(const auto &curve:series)if(curve.at("active")==true) { svg+=""; } svg+=""; out+="
"+picture(renderer_.diagram("statistics-analytics",svg,5100),2496,812)+"
"; for(size_t k=0;k(); out+=btn("statistics-curve","()+";\">"+esc(curve.at("name").get())+"","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+="
"; } 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+="
"; for(size_t c=0;c()); if(column.contains("round"))heading=""+esc(column.at("round").get())+""+heading; if(!trophy.empty()) { const auto art=asset.empty()?std::string():""+img(asset,290,290,asset.starts_with("asset:"),false,640)+""; heading=btn("statistics-trophy",art+""+esc(column.at("text").get())+"","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()+" · Siegerbild ansehen")+"\" "+(asset.empty()||!column.contains("winner")?"disabled":"")); } out+="
"+heading+"
"; } out+="
"; for(size_t r=0;r"; for(size_t c=0;c"+esc(value.value("prefix",""))+""+btn("player-detail",statistics_text(title),"statistics-player-link","id=\"statistics-player-"+token+"\" data-id=\""+esc(value.at("player").get())+"\" data-club=\""+esc(value.value("club",""))+"\" title=\""+esc(title)+"\""); } else if(value.contains("club")) { const auto id=value.at("club").get();const auto *club=world_->find("clubs",id);const bool reverse=section==1&&c==1; const auto name=""+esc(title)+"",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()); content=btn("statistics-trophy",(asset.empty()?std::string():""+img(asset,92,92,asset.starts_with("asset:"),false,256)+"")+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=""+esc(value.at("round").get())+""+content; out+="
"+content+"
"; } out+="
"; } if(rows.empty())out+="

"+statistics_text("Keine Statistikdaten für diese Auswahl vorhanden.")+"

"; out+="
"; } out+="
"+render_report_detail(); } std::string App::render_statistics_trophy() { if(!statistics_trophy_.contains("asset"))return {}; const auto asset=statistics_trophy_.at("asset").get(); 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 "
"+img("background",w,h,false,true,2048)+"
"+img(asset,art,art,world_image,false,1600)+"

"+esc(statistics_trophy_.value("title","Sieger"))+"

"+(club?crest(club,team_h):"")+""+esc(name)+"

"+statistics_text(statistics_trophy_.value("season",""))+"

"+btn("statistics-trophy-close","Weiter","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;\"")+"
"; }