<%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">
</%block>
<%block name="title">
-Game Index
+Recent Games
</%block>
% if not games:
% 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>
"""
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,
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'):
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).\
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):