From: Ant Zucaro Date: Sun, 23 Oct 2016 13:24:34 +0000 (-0400) Subject: Add HTML views for top active players, scoring players, and maps played. X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=69bec456b27e9f5d5b2edc961328df18af5f1cb9;p=xonotic%2Fxonstat.git Add HTML views for top active players, scoring players, and maps played. --- diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 4071dd5..3f9a43d 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -141,14 +141,20 @@ def main(global_config, **settings): accept="text/json") config.add_route("server_top_maps", "/server/{id:\d+}/topmaps") + config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="html", + renderer="server_top_maps.mako", accept="text/html") config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="json", renderer="json", accept="text/json") - config.add_route("server_top_players", "/server/{id:\d+}/topplayers") + config.add_route("server_top_players", "/server/{id:\d+}/topactive") + config.add_view(view=ServerTopPlayers, route_name="server_top_players", attr="html", + renderer="server_top_players_index.mako", accept="text/html") config.add_view(view=ServerTopPlayers, route_name="server_top_players", attr="json", renderer="json", accept="text/json") config.add_route("server_top_scorers", "/server/{id:\d+}/topscorers") + config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="html", + renderer="server_top_scorers.mako", accept="text/html") config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="json", renderer="json", accept="text/json") diff --git a/xonstat/templates/server_top_maps.mako b/xonstat/templates/server_top_maps.mako new file mode 100644 index 0000000..9fdfe14 --- /dev/null +++ b/xonstat/templates/server_top_maps.mako @@ -0,0 +1,55 @@ +<%inherit file="base.mako"/> +<%namespace name="nav" file="nav.mako" /> + +<%block name="navigation"> + ${nav.nav('servers')} + + +<%block name="title"> + Server Top Map Index + + +% if not top_maps and last is not None: +

Sorry, no more maps!

+ +% elif not top_maps and last is None: +

No maps found. Yikes, get playing!

+ +% else: +
+
+ + + + + + + + + + % for tm in top_maps: + + + + + + % endfor + +
#MapTimes Played
${tm.rank}${tm.name|n}${tm.times_played}
+

Note: these figures are from the past 7 days +

+
+ + % if len(top_maps) == 20: +
+
+ +
+
+ % endif + +% endif diff --git a/xonstat/templates/server_top_players_index.mako b/xonstat/templates/server_top_players_index.mako new file mode 100644 index 0000000..3bba6d5 --- /dev/null +++ b/xonstat/templates/server_top_players_index.mako @@ -0,0 +1,57 @@ +<%inherit file="base.mako"/> +<%namespace name="nav" file="nav.mako" /> + +<%block name="navigation"> + ${nav.nav('servers')} + + +<%block name="title"> + Server Active Players Index + + +% if not top_players and start is not None: +

Sorry, no more active players!

+ +% elif not top_players and start is None: +

No active players found. Yikes, get playing!

+ +% else: + ##### ACTIVE PLAYERS ##### +
+
+ + + + + + + + + + + % for tp in top_players: + + + + + + % endfor + +
#NickPlay Time
${tp.rank}${tp.nick|n}${tp.alivetime}
+

Note: these figures are from the past 7 days +

+
+ + % if len(top_players) == 20: +
+
+ +
+
+ % endif + +% endif diff --git a/xonstat/templates/server_top_scorers.mako b/xonstat/templates/server_top_scorers.mako new file mode 100644 index 0000000..ade10d5 --- /dev/null +++ b/xonstat/templates/server_top_scorers.mako @@ -0,0 +1,55 @@ +<%inherit file="base.mako"/> +<%namespace name="nav" file="nav.mako" /> + +<%block name="navigation"> + ${nav.nav('servers')} + + +<%block name="title"> + Server Top Scorer Index + + +% if not top_scorers and last is not None: +

Sorry, no more players!

+ +% elif not top_scorers and last is None: +

No players found. Yikes, get playing!

+ +% else: +
+
+ + + + + + + + + + % for ts in top_scorers: + + + + + + % endfor + +
#NickScore
${ts.rank}${ts.nick|n}${ts.total_score}
+

Note: these figures are from the past 7 days +

+
+ + % if len(top_scorers) == 20: +
+
+ +
+
+ % endif + +% endif diff --git a/xonstat/views/server.py b/xonstat/views/server.py index 1b5dc9b..f65cd13 100644 --- a/xonstat/views/server.py +++ b/xonstat/views/server.py @@ -16,6 +16,7 @@ log = logging.getLogger(__name__) # Defaults LEADERBOARD_LIFETIME = 30 LEADERBOARD_COUNT = 10 +INDEX_COUNT = 20 RECENT_GAMES_COUNT = 20 @@ -72,7 +73,7 @@ class ServerInfoBase(object): class ServerTopMaps(ServerInfoBase): """Returns the top maps played on a given server.""" - def __init__(self, request, limit=LEADERBOARD_COUNT, last=None): + def __init__(self, request, limit=INDEX_COUNT, last=None): """Common parameter parsing.""" super(ServerTopMaps, self).__init__(request, limit, last) @@ -106,7 +107,17 @@ class ServerTopMaps(ServerInfoBase): def html(self): """Returns the HTML-ready representation.""" - return self.top_maps + + # build the query string + query = {} + if len(self.top_maps) > 1: + query['last'] = self.top_maps[-1].rank + + return { + "server_id": self.server_id, + "top_maps": self.top_maps, + "query": query, + } def json(self): """For rendering this data using JSON.""" @@ -123,7 +134,7 @@ class ServerTopMaps(ServerInfoBase): class ServerTopScorers(ServerInfoBase): """Returns the top scorers on a given server.""" - def __init__(self, request, limit=LEADERBOARD_COUNT, last=None): + def __init__(self, request, limit=INDEX_COUNT, last=None): """Common parameter parsing.""" super(ServerTopScorers, self).__init__(request, limit, last) self.top_scorers = self.raw() @@ -166,7 +177,17 @@ class ServerTopScorers(ServerInfoBase): top_scorers = [TopScorer(ts.rank, ts.player_id, html_colors(ts.nick), ts.total_score) for ts in self.top_scorers] - return top_scorers + + # build the query string + query = {} + if len(top_scorers) > 1: + query['last'] = top_scorers[-1].rank + + return { + "server_id": self.server_id, + "top_scorers": top_scorers, + "query": query, + } def json(self): """For rendering this data using JSON.""" @@ -183,7 +204,7 @@ class ServerTopScorers(ServerInfoBase): class ServerTopPlayers(ServerInfoBase): """Returns the top players by playing time on a given server.""" - def __init__(self, request, limit=LEADERBOARD_COUNT, last=None): + def __init__(self, request, limit=INDEX_COUNT, last=None): """Common parameter parsing.""" super(ServerTopPlayers, self).__init__(request, limit, last) self.top_players = self.raw() @@ -226,7 +247,16 @@ class ServerTopPlayers(ServerInfoBase): top_players = [TopPlayer(tp.rank, tp.player_id, html_colors(tp.nick), tp.alivetime) for tp in self.top_players] - return top_players + # build the query string + query = {} + if len(top_players) > 1: + query['last'] = top_players[-1].rank + + return { + "server_id": self.server_id, + "top_players": top_players, + "query": query, + } def json(self): """For rendering this data using JSON.""" @@ -273,9 +303,9 @@ class ServerInfo(ServerInfoBase): """For rendering this data using something HTML-based.""" return { 'server': self.server, - 'top_players': self.top_players_v.html(), - 'top_scorers': self.top_scorers_v.html(), - 'top_maps': self.top_maps_v.html(), + 'top_players': self.top_players_v.html()["top_players"], + 'top_scorers': self.top_scorers_v.html()["top_scorers"], + 'top_maps': self.top_maps_v.html()["top_maps"], 'recent_games': self.recent_games, 'lifetime': self.lifetime, }