From 129a16ca216817db10b4724def90ff8d1fc75961 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sat, 21 Jan 2012 23:11:52 -0500 Subject: [PATCH] Add player_ranks to the mix - it is a batch table intended to represent the latest rankings at any given point in time. Ideally they would be updated daily. --- xonstat/models.py | 16 ++++++++++++++++ xonstat/templates/rank_index.mako | 8 ++++---- xonstat/views/game.py | 9 ++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/xonstat/models.py b/xonstat/models.py index 50d0a35..d53e1da 100755 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -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 "" % \ + (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) diff --git a/xonstat/templates/rank_index.mako b/xonstat/templates/rank_index.mako index 3ddb7f9..75f4574 100755 --- a/xonstat/templates/rank_index.mako +++ b/xonstat/templates/rank_index.mako @@ -28,10 +28,10 @@ Rank Index Elo <% i = 1 %> -% for (rank, player) in ranks: +% for rank in ranks: - ${i} - ${player.nick_html_colors()|n} + ${rank.rank} + ${rank.nick_html_colors()|n} ${round(rank.elo, 3)} <% i += 1 %> @@ -39,5 +39,5 @@ Rank Index -${navlinks("rank_index_paged", ranks.page, ranks.last_page)} +${navlinks("rank_index_paged", ranks.page, ranks.last_page, game_type_cd=game_type_cd)} % endif diff --git a/xonstat/views/game.py b/xonstat/views/game.py index 25ab408..1ce8a9a 100755 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -3,7 +3,7 @@ import logging import re import time from pyramid.response import Response -from sqlalchemy import desc +from sqlalchemy import desc, func, over from webhelpers.paginate import Page, PageURL from xonstat.models import * from xonstat.util import page_url @@ -106,10 +106,9 @@ def rank_index(request): game_type_cd = request.matchdict['game_type_cd'] - ranks_q = DBSession.query(PlayerElo, Player).\ - filter(PlayerElo.game_type_cd==game_type_cd).\ - filter(PlayerElo.player_id==Player.player_id).\ - order_by(PlayerElo.elo.desc()) + ranks_q = DBSession.query(PlayerRank).\ + filter(PlayerRank.game_type_cd==game_type_cd).\ + order_by(PlayerRank.rank) ranks = Page(ranks_q, current_page, url=page_url) -- 2.39.2