<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><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>
</tr>
</thead>
<tbody>
- % for g in games.items:
+ % for rg 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 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>
- % 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
</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">
- % 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
</tr>
</thead>
<tbody>
- % for (gamestat, game, server, map) in recent_games:
+ % for rg in recent_games:
<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>
- % 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
</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">
- <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
<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>
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__)
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 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 = 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