]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add an itemized breakdown of the games played by a player.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 15 Mar 2012 11:16:08 +0000 (07:16 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 15 Mar 2012 11:16:08 +0000 (07:16 -0400)
This is so we can see how many of each type of game type that the player has played. It will look like <total games played> (<number of games played> <game type cd>).

xonstat/templates/player_info.mako
xonstat/views/player.py

index befb2d3d5366266d69e36faeb94bf7a0088608aa..1482ae96e8b314b0847146d75be34ea104bc2697 100755 (executable)
@@ -23,7 +23,8 @@ Player Information
        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 />
-       Games Played: <small>${game_stats['total_games_played']} </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 />
        Average Rank: <small>${game_stats['avg_rank']} </small><br />
        % if elos_display is not None and len(elos_display) > 0:
        Elo:
index 7fcfd62bdcc2414609f1713f6715873f1b5a99a3..9bdb6ed756f56b2fe77ba42ba734fa6c31dcae94 100755 (executable)
@@ -2,6 +2,7 @@ import datetime
 import logging\r
 import re\r
 import sqlalchemy as sa\r
+import sqlalchemy.sql.functions as func\r
 import time\r
 from pyramid.response import Response\r
 from pyramid.url import current_route_url\r
@@ -46,6 +47,27 @@ def player_index(request):
             }\r
 \r
 \r
+def games_played(player_id):\r
+    """\r
+    Provides a breakdown by gametype of the games played by player_id.\r
+\r
+    Returns a tuple containing (total_games, games_breakdown), where\r
+    total_games is the absolute number of games played by player_id\r
+    and games_breakdown is an array containing (game_type_cd, # games)\r
+    """\r
+    games_played = DBSession.query(Game.game_type_cd, func.count()).\\r
+            filter(Game.game_id == PlayerGameStat.game_id).\\r
+            filter(PlayerGameStat.player_id == player_id).\\r
+            group_by(Game.game_type_cd).\\r
+            order_by(func.count().desc()).all()\r
+\r
+    total = 0\r
+    for (game_type_cd, games) in games_played:\r
+        total += games\r
+\r
+    return (total, games_played)\r
+\r
+\r
 def player_info(request):\r
     """\r
     Provides detailed information on a specific player\r
@@ -58,6 +80,8 @@ def player_info(request):
         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
+\r
         elos = DBSession.query(PlayerElo).filter_by(player_id=player_id).\\r
                 filter(PlayerElo.game_type_cd.in_(['ctf','duel','dm'])).\\r
                 order_by(PlayerElo.elo.desc()).all()\r
@@ -136,12 +160,16 @@ def player_info(request):
         weapon_stats = None\r
         game_stats = None\r
         recent_games = None\r
+        total_games = None\r
+        games_breakdown = None\r
 \r
     return {'player':player, \r
             'elos_display':elos_display,\r
             'recent_games':recent_games,\r
             'weapon_stats':weapon_stats,\r
-            'game_stats':game_stats}\r
+            'game_stats':game_stats, \r
+            'total_games':total_games,\r
+            'games_breakdown':games_breakdown}\r
 \r
 \r
 def player_game_index(request):\r