From efe51fc9fb1d23a04fde1fb5b1f6e05d6abdbff4 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sun, 17 Jun 2012 20:10:20 -0400 Subject: [PATCH] Add favorite map support. This commit adds a line item to the player_info page showing the player's favorite map. This is the map the player has played the most in the past 90 days. A link to the map_info page of that map in included. --- xonstat/templates/player_info.mako | 34 ++++++++++++++++++++++-------- xonstat/views/player.py | 27 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index da1057a..f154463 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -156,8 +156,6 @@ ${nav.nav('players')} dataType: 'json', success: plot_dmg_graph }); - - }) % endif @@ -174,26 +172,44 @@ Player Information % else:
-
+

${player.nick_html_colors()|n}

+
+
+ +
+
+

+ Member Since: ${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')}
+ + Last Seen: ${recent_games[0][1].fuzzy_date()}
+ + Playing Time: ${total_stats['alivetime']}
+ + <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %> + Games Played: ${total_games} (${games_breakdown_str})
+ + % if fav_map is not None: + Favorite Map: ${fav_map.name}
+ % endif +

+
+

- Member Since: ${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')}
- Last Seen: ${recent_games[0][1].fuzzy_date()}
- Playing Time: ${total_stats['alivetime']}
% if total_games > 0 and total_stats['wins'] is not None: Win Percentage: ${round(float(total_stats['wins'])/total_games * 100, 2)}% (${total_stats['wins']} wins, ${total_games - total_stats['wins']} losses)
% endif + % if total_stats['kills'] > 0 and total_stats['deaths'] > 0: Kill Ratio: ${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths)
% endif - <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %> - Games Played: ${total_games} (${games_breakdown_str})
+ % if elos_display is not None and len(elos_display) > 0: Elo: ${', '.join(elos_display)}
%if '*' in ', '.join(elos_display): - *preliminary Elo + *preliminary Elo
%endif % endif

diff --git a/xonstat/views/player.py b/xonstat/views/player.py index d211251..9eaf218 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -115,6 +115,29 @@ def _get_total_stats(player_id): return total_stats +def _get_fav_map(player_id): + """ + Get the player's favorite map. The favorite map is defined + as the map that he or she has played the most in the past + 90 days. + + Returns a map object. + """ + # 90 day window + back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90) + + fav_map = DBSession.query(Map).\ + filter(Game.game_id == PlayerGameStat.game_id).\ + filter(Game.map_id == Map.map_id).\ + filter(PlayerGameStat.player_id == player_id).\ + filter(PlayerGameStat.create_dt > back_then).\ + group_by(Map.map_id).\ + order_by(func.count().desc()).\ + limit(1).one() + + return fav_map + + def get_accuracy_stats(player_id, weapon_cd, games): """ Provides accuracy for weapon_cd by player_id for the past N games. @@ -211,6 +234,8 @@ def _player_info_data(request): # games breakdown - N games played (X ctf, Y dm) etc (total_games, games_breakdown) = _get_games_played(player.player_id) + # favorite map from the past 90 days + fav_map = _get_fav_map(player.player_id) # friendly display of elo information and preliminary status elos = DBSession.query(PlayerElo).filter_by(player_id=player_id).\ @@ -255,6 +280,7 @@ def _player_info_data(request): total_games = None games_breakdown = None recent_weapons = [] + fav_map = None return {'player':player, 'elos_display':elos_display, @@ -263,6 +289,7 @@ def _player_info_data(request): 'total_games':total_games, 'games_breakdown':games_breakdown, 'recent_weapons':recent_weapons, + 'fav_map':fav_map, } -- 2.39.2