]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Finalized "Game Breakdown" section (fixed implementation; added more data; improved...
authorJan D. Behrens <zykure@web.de>
Wed, 8 Aug 2012 10:44:34 +0000 (12:44 +0200)
committerJan D. Behrens <zykure@web.de>
Wed, 8 Aug 2012 10:54:47 +0000 (12:54 +0200)
xonstat/static/images/icons/48x48/overall.png [new file with mode: 0644]
xonstat/templates/base.mako
xonstat/templates/player_info.mako
xonstat/views/player.py

diff --git a/xonstat/static/images/icons/48x48/overall.png b/xonstat/static/images/icons/48x48/overall.png
new file mode 100644 (file)
index 0000000..5a2b5e9
Binary files /dev/null and b/xonstat/static/images/icons/48x48/overall.png differ
index 95065f9e53cfc08d902cfff9819d5723c75c98e7..53526091cafe7ac0c7ef3494e5a8e3189d66a217 100644 (file)
@@ -23,6 +23,8 @@
     <link href="/static/css/style.css" rel="stylesheet">
     <link type="images/vnd.microsoft.icon" rel="shortcut icon" href="/static/favicon.ico">
     </%block>
+    
+    <script src="/static/js/jquery-1.7.1.min.js"></script>
   </head>
 
   <body>
index b0607771fcf6bd628ccd9d03716aa09df73d2ef0..291dcd02d505bb309340ba9fcb25209455f76b29 100644 (file)
@@ -8,10 +8,13 @@ ${nav.nav('players')}
 
 <%block name="js">
     % if player is not None:
-      <script src="/static/js/jquery-1.7.1.min.js"></script>
-      <script src="/static/js/bootstrap-tabs.min.js"></script>
       <script src="/static/js/jquery.flot.min.js"></script>
+      <script src="/static/js/bootstrap-tabs.js"></script>
       <script type="text/javascript">
+      jQuery(document).ready(function ($) {
+          $(".tabs").tabs();
+      });      
+
       $(function () {
           // plot the accuracy graph
           function plot_acc_graph(data) {
@@ -163,6 +166,7 @@ ${nav.nav('players')}
           });
       })
       </script>
+      <script src="/static/js/bootstrap-tabs.min.js"></script>
     % endif
 </%block>
 
@@ -392,16 +396,18 @@ Player Information
 <div class="row">
   <div class="span8 tabbable">
     <h3>Game Breakdown</h3>
-    <ul class="nav nav-pills tabs" data-tabs="tabs">
+    <ul class="tabs nav nav-pills" data-tabs="tabs">
     <% gametypes = ['Overall', 'Duel', 'DM', 'TDM', 'CTF'] %>
     % for gtc in gametypes:
-      % if gtc.lower() == 'overall':
+      % if gtc.lower() == 'overall' or total_stats['games_breakdown'].has_key(gtc.lower()):
+        % if gtc.lower() == 'overall':
       <li class="active">
-      % elif total_stats['games_breakdown'].has_key(gtc.lower()):
+        % else:
       <li>
-      % endif
-        <a href="#breakdown-${gtc.lower()}">${gtc}</a>
+        % endif
+        <a href="#breakdown-${gtc.lower()}" data-toggle="tabs">${gtc}</a>
       </li>
+      % endif
     % endfor
     </ul>
     <div class="tab-content">
@@ -409,6 +415,7 @@ Player Information
       <% gtc_key = gtc.lower() %>
       % if gtc_key == "overall":
         <% total     = total_stats['games'] %>
+        <% alivetime = total_stats['alivetime'] %>
         <% wins      = total_stats['wins'] %>
         <% losses    = total - wins %>
         <% kills     = total_stats['kills'] %>
@@ -416,6 +423,7 @@ Player Information
         <% suicides  = total_stats['suicides'] %>
       % elif total_stats['games_breakdown'].has_key(gtc_key):
         <% total     = total_stats['games_breakdown'][gtc_key] %>
+        <% alivetime = total_stats['games_alivetime'][gtc_key] %>
         <% wins      = total_stats[gtc_key+'_wins'] %>
         <% losses    = total - wins %>
         % if gtc_key == "ctf":
@@ -430,41 +438,104 @@ Player Information
           <% suicides  = total_stats[gtc_key+'_suicides'] %>
         % endif
       % endif
-      % if gtc_key == 'overall':
-      <div class="tab-pane active" id="breakdown-${gtc_key}">
-      % else:
+      % if gtc_key == 'overall' or total_stats['games_breakdown'].has_key(gtc_key):
+        % if gtc_key == 'overall':
       <div class="tab-pane active" id="breakdown-${gtc_key}">
-      % endif
+        % else:
+      <div class="tab-pane" id="breakdown-${gtc_key}">
+        % endif
+        <div style="margin:15px;float:left;"><img title="${gtc}" src="/static/images/icons/48x48/${gtc_key}.png" alt="${gtc}" /></div>
         <table class="table table-bordered table-condensed">
           <thead>
           </thead>
           <tbody>
             <tr>
-              <td width="20%">Win Percentage:</td>
-              <td width="15%">${round(float(wins)/total * 100, 2)}%</td>
-              <td width="65%">${wins} wins, ${losses} losses</td>
+              <td width="30%"><b>Games Played:</b></td>
+              <td width="30%">${total}</td>
+              <td width="40%"></td>
+            </tr>
+            <tr>
+              <td><b>Playing Time:</b></td>
+              <td>${alivetime} hours</td>
+              <td></td>
+            </tr>
+            <tr>
+              <td><b>Win Percentage:</b></td>
+              <td>${round(float(wins)/total * 100, 2)}%</td>
+              <td>${wins} wins, ${losses} losses</td>
             </tr>
             % if gtc_key == 'ctf':
             <tr>
-              <td>Cap Ratio:</td>
+              <td><b>Caps:</b></td>
+              <td>${round(float(caps)/total, 2)} per game</td>
+              <td>${caps} total</td>
+            </tr>
+            <tr>
+              <td><b>Pickups:</b></td>
+              <td>${round(float(pickups)/total, 2)} per game</td>
+              <td>${pickups} total</td>
+            </tr>
+            <tr>
+              <td><b>Drops:</b></td>
+              <td>${round(float(drops)/total, 2)} per game</td>
+              <td>${drops} total</td>
+            </tr>
+            <tr>
+              <td><b>Returns:</b></td>
+              <td>${round(float(returns)/total, 2)} per game</td>
+              <td>${returns} total</td>
+            </tr>
+            <tr>
+              <td><b>FC Kills:</b></td>
+              <td>${round(float(fckills)/total, 2)} per game</td>
+              <td>${fckills} total</td>
+            </tr>
+            <tr>
+              <td><b>Cap Ratio:</b></td>
               <td>${round(float(caps)/pickups, 3)}</td>
-              <td>${caps} caps, ${pickups} pickups, ${drops} drops, ${returns} returns, ${fckills} fckills</td>
+              <td></td>
             </tr>
-            <!--<tr>
-              <td>Drop Ratio:</td>
+            <tr>
+              <td><b>Drop Ratio:</b></td>
               <td>${round(float(drops)/pickups, 3)}</td>
-              <td>${caps} caps, ${pickups} pickups, ${drops} drops, ${returns} returns, ${fckills} fckills</td>
-            </tr>-->
+              <td></td>
+            </tr>
+            <tr>
+              <td><b>Return Ratio:</b></td>
+              <td>${round(float(returns)/fckills, 3)}</td>
+              <td></td>
+            </tr>
             % else:
             <tr>
-              <td>Kill Ratio:</td>
+              <td><b>Kills:</b></td>
+              <td>${round(float(kills)/total, 2)} per game</td>
+              <td>${kills} total</td>
+            </tr>
+            <tr>
+              <td><b>Deaths:</b></td>
+              <td>${round(float(deaths)/total, 2)} per game</td>
+              <td>${deaths} total</td>
+            </tr>
+            <tr>
+              <td><b>Suicides:</b></td>
+              <td>${round(float(suicides)/total, 2)} per game</td>
+              <td>${suicides} total</td>
+            </tr>
+            <tr>
+              <td><b>Kill Ratio:</b></td>
               <td>${round(float(kills)/deaths, 3)}</td>
-              <td>${kills} kills, ${deaths} deaths, ${suicides} suicides</td>
+              <td></td>
+            </tr>
+            <tr>
+              <td><b>Suicide Ratio:</b></td>
+              <td>${round(float(suicides)/deaths, 3)}</td>
+              <td></td>
             </tr>
             % endif
           </tbody>
         </table>
       </div>
+      % endif
     % endfor
     </div>
   </div>
index 6185598e32ec556d22597a39e0507f6ff0e9efcf..0bc24b90e42448dea945f10b4625eff644f2c996 100644 (file)
@@ -83,6 +83,7 @@ def _get_total_stats(player_id):
 
     games = how many games a player has played
     games_breakdown = how many games of given type a player has played (dictionary)
+    games_alivetime = how many time a player has spent in a give game type (dictionary)
     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
@@ -100,7 +101,7 @@ def _get_total_stats(player_id):
     total_stats = {}
 
     games_played = DBSession.query(
-            Game.game_type_cd, func.count()).\
+            Game.game_type_cd, func.count(), func.sum(PlayerGameStat.alivetime)).\
             filter(Game.game_id == PlayerGameStat.game_id).\
             filter(PlayerGameStat.player_id == player_id).\
             group_by(Game.game_type_cd).\
@@ -109,9 +110,11 @@ def _get_total_stats(player_id):
 
     total_stats['games'] = 0
     total_stats['games_breakdown'] = {}  # this is a dictionary inside a dictionary .. dictception?
-    for (game_type_cd, games) in games_played:
+    total_stats['games_alivetime'] = {}
+    for (game_type_cd, games, alivetime) in games_played:
         total_stats['games'] += games
         total_stats['games_breakdown'][game_type_cd] = games
+        total_stats['games_alivetime'][game_type_cd] = alivetime
 
      # more fields can be added here, e.g. 'collects' for kh games
     (total_stats['kills'], total_stats['deaths'], total_stats['suicides'],