From: Ant Zucaro Date: Fri, 14 Dec 2012 02:56:40 +0000 (-0500) Subject: Integrate the new helpers everywhere. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ed32fac23d415ca3f50cb2f6f0bc1049a509f7c9;p=xonotic%2Fxonstat.git Integrate the new helpers everywhere. --- diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako index bc227b5..e26bddf 100644 --- a/xonstat/templates/main_index.mako +++ b/xonstat/templates/main_index.mako @@ -231,7 +231,7 @@ Leaderboard ${rg.server_name} ${rg.map_name} - ${rg.fuzzy_date} + ${rg.fuzzy_date} % if rg.player_id > 2: ${rg.nick_html_colors|n} diff --git a/xonstat/templates/map_info.mako b/xonstat/templates/map_info.mako index 5dc5c0b..4394721 100644 --- a/xonstat/templates/map_info.mako +++ b/xonstat/templates/map_info.mako @@ -170,7 +170,7 @@ ${parent.title()} View ${rg.server_name} - ${rg.fuzzy_date} + ${rg.fuzzy_date} % if rg.player_id > 2: ${rg.nick_html_colors|n} diff --git a/xonstat/templates/player_game_index.mako b/xonstat/templates/player_game_index.mako index 2e67e8c..02f4b48 100644 --- a/xonstat/templates/player_game_index.mako +++ b/xonstat/templates/player_game_index.mako @@ -34,34 +34,34 @@ Recent Games - % for g in games.items: + % for rg in games.items: - view - ${g.game_type_cd} - ${g.server_name} - ${g.map_name} + view + ${rg.game_type_cd} + ${rg.server_name} + ${rg.map_name} - % if g.team != None: - % if g.team == g.winner: + % if rg.team != None: + % if rg.team == rg.winner: Win % else: Loss % endif % else: - % if g.rank == 1: + % if rg.rank == 1: Win % else: - Loss (#${g.rank}) + Loss (#${rg.rank}) % endif % endif - ${g.game_fuzzy} + ${rg.fuzzy_date} - % if g.elo_delta is not None: - % if round(g.elo_delta,2) > 0: - - % elif round(g.elo_delta,2) < 0: - + % if rg.elo_delta is not None: + % if round(rg.elo_delta,2) > 0: + + % elif round(rg.elo_delta,2) < 0: + % else: % endif diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index 2cb7a8f..ac6bcd0 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -439,35 +439,35 @@ Player Information - % for (gamestat, game, server, map) in recent_games: + % for rg in recent_games: - view - - ${server.name} - ${map.name} + view + + ${rg.server_name} + ${rg.map_name} - % if gamestat.team != None: - % if gamestat.team == game.winner: + % if rg.team != None: + % if rg.team == rg.winner: Win % else: Loss % endif % else: - % if gamestat.rank == 1: + % if rg.rank == 1: Win % else: - Loss (#${gamestat.rank}) + Loss (#${rg.rank}) % endif % endif - ${game.fuzzy_date()} + ${rg.fuzzy_date} - - % if gamestat.elo_delta is not None: - % if round(gamestat.elo_delta,2) > 0: - - % elif round(gamestat.elo_delta,2) < 0: - + + % if rg.elo_delta is not None: + % if round(rg.elo_delta,2) > 0: + + % elif round(rg.elo_delta,2) < 0: + % else: % endif diff --git a/xonstat/templates/server_info.mako b/xonstat/templates/server_info.mako index 06d33bf..fd36e3b 100644 --- a/xonstat/templates/server_info.mako +++ b/xonstat/templates/server_info.mako @@ -143,7 +143,7 @@ Server Information View ${rg.map_name} - ${rg.fuzzy_date} + ${rg.fuzzy_date} % if rg.player_id > 2: ${rg.nick_html_colors|n} diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 91d0ebf..d773e13 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -8,12 +8,12 @@ import sqlalchemy.sql.functions as func import time from calendar import timegm from collections import namedtuple -from pyramid.response import Response from pyramid.url import current_route_url from sqlalchemy import desc, distinct from webhelpers.paginate import Page, PageURL from xonstat.models import * from xonstat.util import page_url, to_json, pretty_date +from xonstat.views.helpers import RecentGame, recent_games_q log = logging.getLogger(__name__) @@ -391,27 +391,13 @@ def get_elos(player_id): def get_recent_games(player_id): """ - Provides a list of recent games. - - Returns the full PlayerGameStat, Game, Server, Map - objects for all recent games. + Provides a list of recent games for a player. Uses the recent_games_q helper. """ - RecentGame = namedtuple('RecentGame', ['player_stats', 'game', 'server', 'map']) - - # recent games table, all data - recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\ - filter(PlayerGameStat.player_id == player_id).\ - filter(PlayerGameStat.game_id == Game.game_id).\ - filter(Game.server_id == Server.server_id).\ - filter(Game.map_id == Map.map_id).\ - order_by(Game.game_id.desc())[0:10] + # recent games played in descending order + rgs = recent_games_q(player_id=player_id).limit(10).all() + recent_games = [RecentGame(row) for row in rgs] - return [ - RecentGame(player_stats=row.PlayerGameStat, - game=row.Game, - server=row.Server, - map=row.Map) - for row in recent_games ] + return recent_games def get_recent_weapons(player_id): @@ -609,10 +595,6 @@ def player_info_json(request): def player_game_index_data(request): - RecentGame = namedtuple('RecentGame', ['game_id', 'game_type_cd', 'winner', - 'game_create_dt', 'game_epoch', 'game_fuzzy', 'server_id', - 'server_name', 'map_id', 'map_name', 'team', 'rank', 'elo_delta']) - player_id = request.matchdict['player_id'] if request.params.has_key('page'): @@ -624,35 +606,12 @@ def player_game_index_data(request): player = DBSession.query(Player).filter_by(player_id=player_id).\ filter(Player.active_ind == True).one() - games_q = DBSession.query(Game.game_id, Game.game_type_cd, Game.winner, - Game.create_dt, Server.server_id, - Server.name.label('server_name'), Map.map_id, - Map.name.label('map_name'), PlayerGameStat.team, - PlayerGameStat.rank, PlayerGameStat.elo_delta).\ - filter(PlayerGameStat.game_id == Game.game_id).\ - filter(PlayerGameStat.player_id == player_id).\ - filter(Game.server_id == Server.server_id).\ - filter(Game.map_id == Map.map_id).\ - order_by(Game.game_id.desc()) + rgs_q = recent_games_q(player_id=player.player_id) - games = Page(games_q, current_page, items_per_page=10, url=page_url) + games = Page(rgs_q, current_page, items_per_page=10, url=page_url) # replace the items in the canned pagination class with more rich ones - games.items = [RecentGame( - game_id = row.game_id, - game_type_cd = row.game_type_cd, - winner = row.winner, - game_create_dt = row.create_dt, - game_epoch = timegm(row.create_dt.timetuple()), - game_fuzzy = pretty_date(row.create_dt), - server_id = row.server_id, - server_name = row.server_name, - map_id = row.map_id, - map_name = row.map_name, - team = row.team, - rank = row.rank, - elo_delta = row.elo_delta - ) for row in games.items] + games.items = [RecentGame(row) for row in games.items] except Exception as e: player = None