Add player_ranks to the mix - it is a batch table intended to represent the latest...
authorAnt Zucaro <azucaro@gmail.com>
Sun, 22 Jan 2012 04:11:52 +0000 (23:11 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 22 Jan 2012 04:11:52 +0000 (23:11 -0500)
xonstat/models.py
xonstat/templates/rank_index.mako
xonstat/views/game.py

index 50d0a35209ffff71a6eb8dca09973f78c3274ad5..d53e1daeb4fa4cf3bd187d4ec105b6021c02a335 100755 (executable)
@@ -270,6 +270,20 @@ class PlayerElo(object):
                 (self.player_id, self.game_type_cd, self.elo)
 
 
+class PlayerRank(object):
+
+    def nick_html_colors(self):
+        if self.nick is None:
+            return "Anonymous Player"
+        else:
+            return html_colors(self.nick)
+
+
+    def __repr__(self):
+        return "<PlayerRank(pid=%s, gametype=%s, rank=%s)>" % \
+                (self.player_id, self.game_type_cd, self.rank)
+
+
 def initialize_db(engine=None):
     DBSession.configure(bind=engine)
     Base.metadata.bind = engine
@@ -291,6 +305,7 @@ def initialize_db(engine=None):
     servers_table = MetaData.tables['servers']
     player_nicks_table = MetaData.tables['player_nicks']
     player_elos_table = MetaData.tables['player_elos']
+    player_ranks_table = MetaData.tables['player_ranks']
 
     # now map the tables and the objects together
     mapper(PlayerAchievement, achievements_table)
@@ -306,3 +321,4 @@ def initialize_db(engine=None):
     mapper(Server, servers_table)
     mapper(PlayerNick, player_nicks_table)
     mapper(PlayerElo, player_elos_table)
+    mapper(PlayerRank, player_ranks_table)
index 3ddb7f9597d2d337c205adb0d1109a7c8cdf857b..75f4574cf2980bba2dade6b8375e230064cde3fc 100755 (executable)
@@ -28,10 +28,10 @@ Rank Index</h2>
     <th>Elo</th>\r
   </tr>\r
 <% i = 1 %>\r
-% for (rank, player) in ranks:\r
+% for rank in ranks:\r
   <tr>\r
-    <td>${i}</td>\r
-    <td><a href="${request.route_url("player_info", id=rank.player_id)}" title="Go to this player's info page">${player.nick_html_colors()|n}</a></th>\r
+    <td>${rank.rank}</td>\r
+    <td><a href="${request.route_url("player_info", id=rank.player_id)}" title="Go to this player's info page">${rank.nick_html_colors()|n}</a></th>\r
     <td>${round(rank.elo, 3)}</th>\r
   </tr>\r
 <% i += 1 %>\r
@@ -39,5 +39,5 @@ Rank Index</h2>
 </table>\r
 \r
 <!-- navigation links -->\r
-${navlinks("rank_index_paged", ranks.page, ranks.last_page)}\r
+${navlinks("rank_index_paged", ranks.page, ranks.last_page, game_type_cd=game_type_cd)}\r
 % endif\r
index 25ab4082333742a079b51d56bd91c4741bbe2408..1ce8a9ac74e5aeb164118a44db9da532f6427d66 100755 (executable)
@@ -3,7 +3,7 @@ import logging
 import re\r
 import time\r
 from pyramid.response import Response\r
-from sqlalchemy import desc\r
+from sqlalchemy import desc, func, over\r
 from webhelpers.paginate import Page, PageURL\r
 from xonstat.models import *\r
 from xonstat.util import page_url\r
@@ -106,10 +106,9 @@ def rank_index(request):
 \r
     game_type_cd = request.matchdict['game_type_cd']\r
 \r
-    ranks_q = DBSession.query(PlayerElo, Player).\\r
-            filter(PlayerElo.game_type_cd==game_type_cd).\\r
-            filter(PlayerElo.player_id==Player.player_id).\\r
-            order_by(PlayerElo.elo.desc())\r
+    ranks_q = DBSession.query(PlayerRank).\\r
+            filter(PlayerRank.game_type_cd==game_type_cd).\\r
+            order_by(PlayerRank.rank)\r
 \r
     ranks = Page(ranks_q, current_page, url=page_url)\r
 \r