]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add favorite map support.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 18 Jun 2012 00:10:20 +0000 (20:10 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 18 Jun 2012 00:10:20 +0000 (20:10 -0400)
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
xonstat/views/player.py

index da1057aaed5f3aa2887a461dc524824865ce968f..f154463ecd66d9a65ebfdc63a7d99009d8cee26c 100644 (file)
@@ -156,8 +156,6 @@ ${nav.nav('players')}
               dataType: 'json',
               success: plot_dmg_graph
           });
-
-
       })
       </script>
     % endif
@@ -174,26 +172,44 @@ Player Information
 
 % else:
 <div class="row">
-  <div class="span8">
+  <div class="span12">
     <h2>${player.nick_html_colors()|n}</h2>
+  </div>
+</div>
+
+<div class="row">
+  <div class="span6">
+    <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>${total_stats['alivetime']} </small><br />
+
+      <% 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 />
+
+      % if fav_map is not None:
+      Favorite Map: <small><a href="${request.route_url('map_info', id=fav_map.map_id)}" title="view map info">${fav_map.name}</a></small><br />
+      % endif
+    </p>
+  </div>
+  <div class="span6">
     <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>${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 />
+
        % if elos_display is not None and len(elos_display) > 0:
        Elo:
           <small>${', '.join(elos_display)} </small>
           <br />
           %if '*' in ', '.join(elos_display):
-              <small><i>*preliminary Elo</i></small>
+              <small><i>*preliminary Elo</i></small><br />
           %endif
       % endif
     </p>
index d2112515ed82ff1cc911a2b993667d9976fbef69..9eaf218f20026eb89a567ba03450f88abd727920 100644 (file)
@@ -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,
             }