<p>
Member Since: <small>${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')} </small><br />
Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
- Playing Time: <small>${game_stats['total_alivetime']} </small><br />
+ Playing Time: <small>${total_stats['alivetime']} </small><br />
+ % if total_games > 0 and total_stats['wins'] is not None:
+ Win Percentage: <small>${round(float(total_stats['wins'])/total_games * 100, 2)}% (${total_stats['wins']} wins, ${total_games - total_stats['wins']} losses) </small><br />
+ % endif
+ % if total_stats['kills'] > 0 and total_stats['deaths'] > 0:
+ Kill Ratio: <small>${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths) </small><br />
+ % endif
<% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %>
Games Played: <small>${total_games} (${games_breakdown_str})</small><br />
- Average Rank: <small>${game_stats['avg_rank']} </small><br />
% if elos_display is not None and len(elos_display) > 0:
Elo:
<small>${', '.join(elos_display)} </small>
% endif
-% if game_stats:
-<div class="row">
- <div class="span12">
- <h3>Overall Game Stats</h2>
- <table class="table table-bordered table-condensed">
- <thead>
- <tr>
- <th>Score</th>
- <th>Carrier Kills</th>
- <th>Kills</th>
- <th>Collects</th>
- <th>Deaths</th>
- <th>Destroys</th>
- <th>Suicides</th>
- <th>Destroys (with key)</th>
- <th>Captures</th>
- <th>Pushes</th>
- <th>Pickups</th>
- <th>Pushed</th>
- <th>Drops</th>
- <th>Returns</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>${game_stats['total_score']}</td>
- <td>${game_stats['total_carrier_frags']}</td>
- <td>${game_stats['total_kills']}</td>
- <td>${game_stats['total_collects']}</td>
- <td>${game_stats['total_deaths']}</td>
- <td>${game_stats['total_destroys']}</td>
- <td>${game_stats['total_suicides']}</td>
- <td>${game_stats['total_destroys']}</td>
- <td>${game_stats['total_captures']}</td>
- <td>${game_stats['total_pushes']}</td>
- <td>${game_stats['total_pickups']}</td>
- <td>${game_stats['total_pushed']}</td>
- <td>${game_stats['total_drops']}</td>
- <td>${game_stats['total_returns']}</td>
- </tr>
- </tbody>
- </table>
- % endif
- </div>
-</div>
-
-
% if weapon_stats:
<div class="row">
<div class="span12">
##### RECENT GAMES (v2) ####
% if recent_games:
<div class="row">
- <div class="span6">
+ <div class="span12">
<h3>Recent Games</h3>
<table class="table table-bordered table-condensed">
<thead>
<tr>
- <th>Game Type</th>
+ <th></th>
+ <th>Type</th>
+ <th>Server</th>
<th>Map</th>
<th>Result</th>
<th>Played</th>
- <th>Permalink</th>
</tr>
</thead>
<tbody>
% for (gamestat, game, server, map) in recent_games:
<tr>
- <td><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
+ <td><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 style="width:20px;"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
+ <td>${server.name}</td>
<td>${map.name}</td>
<td>
- % if gamestat.team != None and gamestat.team == game.winner:
- Won (#${gamestat.rank})
- % elif gamestat.team != None and gamestat.team != game.winner:
- Lost (#${gamestat.rank})
- % else:
- #${gamestat.rank}
- % endif
+ % if gamestat.team != None:
+ % if gamestat.team == game.winner:
+ Win
+ % else:
+ Loss
+ % endif
+ % else:
+ % if gamestat.rank == 1:
+ Win
+ % else:
+ Loss (#${gamestat.rank})
+ % endif
+ % endif
</td>
<td>${game.fuzzy_date()}</td>
- <td><a class="recent_game_box" href="${request.route_url("game_info", id=game.game_id)}" name="Game info page for game #${game.game_id}">View</a></td>
</tr>
% endfor
</tbody>
</table>
- % if game_stats['total_games_played'] > 10:
+ % if total_games > 10:
<a href="${request.route_url("player_game_index", player_id=player.player_id, page=1)}" title="Game index for ${player.nick}">More games played by ${player.nick_html_colors()|n}...</a>
% endif
</div>
}\r
\r
\r
-def games_played(player_id):\r
+def get_games_played(player_id):\r
"""\r
Provides a breakdown by gametype of the games played by player_id.\r
\r
return (total, games_played)\r
\r
\r
+# TODO: should probably factor the above function into this one such that\r
+# total_stats['ctf_games'] is the count of CTF games and so on...\r
+def get_total_stats(player_id):\r
+ """\r
+ Provides aggregated stats by player_id.\r
+\r
+ Returns a dict with the keys 'kills', 'deaths', 'alivetime'.\r
+\r
+ kills = how many kills a player has over all games\r
+ deaths = how many deaths a player has over all games\r
+ alivetime = how long a player has played over all games\r
+\r
+ If any of the above are None, they are set to 0.\r
+ """\r
+ total_stats = {}\r
+ (total_stats['kills'], total_stats['deaths'], total_stats['alivetime']) = DBSession.\\r
+ query("total_kills", "total_deaths", "total_alivetime").\\r
+ from_statement(\r
+ "select sum(kills) total_kills, "\r
+ "sum(deaths) total_deaths, "\r
+ "sum(alivetime) total_alivetime "\r
+ "from player_game_stats "\r
+ "where player_id=:player_id"\r
+ ).params(player_id=player_id).one()\r
+\r
+ (total_stats['wins'],) = DBSession.\\r
+ query("total_wins").\\r
+ from_statement(\r
+ "select count(*) total_wins "\r
+ "from games g, player_game_stats pgs "\r
+ "where g.game_id = pgs.game_id "\r
+ "and player_id=:player_id "\r
+ "and (g.winner = pgs.team or pgs.rank = 1)"\r
+ ).params(player_id=player_id).one()\r
+\r
+ for (key,value) in total_stats.items():\r
+ if value == None:\r
+ total_stats[key] = 0\r
+\r
+ return total_stats\r
+\r
+\r
def player_info(request):\r
"""\r
Provides detailed information on a specific player\r
player = DBSession.query(Player).filter_by(player_id=player_id).\\r
filter(Player.active_ind == True).one()\r
\r
- (total_games, games_breakdown) = games_played(player.player_id)\r
+ (total_games, games_breakdown) = get_games_played(player.player_id)\r
+\r
+ total_stats = get_total_stats(player.player_id)\r
\r
elos = DBSession.query(PlayerElo).filter_by(player_id=player_id).\\r
filter(PlayerElo.game_type_cd.in_(['ctf','duel','dm'])).\\r
filter(Game.map_id == Map.map_id).\\r
order_by(Game.game_id.desc())[0:10]\r
\r
- game_stats = {}\r
- (game_stats['avg_rank'], game_stats['total_kills'], \r
- game_stats['total_deaths'], game_stats['total_suicides'], \r
- game_stats['total_score'], game_stats['total_time'], \r
- game_stats['total_held'], game_stats['total_captures'], \r
- game_stats['total_pickups'],game_stats['total_drops'], \r
- game_stats['total_returns'], game_stats['total_collects'], \r
- game_stats['total_destroys'], game_stats['total_dhk'], \r
- game_stats['total_pushes'], game_stats['total_pushed'], \r
- game_stats['total_carrier_frags'], \r
- game_stats['total_alivetime'],\r
- game_stats['total_games_played']) = DBSession.\\r
- query("avg_rank", "total_kills", "total_deaths", \r
- "total_suicides", "total_score", "total_time", "total_held",\r
- "total_captures", "total_pickups", "total_drops", \r
- "total_returns", "total_collects", "total_destroys", \r
- "total_dhk", "total_pushes", "total_pushed", \r
- "total_carrier_frags", "total_alivetime", \r
- "total_games_played").\\r
- from_statement(\r
- "select round(avg(rank)) avg_rank, sum(kills) total_kills, "\r
- "sum(deaths) total_deaths, sum(suicides) total_suicides, "\r
- "sum(score) total_score, sum(time) total_time, "\r
- "sum(held) total_held, sum(captures) total_captures, "\r
- "sum(pickups) total_pickups, sum(drops) total_drops, "\r
- "sum(returns) total_returns, sum(collects) total_collects, "\r
- "sum(destroys) total_destroys, sum(destroys_holding_key) total_dhk, "\r
- "sum(pushes) total_pushes, sum(pushed) total_pushed, "\r
- "sum(carrier_frags) total_carrier_frags, "\r
- "sum(alivetime) total_alivetime, count(*) total_games_played "\r
- "from player_game_stats "\r
- "where player_id=:player_id"\r
- ).params(player_id=player_id).one()\r
-\r
- for (key,value) in game_stats.items():\r
- if value == None:\r
- game_stats[key] = '-'\r
-\r
except Exception as e:\r
player = None\r
elos_display = None\r
weapon_stats = None\r
- game_stats = None\r
+ total_stats = None\r
recent_games = None\r
total_games = None\r
games_breakdown = None\r
'elos_display':elos_display,\r
'recent_games':recent_games,\r
'weapon_stats':weapon_stats,\r
- 'game_stats':game_stats, \r
+ 'total_stats':total_stats, \r
'total_games':total_games,\r
'games_breakdown':games_breakdown}\r
\r