From 1bb4bed635c0389f1aeaa2a326448e66de565936 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sun, 4 Nov 2012 08:17:22 -0500 Subject: [PATCH] Add overall best flag capture times to the map info page. 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 | 33 +++++++++++++++++++++++++++++++++ xonstat/views/map.py | 19 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/xonstat/templates/map_info.mako b/xonstat/templates/map_info.mako index a16e920..b663438 100644 --- a/xonstat/templates/map_info.mako +++ b/xonstat/templates/map_info.mako @@ -107,6 +107,39 @@ ${parent.title()} +% if len(captimes) > 0: +
+
+

Best Flag Capture Times

+ + + + + + + + + % for c in captimes: + + + + + % endfor + +
NickCaptime
+ % if c.player_id > 2: + + ${c.nick_html_colors|n} + + % else: + ${c.nick_html_colors|n} + % endif + ${round(float(c.fastest_cap.seconds) + (c.fastest_cap.microseconds/1000000.0), 2)}
+
+
+% endif +
diff --git a/xonstat/views/map.py b/xonstat/views/map.py index a74a220..5fbc772 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -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, } -- 2.39.2