]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Fixed some bugs in the latest commits (e.g. DB queries, website layout)
authorJan D. Behrens <zykure@web.de>
Sun, 5 Aug 2012 15:54:00 +0000 (17:54 +0200)
committerJan D. Behrens <zykure@web.de>
Wed, 8 Aug 2012 10:54:47 +0000 (12:54 +0200)
xonstat/templates/player_info.mako
xonstat/views/player.py

index d86ceb5e6b55fc23f79c4240fd21555d14b80514..4e44f3f82da4650ceed903ec8a19c72fef5b7ecb 100644 (file)
@@ -190,8 +190,8 @@ Player Information
       Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
 
       % if fav_server is not None:
-      Favorite Server: <small>
-      <% srv_list = fav_server[:1] %>
+      Favorite Servers: <small>
+      <% srv_list = fav_server[:3] %>
       % for srvinfo in srv_list:
           % if srvinfo != srv_list[-1]:
               <% delim = ", " %>
@@ -234,18 +234,18 @@ Player Information
   </div>
   <div class="span6">
     <p>
-      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)
+      Playing Time: <small>${total_stats['alivetime']}
+      % if total_stats['alivetime_month'] and total_stats['alivetime'] > total_stats['alivetime_month']:
+          % if total_stats['alivetime_week'] and total_stats['alivetime_month'] > total_stats['alivetime_week']:
+              <br />(${total_stats['alivetime_month']} this month; ${total_stats['alivetime_week']} this week)
           % else:
-              (${total_stats['alivetime_month']} hours this month)
+              <br />(${total_stats['alivetime_month']} this month)
           % endif
       % endif
       </small><br />
 
       <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in total_stats['games_breakdown'].items()]) %>
-      Games Played: <small>${total_stats['games']} (${games_breakdown_str})</small><br />
+      Games Played: <small>${total_stats['games']}<br />(${games_breakdown_str})</small><br />
 
        % if total_stats['games'] > 0 and total_stats['wins'] is not None:
        Win Percentage: <small>${round(float(total_stats['wins'])/total_stats['games'] * 100, 2)}% (${total_stats['wins']} wins, ${total_stats['games'] - total_stats['wins']} losses) </small><br />
@@ -259,7 +259,7 @@ Player Information
 </div>
 
 <div class="row">
-  <div class="span11">
+  <div class="span12">
     <p>
        % if total_stats['games_breakdown'].has_key('duel'):
        Duel Stats: <small>
index 7491902a4d9fdd255a4deecd2c0a8b9c300a2172..6185598e32ec556d22597a39e0507f6ff0e9efcf 100644 (file)
@@ -141,7 +141,7 @@ def _get_total_stats(player_id):
             filter(PlayerGameStat.player_id == player_id).\
             filter(Game.winner == PlayerGameStat.team or PlayerGameStat.rank == 1).\
             one()
-    
+
     (total_stats['duel_wins'],) = DBSession.query(
             func.count("*")).\
             filter(Game.game_id == PlayerGameStat.game_id).\
@@ -162,7 +162,7 @@ def _get_total_stats(player_id):
     (total_stats['dm_wins'],) = DBSession.query(
             func.count("*")).\
             filter(Game.game_id == PlayerGameStat.game_id).\
-            filter(Game.game_type_cd == "dm" or Game.game_type_cd == "tdm").\
+            filter(Game.game_type_cd == "dm").\
             filter(PlayerGameStat.player_id == player_id).\
             filter(PlayerGameStat.rank == 1).\
             one()
@@ -172,10 +172,27 @@ def _get_total_stats(player_id):
             func.sum(PlayerGameStat.deaths),
             func.sum(PlayerGameStat.suicides)).\
             filter(Game.game_id == PlayerGameStat.game_id).\
-            filter(Game.game_type_cd == "dm" or Game.game_type_cd == "tdm").\
+            filter(Game.game_type_cd == "dm").\
             filter(PlayerGameStat.player_id == player_id).\
             one()
 
+    (total_stats['tdm_kills'], total_stats['tdm_deaths'], total_stats['tdm_suicides'],) = DBSession.query(
+            func.sum(PlayerGameStat.kills),
+            func.sum(PlayerGameStat.deaths),
+            func.sum(PlayerGameStat.suicides)).\
+            filter(Game.game_id == PlayerGameStat.game_id).\
+            filter(Game.game_type_cd == "tdm").\
+            filter(PlayerGameStat.player_id == player_id).\
+            one()
+
+    (total_stats['tdm_wins'],) = DBSession.query(
+            func.count("*")).\
+            filter(Game.game_id == PlayerGameStat.game_id).\
+            filter(Game.game_type_cd == "tdm").\
+            filter(PlayerGameStat.player_id == player_id).\
+            filter(PlayerGameStat.rank == 1).\
+            one()
+
     (total_stats['ctf_wins'],) = DBSession.query(
             func.count("*")).\
             filter(Game.game_id == PlayerGameStat.game_id).\
@@ -221,7 +238,7 @@ def _get_fav_map(player_id):
             filter(PlayerGameStat.create_dt > back_then).\
             group_by(Map.name, Map.map_id).\
             order_by(func.count().desc()).\
-            all()
+            limit(5).all()
 
     fav_map = []
     for map_e in raw_fav_map:
@@ -246,13 +263,13 @@ def _get_fav_weapon(player_id):
     back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90)
 
     raw_fav_weapon = DBSession.query(Weapon.descr, Weapon.weapon_cd).\
-            filter(Game.game_id == PlayerGameStat.game_id).\
+            filter(Game.game_id == PlayerWeaponStat.game_id).\
+            filter(PlayerWeaponStat.player_id == player_id).\
             filter(PlayerWeaponStat.weapon_cd == Weapon.weapon_cd).\
-            filter(PlayerGameStat.player_id == player_id).\
-            filter(PlayerGameStat.create_dt > back_then).\
+            filter(PlayerWeaponStat.create_dt > back_then).\
             group_by(Weapon.descr, Weapon.weapon_cd).\
             order_by(func.count().desc()).\
-            all()
+            limit(5).all()
 
     fav_weapon = []
     for wpn_e in raw_fav_weapon:
@@ -283,7 +300,7 @@ def _get_fav_server(player_id):
             filter(PlayerGameStat.create_dt > back_then).\
             group_by(Server.name, Server.server_id).\
             order_by(func.count().desc()).\
-            all()
+            limit(5).all()
 
     fav_server = []
     for srv_e in raw_fav_server: