]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Implemented feature #1228:
authorJan D. Behrens <zykure@web.de>
Sat, 4 Aug 2012 20:46:21 +0000 (22:46 +0200)
committerJan D. Behrens <zykure@web.de>
Wed, 8 Aug 2012 10:54:46 +0000 (12:54 +0200)
Show weekly/monthly timer on the player_info page - http://dev.xonotic.org/issues/1228

Also added "suicides" to kill/death statistics (number only, no ratio)

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

index c01ff1a65d1c7a8df464aa024e71facc226545e3..444d97f5aea4eff2c972bdc321a1d297cde5c0ff 100644 (file)
@@ -189,7 +189,15 @@ Player Information
 
       Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
 
-      Playing Time: <small>${total_stats['alivetime']} </small><br />
+      Playing Time: <small>${total_stats['alivetime']} hours
+      % if total_stats['alivetime'] > total_stats['alivetime_month']:
+          % if total_stats['alivetime_month'] > total_stats['alivetime_week']:
+              (${total_stats['alivetime_month']} hours this month; ${total_stats['alivetime_week']} hours this week)
+          % else:
+              (${total_stats['alivetime_month']} hours this month)
+          % endif
+      % endif
+      </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 />
@@ -230,7 +238,7 @@ Player Information
        % 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 />
+       Kill Ratio: <small>${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths, ${total_stats['suicides']} suicides) </small><br />
        % endif
 
        % if elos_display is not None and len(elos_display) > 0:
index 5f211d3e84d97aa836cb5da5aeefa1dd3f786f5c..443e9d5816e2b008ad3c592799128aec5511c459 100644 (file)
@@ -83,30 +83,45 @@ def _get_total_stats(player_id):
 
     kills = how many kills a player has over all games
     deaths = how many deaths a player has over all games
+    suicides = how many suicides a player has over all games
     alivetime = how long a player has played over all games
+    alivetime_week = how long a player has played over all games in the last week
+    alivetime_month = how long a player has played over all games in the last month
+    wins = how many games a player has won
 
     If any of the above are None, they are set to 0.
     """
+    # 7 and 30 day windows
+    one_week_ago  = datetime.datetime.utcnow() - datetime.timedelta(days=7)
+    one_month_ago = datetime.datetime.utcnow() - datetime.timedelta(days=30)
+
     total_stats = {}
-    (total_stats['kills'], total_stats['deaths'], total_stats['alivetime']) = DBSession.\
-            query("total_kills", "total_deaths", "total_alivetime").\
-            from_statement(
-                "select sum(kills) total_kills, "
-                "sum(deaths) total_deaths, "
-                "sum(alivetime) total_alivetime "
-                "from player_game_stats "
-                "where player_id=:player_id"
-            ).params(player_id=player_id).one()
-
-    (total_stats['wins'],) = DBSession.\
-            query("total_wins").\
-            from_statement(
-                "select count(*) total_wins "
-                "from games g, player_game_stats pgs "
-                "where g.game_id = pgs.game_id "
-                "and player_id=:player_id "
-                "and (g.winner = pgs.team or pgs.rank = 1)"
-            ).params(player_id=player_id).one()
+    (total_stats['kills'], total_stats['deaths'], total_stats['suicides'], total_stats['alivetime'],) = DBSession.query(
+            func.sum(PlayerGameStat.kills),
+            func.sum(PlayerGameStat.deaths),
+            func.sum(PlayerGameStat.suicides),
+            func.sum(PlayerGameStat.alivetime)).\
+            filter(PlayerGameStat.player_id == player_id).\
+            one()
+
+    (total_stats['alivetime_week'],) = DBSession.query(
+            func.sum(PlayerGameStat.alivetime)).\
+            filter(PlayerGameStat.player_id == player_id).\
+            filter(PlayerGameStat.create_dt > one_week_ago).\
+            one()
+
+    (total_stats['alivetime_month'],) = DBSession.query(
+            func.sum(PlayerGameStat.alivetime)).\
+            filter(PlayerGameStat.player_id == player_id).\
+            filter(PlayerGameStat.create_dt > one_month_ago).\
+            one()
+
+    (total_stats['wins'],) = DBSession.query(
+            func.count("*")).\
+            filter(Game.game_id == PlayerGameStat.game_id).\
+            filter(PlayerGameStat.player_id == player_id).\
+            filter(Game.winner == PlayerGameStat.team or PlayerGameStat.rank == 1).\
+            one()
 
     for (key,value) in total_stats.items():
         if value == None: