From ae96b61e5b1c4a5ecd4377f3e904180ac91ad80e Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 16 Jun 2011 06:53:15 -0400 Subject: [PATCH] Add top_maps to main view and template. --- xonstat/templates/main_index.mako | 20 ++++++++++++++++++++ xonstat/views/main.py | 11 ++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako index 0caccc1..12d5323 100755 --- a/xonstat/templates/main_index.mako +++ b/xonstat/templates/main_index.mako @@ -43,3 +43,23 @@ Main Page - ${parent.title()} % endfor + + + + + + +% for (map_id, name, count) in top_maps: + + + + +% endfor + +% for i in range(10 - len(top_maps)): + + + + +% endfor +
MapTimes Played
${name}${count}
--
diff --git a/xonstat/views/main.py b/xonstat/views/main.py index 2e59f3f..811a1a6 100755 --- a/xonstat/views/main.py +++ b/xonstat/views/main.py @@ -17,12 +17,21 @@ def main_index(request): # top servers by number of total players played top_servers = DBSession.query(Server.server_id, Server.name, - func.count(Game.game_id)).\ + func.count()).\ filter(Game.server_id==Server.server_id).\ order_by(func.count(Game.game_id)).\ group_by(Server.server_id).\ group_by(Server.name).all()[0:10] + # top maps by total times played + top_maps = DBSession.query(Map.map_id, Map.name, + func.count(Game.game_id)).\ + filter(Map.map_id==Game.game_id).\ + order_by(func.count(Game.game_id)).\ + group_by(Map.map_id).\ + group_by(Map.name).all()[0:10] + return {'top_players':top_players, 'top_servers':top_servers, + 'top_maps':top_maps, } -- 2.39.2