]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add a tabular accuracy view to the player info page.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 24 May 2011 18:24:00 +0000 (14:24 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 24 May 2011 18:24:00 +0000 (14:24 -0400)
xonstat/templates/player_info.mako
xonstat/views.py

index 561da175b40ab27a36b437fd46f513984b253937..df133d4f849a5d798cf00692ab008e9273baee55 100755 (executable)
@@ -29,3 +29,43 @@ ${parent.title()}
 </ul>
 <a href="${request.route_url("player_game_index", player_id=player.player_id, page=1)}" title="Game index for ${player.nick}">More games</a> played by ${player.nick_html_colors()}...
 % endif
+
+
+% if weapon_stats:
+<h2>Accuracy</h2>
+<table border="1" cellpadding="3">
+<tr>
+    <td></td>
+    <td>Weapon</td>
+    <td>Hit</td>
+    <td>Fired</td>
+    <td>Hit %</td>
+    <td>Actual Damage</td>
+    <td>Potential Damage</td>
+    <td>Damage %</td>
+</tr>
+% for weapon_stat in weapon_stats:
+<%
+if weapon_stat[2] > 0: 
+    damage_pct = round(float(weapon_stat[1])/weapon_stat[2]*100, 2)
+else:
+    damage_pct = 0
+if weapon_stat[4] > 0: 
+    hit_pct = round(float(weapon_stat[3])/weapon_stat[4]*100, 2)
+else:
+    hit_pct = 0
+%>
+<tr>
+    <td>[IMAGE]</td>
+    <td>${weapon_stat[0]}</td>
+    <td>${weapon_stat[3]}</td>
+    <td>${weapon_stat[4]}</td>
+    <td>${hit_pct}%</td>
+    <td>${weapon_stat[1]}</td>
+    <td>${weapon_stat[2]}</td>
+    <td>${damage_pct}%</td>
+</tr>
+% endfor
+</table>
+
+% endif
index 36afef452272bf1dfeabb19c8a8b81e41f246b09..77ed15049f7da00ea6a15f2823f0abf90d2ce879 100755 (executable)
@@ -38,6 +38,22 @@ def player_info(request):
     player_id = request.matchdict['id']
     try:
         player = DBSession.query(Player).filter_by(player_id=player_id).one()
+
+        weapon_stats = DBSession.query("descr", "actual_total", 
+                "max_total", "hit_total", "fired_total", "frags_total").\
+                from_statement(
+                    "select cw.descr, sum(actual) actual_total, "
+                    "sum(max) max_total, sum(hit) hit_total, "
+                    "sum(fired) fired_total, sum(frags) frags_total "
+                    "from xonstat.player_weapon_stats ws, xonstat.cd_weapon cw "
+                    "where ws.weapon_cd = cw.weapon_cd "
+                    "and player_id = :player_id "
+                    "group by descr "
+                    "order by descr"
+                ).params(player_id=player_id).all()
+
+        log.debug(weapon_stats)
+
         recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\
                 filter(PlayerGameStat.player_id == player_id).\
                 filter(PlayerGameStat.game_id == Game.game_id).\
@@ -47,9 +63,11 @@ def player_info(request):
 
     except Exception as e:
         player = None
+        weapon_stats = None
         recent_games = None
     return {'player':player, 
-            'recent_games':recent_games}
+            'recent_games':recent_games,
+            'weapon_stats':weapon_stats}
 
 
 def player_game_index(request):