diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp index 8d9348d..0c97693 100644 --- a/src/oastat_static_web_generator.cpp +++ b/src/oastat_static_web_generator.cpp @@ -15,6 +15,8 @@ CommandArguments cmdargs; +const size_t MAX_MAP_LIST = 10; + const char* const SAGO_CONNECTION_STRING = "SAGO_CONNECTION_STRING"; // means of death @@ -100,10 +102,16 @@ std::string getTimeStamp(const tm& _datetime) return s; } +struct MapInfo { + int times_played = {}; + tm last_played = {}; +}; + static std::map kills_by_player; static std::map player_deaths; static std::map> player_awards; static std::map> player_weapon_kills; +static std::map map_infos; 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 = ?"; @@ -165,6 +173,21 @@ std::vector get_top_killers(cppdb::session& database, int count) { return ret; } +std::vector get_most_played_maps(cppdb::session& database) { + std::vector ret; + std::string sql = "select mapname, count(0) c, max(time) last_game from oastat.oastat_games group by mapname order by c desc"; + cppdb::statement st = database.prepare(sql); + cppdb::result res = st.query(); + while(res.next()) { + std::string mapname; + MapInfo info; + res >> mapname >> info.times_played >> info.last_played; + map_infos[mapname] = info; + ret.push_back(mapname); + } + return ret; +} + struct OastatPlayer { int playerid = 0; std::string nickname; @@ -233,6 +256,16 @@ void write_html_index(cppdb::session& database) { sub_dict->SetValue("WEAPON_TELEFRAG", std::to_string(player_weapon_kills[p.playerid][MOD_TELEFRAG])); sub_dict->SetValue("WEAPON_FALLING", std::to_string(player_weapon_kills[p.playerid][MOD_FALLING])); } + std::vector map_list = get_most_played_maps(database); + for (size_t i = 0; i < map_list.size() && i < MAX_MAP_LIST; ++i) { + const std::string& mapname = map_list[i]; + const MapInfo& info = map_infos[mapname]; + ctemplate::TemplateDictionary* sub_dict = index_tpl.AddSectionDictionary("MAP_LIST"); + sub_dict->SetValue("EVEN_LINE", (i%2)?"1":"0"); + sub_dict->SetValue("MAP_NAME", mapname); + sub_dict->SetValue("TIMES_PLAYED", std::to_string(info.times_played)); + sub_dict->SetValue("LAST_PLAYED", getTimeStamp(info.last_played)); + } std::string output; ctemplate::ExpandTemplate("templates/index.tpl", ctemplate::DO_NOT_STRIP, &index_tpl, &output); std::ofstream myfile; diff --git a/static_content/css/oastat.css b/static_content/css/oastat.css index 2337d1e..89f66ba 100644 --- a/static_content/css/oastat.css +++ b/static_content/css/oastat.css @@ -184,6 +184,8 @@ background-color: #FFFFFF; border-color: #3366CC; border-style: solid; margin-top: 20px; +margin-left:auto; +margin-right:auto; } diff --git a/templates/index.tpl b/templates/index.tpl index b9f2ecf..11cec69 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -48,7 +48,7 @@ {{/PLAYER_LIST}} - +
@@ -83,6 +83,21 @@ {{/PLAYER_WEAPON_LIST}} +
Name
Shotgun
{{WEAPON_FALLING}}
+ + + + + + +{{#MAP_LIST}} + + + + + +{{/MAP_LIST}} +
Map
Times played
Last played at
{{MAP_NAME}}
{{TIMES_PLAYED}}
{{LAST_PLAYED}}