]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Integrate the new helpers everywhere.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 14 Dec 2012 02:56:40 +0000 (21:56 -0500)
committerJan Behrens <zykure@web.de>
Sun, 23 Dec 2012 14:18:35 +0000 (15:18 +0100)
xonstat/templates/main_index.mako
xonstat/templates/map_info.mako
xonstat/templates/player_game_index.mako
xonstat/templates/player_info.mako
xonstat/templates/server_info.mako
xonstat/views/player.py

index bc227b527f5d73887d10fc78f1a6c1606a451724..e26bddf8b73a712fe2718ffb130a69ba08bb1d5c 100644 (file)
@@ -231,7 +231,7 @@ Leaderboard
           <td><span class="sprite sprite-${rg.game_type_cd}" title="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('server_info', id=rg.server_id)}" title="Go to the detail page for this server">${rg.server_name}</a></td>
           <td><a href="${request.route_url('map_info', id=rg.map_id)}" title="Go to the map detail page for this map">${rg.map_name}</a></td>
           <td><span class="sprite sprite-${rg.game_type_cd}" title="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('server_info', id=rg.server_id)}" title="Go to the detail page for this server">${rg.server_name}</a></td>
           <td><a href="${request.route_url('map_info', id=rg.map_id)}" title="Go to the map detail page for this map">${rg.map_name}</a></td>
-          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
+          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a></td>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a></td>
index 5dc5c0b2cd0501704ff604aaf09811968f41ca35..4394721f3dfd171265c7d1837cf2b59c2e3ec455 100644 (file)
@@ -170,7 +170,7 @@ ${parent.title()}
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">View</a></td>
           <td><span class="sprite sprite-${rg.game_type_cd}" alt="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('server_info', id=rg.server_id)}" title="Go to the detail page for this server">${rg.server_name}</a></td>
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">View</a></td>
           <td><span class="sprite sprite-${rg.game_type_cd}" alt="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('server_info', id=rg.server_id)}" title="Go to the detail page for this server">${rg.server_name}</a></td>
-          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
+          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a>
index 2e67e8cbc33b49a2e74e23aa37a28f59de1112a8..02f4b48b3b4ce9408666b0281b2c763c3c353144 100644 (file)
@@ -34,34 +34,34 @@ Recent Games
         </tr>
       </thead>
       <tbody>
         </tr>
       </thead>
       <tbody>
-      % for g in games.items:
+      % for rg in games.items:
         <tr>
         <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 class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">view</a></td>
+           <td class="tdcenter"><img title="${rg.game_type_cd}" src="/static/images/icons/24x24/${rg.game_type_cd}.png" alt="${rg.game_type_cd}" /></td>
+           <td>${rg.server_name}</td>
+           <td>${rg.map_name}</td>
            <td>
            <td>
-           % if g.team != None:
-             % if g.team == g.winner:
+           % if rg.team != None:
+             % if rg.team == rg.winner:
              Win
              % else:
              Loss
              % endif
           % else:
              Win
              % else:
              Loss
              % endif
           % else:
-            % if g.rank == 1:
+            % if rg.rank == 1:
             Win
             % else:
             Win
             % else:
-            Loss (#${g.rank})
+            Loss (#${rg.rank})
             % endif
           % endif
            </td>
             % 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><span class="abstime" data-epoch="${rg.epoch}" title="${rg.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
            <td class="tdcenter">
            <td class="tdcenter">
-             % if g.elo_delta is not None:
-               % 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>
+             % if rg.elo_delta is not None:
+               % if round(rg.elo_delta,2) > 0:
+               <span title="Elo went up by ${round(rg.elo_delta,2)}"><i class="icon-arrow-up icon-white"></i></span>
+               % elif round(rg.elo_delta,2) < 0:
+               <span title="Elo went down by ${round(-rg.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
                % else:
                <span title="Elo did not change"><i class="icon-minus icon-white"></i></span>
                % endif
index 2cb7a8f1a23694c3f411fa310f1bf5276c3aec05..ac6bcd05eef7c086609768c192ecb5c4e543319d 100644 (file)
@@ -439,35 +439,35 @@ Player Information
         </tr>
       </thead>
       <tbody>
         </tr>
       </thead>
       <tbody>
-      % for (gamestat, game, server, map) in recent_games:
+      % for rg in recent_games:
         <tr>
         <tr>
-           <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">view</a></td>
-           <td class="tdcenter"><span class="sprite sprite-${game.game_type_cd}" alt="${game.game_type_cd}"></span></td>
-           <td>${server.name}</td>
-           <td>${map.name}</td>
+           <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">view</a></td>
+           <td class="tdcenter"><span class="sprite sprite-${rg.game_type_cd}" alt="${rg.game_type_cd}"></span></td>
+           <td>${rg.server_name}</td>
+           <td>${rg.map_name}</td>
            <td>
            <td>
-           % if gamestat.team != None:
-             % if gamestat.team == game.winner:
+           % if rg.team != None:
+             % if rg.team == rg.winner:
              Win
              % else:
              Loss
              % endif
           % else:
              Win
              % else:
              Loss
              % endif
           % else:
-            % if gamestat.rank == 1:
+            % if rg.rank == 1:
             Win
             % else:
             Win
             % else:
-            Loss (#${gamestat.rank})
+            Loss (#${rg.rank})
             % endif
           % endif
            </td>
             % endif
           % endif
            </td>
-           <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
+           <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
            <td class="tdcenter">
            <td class="tdcenter">
-             <a href="${request.route_url('game_info', id=game.game_id, _query={'show_elo':1})}" title="View detailed information about this game">
-               % if gamestat.elo_delta is not None:
-                 % if round(gamestat.elo_delta,2) > 0:
-                 <span title="Elo went up by ${round(gamestat.elo_delta,2)}"><i class="icon-arrow-up icon-white"></i></span>
-                 % elif round(gamestat.elo_delta,2) < 0:
-                 <span title="Elo went down by ${round(-gamestat.elo_delta,2)}"><i class="icon-arrow-down icon-white"></i></span>
+             <a href="${request.route_url('game_info', id=rg.game_id, _query={'show_elo':1})}" title="View detailed information about this game">
+               % if rg.elo_delta is not None:
+                 % if round(rg.elo_delta,2) > 0:
+                 <span title="Elo went up by ${round(rg.elo_delta,2)}"><i class="icon-arrow-up icon-white"></i></span>
+                 % elif round(rg.elo_delta,2) < 0:
+                 <span title="Elo went down by ${round(-rg.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
                  % else:
                  <span title="Elo did not change"><i class="icon-minus icon-white"></i></span>
                  % endif
index 06d33bfc0924af2a7b514ebbaef3ed13011af8e2..fd36e3b89d328bbe785e023e357f4b37759faf52 100644 (file)
@@ -143,7 +143,7 @@ Server Information
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">View</a></td>
           <td><span class="sprite sprite-${rg.game_type_cd}" alt="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('map_info', id=rg.map_id)}" title="Go to the map detail page for this map">${rg.map_name}</a></td>
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">View</a></td>
           <td><span class="sprite sprite-${rg.game_type_cd}" alt="${rg.game_type_cd}"></span></td>
           <td><a href="${request.route_url('map_info', id=rg.map_id)}" title="Go to the map detail page for this map">${rg.map_name}</a></td>
-          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
+          <td><span class="abstime" data-epoch="${rg.epoch}" title="${rg.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${rg.fuzzy_date}</span></td>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a>
           <td>
             % if rg.player_id > 2:
             <a href="${request.route_url('player_info', id=rg.player_id)}" title="Go to the player info page for this player">${rg.nick_html_colors|n}</a>
index 91d0ebfb577be773de6650023fbf8a7a8908c082..d773e134efd849017869e2c4069b0e65e19f7b80 100644 (file)
@@ -8,12 +8,12 @@ import sqlalchemy.sql.functions as func
 import time
 from calendar import timegm
 from collections import namedtuple
 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 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__)
 
 
 log = logging.getLogger(__name__)
 
@@ -391,27 +391,13 @@ def get_elos(player_id):
 
 def get_recent_games(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):
 
 
 def get_recent_weapons(player_id):
@@ -609,10 +595,6 @@ def player_info_json(request):
 
 
 def player_game_index_data(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'):
     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()
 
         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
 
         # 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
 
     except Exception as e:
         player = None