commit 897dc796
Add a list of the 10 most played maps
Changed files
| M | src/oastat_static_web_generator.cpp before |
| M | static_content/css/oastat.css before |
| M | templates/index.tpl before |
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<int, int> kills_by_player;
static std::map<int, int> player_deaths;
static std::map<int, std::map<int, int>> player_awards;
static std::map<int, std::map<int, int>> player_weapon_kills;
+static std::map<std::string, MapInfo> map_infos;
void populate_player_deaths(cppdb::session& database, const std::vector<int>& 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<int> get_top_killers(cppdb::session& database, int count) {
return ret;
}
+std::vector<std::string> get_most_played_maps(cppdb::session& database) {
+ std::vector<std::string> 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<std::string> 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}}
</TABLE>
-<TABLE class="tabladatos">
+<table class="tabladatos">
<TR>
<TH><DIV class="tituloup">Name</DIV></TH>
<TH><DIV class="tituloup">Shotgun</DIV></TH>
@@ -83,6 +83,21 @@
<td><div class="dato{{EVEN_LINE}}">{{WEAPON_FALLING}}</div></td>
<tr>
{{/PLAYER_WEAPON_LIST}}
+</table>
+<table class="tabladatos">
+<tr>
+<TH><DIV class="tituloup">Map</DIV></TH>
+<TH><DIV class="tituloup">Times played</DIV></TH>
+<TH><DIV class="tituloup">Last played at</DIV></TH>
+</tr>
+{{#MAP_LIST}}
+<tr>
+ <td><div class="jugador{{EVEN_LINE}}">{{MAP_NAME}}</div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{TIMES_PLAYED}}</div></td>
+ <td><div class="dato{{EVEN_LINE}}">{{LAST_PLAYED}}</div></td>
+</tr>
+{{/MAP_LIST}}
+</table>
</DIV>
</DIV>
</BODY>