]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Make the "recent games" table expand with the "more" link.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 7 Oct 2012 02:37:09 +0000 (22:37 -0400)
committerJan Behrens <zykure@web.de>
Sun, 23 Dec 2012 14:18:33 +0000 (15:18 +0100)
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
xonstat/views/player.py

index 5de8b1c2b7c7c251e445d680330fb9962721a0e0..1ed3b1575718c3c51aeeb3a5c80ea2733af2c21f 100644 (file)
@@ -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>
 
 <%block name="title">
-Game Index
+Recent Games
 </%block>
 
 % if not games:
@@ -17,13 +16,59 @@ Game Index
 % else:
 <div class="row">
   <div class="span12">
-    <h2>Recent Games</h2>
-    % for (game, server, map) in games:
-    <div class="game">
-      <h4><img src="/static/images/icons/48x48/${game.game_type_cd}.png" width="30" height="30" /><a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for ${map.name}">${map.name}</a> on <a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for ${server.name}">${server.name}</a> <span class="permalink">(<a href="${request.route_url('game_info', id=game.game_id)}" name="Permalink for game #${game.game_id}">permalink</a>)</span></h4>
-      ${scoreboard(game.game_type_cd, pgstats[game.game_id])}
-    </div>
-    % endfor
+    <h3>Recent Games by ${player.nick_html_colors()|n}</h3>
+  </div>
+</div>
+<div class="row">
+  <div class="span12">
+    <table class="table table-bordered table-condensed">
+      <thead>
+        <tr>
+           <th></th>
+           <th>Type</th>
+           <th>Server</th>
+           <th>Map</th>
+           <th>Result</th>
+           <th>Played</th>
+           <th>Elo</th>
+        </tr>
+      </thead>
+      <tbody>
+      % for g in games.items:
+        <tr>
+           <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=g.game_id)}" title="View detailed information about this game">view</a></td>
+           <td class="tdcenter"><img title="${g.game_type_cd}" src="/static/images/icons/24x24/${g.game_type_cd}.png" alt="${g.game_type_cd}" /></td>
+           <td>${g.server_name}</td>
+           <td>${g.map_name}</td>
+           <td>
+           % 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
+           </td>
+           <td><span class="abstime" data-epoch="${g.game_epoch}" title="${g.game_create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${g.game_fuzzy}</span></td>
+           <td class="tdcenter">
+             % if round(g.elo_delta,2) > 0:
+             <span title="Elo went up by ${round(g.elo_delta,2)}"><i class="icon-arrow-up icon-white"></i></span>
+             % elif round(g.elo_delta,2) < 0:
+             <span title="Elo went down by ${round(g.elo_delta,2)}"><i class="icon-arrow-down icon-white"></i></span>
+             % else:
+             <span title="Elo did not change"><i class="icon-minus icon-white"></i></span>
+             % endif
+           </td>
+        </tr>
+      % endfor
+      </tbody>
+    </table>
   </div>
 </div>
 
index 79ff34b3cbd4b1c19b8d867d6767788f5ac019a8..8d3c8bb17624dd0c10be980a67a756d180a6740f 100644 (file)
@@ -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):