]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add top servers data.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 15 Jun 2011 22:13:42 +0000 (18:13 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 15 Jun 2011 22:13:42 +0000 (18:13 -0400)
xonstat/templates/main_index.mako
xonstat/views/main.py

index 0b03aedff59c218236b67c74498cdf0775fd3e7b..0caccc17bcbe90fe09c220c196a569cb6a51f05c 100755 (executable)
@@ -23,3 +23,23 @@ Main Page - ${parent.title()}
 </tr>\r
 % endfor\r
 </table>\r
+\r
+<table>\r
+<tr>\r
+<th>Server</th>\r
+<th>Games</th>\r
+</tr>\r
+% for (server_id, name, count) in top_servers:\r
+<tr>\r
+<td>${name}</td>\r
+<td>${count}</td>\r
+</tr>\r
+% endfor\r
+\r
+% for i in range(10 - len(top_servers)):\r
+<tr>\r
+<td>-</td>\r
+<td>-</td>\r
+</tr>\r
+% endfor\r
+</table>\r
index 33f0b3db96ff551818f91bfecc9cf8be3dec4dac..2e59f3f8e26176679eee798c03bd7e608e5e1e1e 100755 (executable)
@@ -6,11 +6,23 @@ from xonstat.models import *
 log = logging.getLogger(__name__)
 
 def main_index(request):
-    top_players = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.score)).\
+    # top players by score
+    top_players = DBSession.query(Player.player_id, Player.nick, 
+            func.sum(PlayerGameStat.score)).\
             filter(Player.player_id == PlayerGameStat.player_id).\
             filter(Player.player_id > 2).\
             order_by(func.sum(PlayerGameStat.score)).\
             group_by(Player.nick).\
             group_by(Player.player_id).all()[0:10]
 
-    return {'top_players':top_players}
+    # top servers by number of total players played
+    top_servers = DBSession.query(Server.server_id, Server.name, 
+            func.count(Game.game_id)).\
+            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]
+
+    return {'top_players':top_players,
+            'top_servers':top_servers,
+            }