From 61b082e0432dbdab0b200257efa79a50ad96a304 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sat, 6 Oct 2012 22:37:09 -0400 Subject: [PATCH] Make the "recent games" table expand with the "more" link. Previously a big list of scoreboards would be shown if a person clicked on the "more" link below the "recent games" table on the player info page. Now a table that is exactly the same is shown, but with pagination. This is in essence an attempt to keep the same elements in the view; when a person clicks on a "more" link, they expect to see more of the same items they were looking at. The end benefit for players is that they can quickly page through all of their games and see summary results as well as their elo changes from one simple view. --- xonstat/templates/player_game_index.mako | 63 ++++++++++++++++++++---- xonstat/views/player.py | 60 +++++++++++++++------- 2 files changed, 96 insertions(+), 27 deletions(-) diff --git a/xonstat/templates/player_game_index.mako b/xonstat/templates/player_game_index.mako index 5de8b1c..1ed3b15 100644 --- a/xonstat/templates/player_game_index.mako +++ b/xonstat/templates/player_game_index.mako @@ -1,6 +1,5 @@ <%inherit file="base.mako"/> <%namespace name="nav" file="nav.mako" /> -<%namespace file="scoreboard.mako" import="scoreboard" /> <%namespace file="navlinks.mako" import="navlinks" /> <%block name="navigation"> @@ -8,7 +7,7 @@ ${nav.nav('games')} <%block name="title"> -Game Index +Recent Games % if not games: @@ -17,13 +16,59 @@ Game Index % else:
-

Recent Games

- % for (game, server, map) in games: -
-

${map.name} on ${server.name} (permalink)

- ${scoreboard(game.game_type_cd, pgstats[game.game_id])} -
- % endfor +

Recent Games by ${player.nick_html_colors()|n}

+
+
+
+
+ + + + + + + + + + + + + + % for g in games.items: + + + + + + + + + + % endfor + +
TypeServerMapResultPlayedElo
view${g.game_type_cd}${g.server_name}${g.map_name} + % if g.team != None: + % if g.team == g.winner: + Win + % else: + Loss + % endif + % else: + % if g.rank == 1: + Win + % else: + Loss (#${g.rank}) + % endif + % endif + ${g.game_fuzzy} + % if round(g.elo_delta,2) > 0: + + % elif round(g.elo_delta,2) < 0: + + % else: + + % endif +
diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 79ff34b..8d3c8bb 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -561,38 +561,38 @@ def player_info_json(request): """ Provides detailed information on a specific player. JSON. """ - + # All player_info fields are converted into JSON-formattable dictionaries player_info = player_info_data(request) - + player = player_info['player'].to_dict() games_played = {} for game in player_info['games_played']: games_played[game.game_type_cd] = to_json(game) - + overall_stats = {} for gt,stats in player_info['overall_stats'].items(): overall_stats[gt] = to_json(stats) - + elos = {} for gt,elo in player_info['elos'].items(): elos[gt] = to_json(elo.to_dict()) - + ranks = {} for gt,rank in player_info['ranks'].items(): ranks[gt] = to_json(rank) - + fav_maps = {} for gt,mapinfo in player_info['fav_maps'].items(): fav_maps[gt] = to_json(mapinfo) - + recent_games = [] for game in player_info['recent_games']: recent_games.append(to_json(game)) - + #recent_weapons = player_info['recent_weapons'] - + return [{ 'player': player, 'games_played': games_played, @@ -608,6 +608,10 @@ 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'): @@ -616,7 +620,14 @@ def player_game_index_data(request): current_page = 1 try: - games_q = DBSession.query(Game, Server, Map).\ + 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).\ @@ -625,20 +636,33 @@ def player_game_index_data(request): games = Page(games_q, current_page, items_per_page=10, url=page_url) - pgstats = {} - for (game, server, map) in games: - pgstats[game.game_id] = DBSession.query(PlayerGameStat).\ - filter(PlayerGameStat.game_id == game.game_id).\ - order_by(PlayerGameStat.rank).\ - order_by(PlayerGameStat.score).all() + # 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] except Exception as e: + raise e player = None games = None - return {'player_id':player_id, + return { + 'player_id':player.player_id, + 'player':player, 'games':games, - 'pgstats':pgstats} + } def player_game_index(request): -- 2.39.2