]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add overall best flag capture times to the map info page.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 4 Nov 2012 13:17:22 +0000 (08:17 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 4 Nov 2012 13:17:22 +0000 (08:17 -0500)
Only the top ten fastest capture times are shown. Players in this
list must be tracked. No bots are tracked, obviously :D.

xonstat/templates/map_info.mako
xonstat/views/map.py

index a16e92087385e8192371d9e18ab1e9d6f009ff0a..b6634386385cbe4e76771db1f92e56e8a17647b3 100644 (file)
@@ -107,6 +107,39 @@ ${parent.title()}
 </div>
 </div> <!-- /row -->
 
+% 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 c in captimes:
+        <tr>
+          <td>
+          % if c.player_id > 2:
+            <a href="${request.route_url("player_info", id=c.player_id)}"
+             title="Go to the info page for this player">
+            <span class="nick">${c.nick_html_colors|n}</span>
+            </a>
+          % else:
+            <span class="nick">${c.nick_html_colors|n}</span>
+          % endif
+          </td>
+          <td>${round(float(c.fastest_cap.seconds) + (c.fastest_cap.microseconds/1000000.0), 2)}</td>
+        </tr>
+      % endfor
+      </tbody>
+    </table>
+  </div>
+</div>
+% endif
+
 
 <div class="row">
   <div class="span12">
index a74a220644f6b7b39c1a4b50722b531e7536b835..5fbc7727578780308a3a57beb8ce60ca120591ee 100644 (file)
@@ -1,12 +1,13 @@
 import logging
 import sqlalchemy.sql.functions as func
 import sqlalchemy.sql.expression as expr
+from collections import namedtuple
 from datetime import datetime, timedelta
 from pyramid.response import Response
 from sqlalchemy import desc
 from webhelpers.paginate import Page, PageURL
 from xonstat.models import *
-from xonstat.util import page_url
+from xonstat.util import page_url, html_colors
 
 log = logging.getLogger(__name__)
 
@@ -58,6 +59,10 @@ def _map_info_data(request):
     leaderboard_count = 10
     recent_games_count = 20
 
+    # captime tuples
+    Captime = namedtuple('Captime', ['player_id', 'nick_html_colors',
+        'fastest_cap', 'game_id'])
+
     try:
         gmap = DBSession.query(Map).filter_by(map_id=map_id).one()
 
@@ -113,6 +118,17 @@ def _map_info_data(request):
                 group_by(Server.name).\
                 group_by(Server.server_id).all()[0:leaderboard_count]
 
+        # top captimes
+        captimes_raw = DBSession.query(Player.player_id, Player.nick,
+            PlayerCaptime.fastest_cap, PlayerCaptime.game_id).\
+                filter(PlayerCaptime.map_id == map_id).\
+                filter(Player.player_id == PlayerCaptime.player_id).\
+                order_by(PlayerCaptime.fastest_cap).\
+                limit(10).all()
+
+        captimes = [Captime(c.player_id, html_colors(c.nick),
+            c.fastest_cap, c.game_id) for c in captimes_raw]
+
     except Exception as e:
         gmap = None
     return {'gmap':gmap,
@@ -120,6 +136,7 @@ def _map_info_data(request):
             'top_scorers':top_scorers,
             'top_players':top_players,
             'top_servers':top_servers,
+            'captimes':captimes,
             }