diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp index 076947b..530e096 100644 --- a/src/oastat_static_web_generator.cpp +++ b/src/oastat_static_web_generator.cpp @@ -60,6 +60,23 @@ std::string getTimeStamp(const tm& _datetime) return s; } +static std::map kills_by_player; +static std::map player_deaths; + +void populate_player_deaths(cppdb::session& database, const std::vector& player_ids) { + std::string sql = "select count(0) from oastat.oastat_kills k where k.attacker <> k.target and target = ?"; + cppdb::statement st = database.prepare(sql); + for (int player_id : player_ids) { + st.bind(1, player_id); + int deaths; + cppdb::result res = st.query(); + if (res.next()) { + res >> deaths; + player_deaths[player_id] = deaths; + } + } +} + std::vector get_top_killers(cppdb::session& database, int count) { std::vector ret; std::string sql = "select p.playerid, count(0) c from oastat.oastat_players p, oastat.oastat_kills k where p.playerid = k.attacker and k.attacker <> k.target and p.playerid <> 0 group by p.playerid order by c desc limit ?"; @@ -67,9 +84,11 @@ std::vector get_top_killers(cppdb::session& database, int count) { st.bind(1, count); cppdb::result res = st.query(); while(res.next()) { - int value; - res >> value; - ret.push_back(value); + int player_id; + int kills; + res >> player_id >> kills; + kills_by_player[player_id] = kills; + ret.push_back(player_id); } return ret; } @@ -105,12 +124,15 @@ void write_html_index(cppdb::session& database) { ctemplate::TemplateDictionary index_tpl("templates/index.tpl"); index_tpl.SetValue("GENERATION_DATE", timestamp_now_as_string(database)); std::vector player_list = get_top_killers(database, 25); + populate_player_deaths(database, player_list); for (int i = 0; i < player_list.size(); ++i) { OastatPlayer p = getPlayer(database, player_list.at(i)); ctemplate::TemplateDictionary* sub_dict = index_tpl.AddSectionDictionary("PLAYER_LIST"); sub_dict->SetValue("EVEN_LINE", (i%2)?"1":"0"); sub_dict->SetValue("PLAYER_NAME", p.nickname); sub_dict->SetValue("PLAYER_LAST_SEEN", getTimeStamp(p.lastseen)); + sub_dict->SetValue("PLAYER_KILLS", std::to_string(kills_by_player[p.playerid])); + sub_dict->SetValue("PLAYER_DEATHS", std::to_string(player_deaths[p.playerid])); sub_dict->SetValue("PLAYER_IS_BOT", p.isBot); } std::string output; diff --git a/templates/index.tpl b/templates/index.tpl index dd2eae0..7ac54f8 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -19,13 +19,17 @@ - + + + {{#PLAYER_LIST}} + +
Name
Kills
Deaths
Last seen
Is bot
{{PLAYER_NAME}}
{{PLAYER_KILLS}}
{{PLAYER_DEATHS}}
{{PLAYER_LAST_SEEN}}
{{PLAYER_IS_BOT}}