From ec61e1f548359d7b7e065b361ab95a53b9481ec4 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Fri, 29 Mar 2013 16:02:56 -0400 Subject: [PATCH] Clean up server view, show more on server_index page. --- xonstat/templates/server_index.mako | 2 ++ xonstat/views/server.py | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/xonstat/templates/server_index.mako b/xonstat/templates/server_index.mako index fc3cb92..3217bed 100644 --- a/xonstat/templates/server_index.mako +++ b/xonstat/templates/server_index.mako @@ -23,11 +23,13 @@ Server Index + % for server in servers: + diff --git a/xonstat/views/server.py b/xonstat/views/server.py index d25e8e8..e685f96 100644 --- a/xonstat/views/server.py +++ b/xonstat/views/server.py @@ -1,10 +1,8 @@ import logging import sqlalchemy.sql.functions as func import sqlalchemy.sql.expression as expr -import time from datetime import datetime, timedelta -from sqlalchemy import desc -from webhelpers.paginate import Page, PageURL +from webhelpers.paginate import Page from xonstat.models import * from xonstat.util import page_url, html_colors from xonstat.views.helpers import RecentGame, recent_games_q @@ -21,9 +19,9 @@ def _server_index_data(request): server_q = DBSession.query(Server).\ order_by(Server.server_id.desc()) - servers = Page(server_q, current_page, items_per_page=10, url=page_url) + servers = Page(server_q, current_page, items_per_page=25, url=page_url) + - except Exception as e: servers = None @@ -47,7 +45,7 @@ def server_index_json(request): def _server_info_data(request): server_id = request.matchdict['id'] - try: + try: leaderboard_lifetime = int( request.registry.settings['xonstat.leaderboard_lifetime']) except: @@ -60,24 +58,24 @@ def _server_info_data(request): server = DBSession.query(Server).filter_by(server_id=server_id).one() # top maps by total times played - top_maps = DBSession.query(Game.map_id, Map.name, + top_maps = DBSession.query(Game.map_id, Map.name, func.count()).\ filter(Map.map_id==Game.map_id).\ filter(Game.server_id==server.server_id).\ - filter(Game.create_dt > + filter(Game.create_dt > (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.count())).\ group_by(Game.map_id).\ group_by(Map.name).all()[0:leaderboard_count] # top players by score - top_scorers = DBSession.query(Player.player_id, Player.nick, + top_scorers = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.score)).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(Game.game_id == PlayerGameStat.game_id).\ filter(Game.server_id == server.server_id).\ filter(Player.player_id > 2).\ - filter(PlayerGameStat.create_dt > + filter(PlayerGameStat.create_dt > (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.sum(PlayerGameStat.score))).\ group_by(Player.nick).\ @@ -87,13 +85,13 @@ def _server_info_data(request): for (player_id, nick, score) in top_scorers] # top players by playing time - top_players = DBSession.query(Player.player_id, Player.nick, + top_players = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.alivetime)).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(Game.game_id == PlayerGameStat.game_id).\ filter(Game.server_id == server.server_id).\ filter(Player.player_id > 2).\ - filter(PlayerGameStat.create_dt > + filter(PlayerGameStat.create_dt > (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\ group_by(Player.nick).\ -- 2.39.2
ID Name Added
${server.server_id} ${server.name} ${server.fuzzy_date()}