</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">
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__)
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()
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,
'top_scorers':top_scorers,
'top_players':top_players,
'top_servers':top_servers,
+ 'captimes':captimes,
}