diff --git a/src/oastat_static_web_generator.cpp b/src/oastat_static_web_generator.cpp index ee825d6..076947b 100644 --- a/src/oastat_static_web_generator.cpp +++ b/src/oastat_static_web_generator.cpp @@ -4,6 +4,10 @@ #include "command_arguments.hpp" #include #include +#include +#include +#include +#include #ifndef VERSIONNUMBER #define VERSIONNUMBER "0.1.0" @@ -40,10 +44,75 @@ static void copy_static_files(const std::string& source, const std::string& dest } } +std::string ZeroPadNumber(int num, int size = 2) +{ + std::ostringstream ss; + ss.clear(); + ss << std::setw( size ) << std::setfill( '0' ) << num; + return ss.str(); +} + +std::string getTimeStamp(const tm& _datetime) +{ + std::string s = ZeroPadNumber(_datetime.tm_year+1900,4) + "-" + ZeroPadNumber(_datetime.tm_mon+1) + "-" + + ZeroPadNumber(_datetime.tm_mday) + " " + ZeroPadNumber(_datetime.tm_hour) + ":" + + ZeroPadNumber(_datetime.tm_min) + ":" + ZeroPadNumber(_datetime.tm_sec); + return s; +} + +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 ?"; + cppdb::statement st = database.prepare(sql); + st.bind(1, count); + cppdb::result res = st.query(); + while(res.next()) { + int value; + res >> value; + ret.push_back(value); + } + return ret; +} + + +struct OastatPlayer { + int playerid = 0; + std::string nickname; + tm lastseen; + std::string isBot = "n"; + std::string model; + std::string headmodel; +}; + +static std::map players; + +OastatPlayer getPlayer(cppdb::session& database, int playerid) { + OastatPlayer ret; + if (players.count(playerid)) { + ret = players[playerid]; + } + cppdb::statement st = database.prepare("select playerid, lastseen, isbot, model, headmodel, nickname from oastat.oastat_players where playerid = ?"); + st.bind(1, playerid); + cppdb::result res = st.query(); + if (res.next()) { + res >> ret.playerid >> ret.lastseen >> ret.isBot >> ret.model >> ret.headmodel >> ret.nickname; + players[playerid] = ret; + } + return ret; +} 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); + 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_IS_BOT", p.isBot); + } 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 33db3f3..2337d1e 100644 --- a/static_content/css/oastat.css +++ b/static_content/css/oastat.css @@ -22,7 +22,7 @@ font-style: normal; /* normal | italic | oblique | inherit */ font-variant: normal; /* normal | small-caps */ font-weight: normal; /* normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit */ font-size: 10pt; /* | | | | inherit */ -text-indent: 0px; /* justificación de la primera línea de un párrafo */ +text-indent: 0px; /* justificación de la primera línea de un párrafo */ text-align: left; /* left | right | center | justify | inherit */ text-decoration: none; /* none | [ underline || overline || line-through || blink ] | inherit */ text-transform: none; /* capitalize | uppercase | lowercase | none | inherit */ @@ -106,7 +106,7 @@ font-size: 20pt; .update { float: right; color: #FFFFFF; -margin-right: 70px; +margin-right: 70px; padding-top: 10px; font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 9pt; @@ -117,7 +117,7 @@ font-style: italic; .endnote { float: right; color: #000000; -margin-right: 10px; +margin-right: 10px; padding-top: 0px; padding-bottom: 15px; font-family: Verdana, Tahoma, Arial, sans-serif; @@ -321,7 +321,7 @@ font-weight: bold; text-align: center; } -.jugador { +.jugador0 { background: #CCCCff; color: #000000; margin-top: 1px; @@ -337,7 +337,7 @@ font-size: 8pt; text-align: left; } -.jugador2 { +.jugador1 { background: #eeeeff; color: #000000; margin-top: 1px; @@ -353,7 +353,7 @@ font-size: 8pt; text-align: left; } -.dato { +.dato0 { background: #CCCCff; color: #000000; margin-top: 1px; @@ -369,7 +369,7 @@ font-size: 8pt; text-align: center; } -.dato2 { +.dato1 { background: #eeeeff; color: #000000; margin-top: 1px; @@ -386,13 +386,13 @@ text-align: center; } -div.centered +div.centered { text-align: center; } -div.centered table +div.centered table { -margin: 0 auto; +margin: 0 auto; text-align: left; } @@ -443,4 +443,3 @@ font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 8pt; color: #FFA500; } - diff --git a/templates/index.tpl b/templates/index.tpl index dceab49..dd2eae0 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -15,6 +15,23 @@
Last updated on {{GENERATION_DATE}}
OpenArena Stats
+ + + + + + + + + {{#PLAYER_LIST}} + + + + + + {{/PLAYER_LIST}} +
Last seen
Is bot
{{PLAYER_NAME}}
{{PLAYER_LAST_SEEN}}
{{PLAYER_IS_BOT}}
+