From 69b8e5b4bf31107b74c5751e131ebdbb5416facb Mon Sep 17 00:00:00 2001
From: Ant Zucaro <azucaro@gmail.com>
Date: Thu, 1 Nov 2012 21:59:21 -0400
Subject: [PATCH] Show the best flag capture times on the game info page.

The best flag capture time for each player is shown in the game
info page now. This only happens for CTF. The format shown is
seconds.milliseconds, with up to two decimal places shown.
---
 xonstat/templates/game_info.mako | 34 ++++++++++++++++++++++++++++++++
 xonstat/views/game.py            | 15 ++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/xonstat/templates/game_info.mako b/xonstat/templates/game_info.mako
index 141f3a9..0e3a383 100644
--- a/xonstat/templates/game_info.mako
+++ b/xonstat/templates/game_info.mako
@@ -46,6 +46,40 @@ Game Information
   </div>
 </div>
 
+% if len(captimes) > 0:
+<div class="row">
+  <div class="span6">
+    <h3>Best Flag Capture Times</h3>
+    <table class="table table-bordered table-condensed">
+      <thead>
+        <tr>
+           <th>Nick</th>
+           <th>Captime</th>
+        </tr>
+      </thead>
+      <tbody>
+      % for pgs in captimes:
+        <tr>
+          <td>
+          % if pgs.player_id > 2:
+            <a href="${request.route_url("player_info", id=pgs.player_id)}"
+             title="Go to the info page for this player">
+            <span class="nick">${pgs.nick_html_colors()|n}</span>
+            </a>
+          % else:
+            <span class="nick">${pgs.nick_html_colors()|n}</span>
+          % endif
+          </td>
+          <td>${round(float(pgs.fastest_cap.seconds) + (pgs.fastest_cap.microseconds/1000000.0), 2)}</td>
+        </tr>
+      % endfor
+      </tbody>
+    </table>
+  </div>
+</div>
+% endif
+
+
 % if len(pgstats) > 0:
 <div class="row">
   <div class="span12">
diff --git a/xonstat/views/game.py b/xonstat/views/game.py
index 04774fe..2e088b8 100644
--- a/xonstat/views/game.py
+++ b/xonstat/views/game.py
@@ -69,12 +69,13 @@ def _game_info_data(request):
                 order_by(PlayerGameStat.score).\
                 all()
 
-        # mako is an absolute bastard when dealing with decimals, so...
-        for pgstat in pgstats:
-            try:
-                pgstat.elo_delta = "{0:+4.2f}".format(float(pgstat.elo_delta))
-            except:
-                pgstat.elo_delta = "0.00"
+        captimes = []
+        if game.game_type_cd == 'ctf':
+            for pgstat in pgstats:
+                if pgstat.fastest_cap is not None:
+                    captimes.append(pgstat)
+
+            captimes = sorted(captimes, key=lambda x:x.fastest_cap)
 
         pwstats = {}
         for (pwstat, pgstat, weapon) in DBSession.query(PlayerWeaponStat, PlayerGameStat, Weapon).\
@@ -102,6 +103,7 @@ def _game_info_data(request):
         map = None
         pgstats = None
         pwstats = None
+        captimes = None
         raise inst
 
     return {'game':game,
@@ -109,6 +111,7 @@ def _game_info_data(request):
             'map':map,
             'pgstats':pgstats,
             'pwstats':pwstats,
+            'captimes':captimes,
             }
 
 
-- 
2.39.5