From b5bc55d40ea6aeed44d8d2c9f44937dff4fa3687 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Fri, 19 Apr 2013 19:34:12 -0400 Subject: [PATCH] Replace the game_index view w/ game_finder. The game_index view was cluttered, ugly, slow, and not used much. This changeset makes the page similar to the "recent games" lists throughout the app, but with a game type filter on it. This should be a more useable alternative than showing a bunch of scoreboards. --- xonstat/__init__.py | 12 +++++----- xonstat/templates/game_finder.mako | 35 ++++++++++++++++++++++++++++-- xonstat/templates/main_index.mako | 2 +- xonstat/views/game.py | 18 +++++++++++++-- xonstat/views/helpers.py | 19 +++++++++++++--- xonstat/views/player.py | 3 ++- 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 08946ad..bbd08bf 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -74,10 +74,10 @@ def main(global_config, **settings): config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp") # GAME ROUTES - config.add_route("game_index", "/games") - config.add_route("game_index_json", "/games.json") - config.add_view(game_index, route_name="game_index", renderer="game_index.mako") - config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp") + # config.add_route("game_index", "/games") + # config.add_route("game_index_json", "/games.json") + # config.add_view(game_index, route_name="game_index", renderer="game_index.mako") + # config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp") config.add_route("game_info", "/game/{id:\d+}") config.add_route("game_info_json", "/game/{id:\d+}.json") @@ -89,8 +89,8 @@ def main(global_config, **settings): config.add_view(rank_index, route_name="rank_index", renderer="rank_index.mako") config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp") - config.add_route("game_finder", "/gamefinder") - config.add_view(game_finder, route_name="game_finder", renderer="game_finder.mako") + config.add_route("game_index", "/games") + config.add_view(game_finder, route_name="game_index", renderer="game_finder.mako") # SERVER ROUTES config.add_route("server_index", "/servers") diff --git a/xonstat/templates/game_finder.mako b/xonstat/templates/game_finder.mako index cff4876..fc96277 100644 --- a/xonstat/templates/game_finder.mako +++ b/xonstat/templates/game_finder.mako @@ -11,10 +11,41 @@ ${nav.nav('games')} +<%block name="title"> +Game Index + + % if len(recent_games) > 0: + +##### ROW OF GAME TYPE ICONS ##### +
+
+ +
+
+
+ +##### RECENT GAMES TABLE #####
-

Recent Games

@@ -48,5 +79,5 @@ ${nav.nav('games')} -${navlinks("game_finder", recent_games.page, recent_games.last_page, search_query=query)} +${navlinks("game_index", recent_games.page, recent_games.last_page, search_query=query)} % endif diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako index b27efe4..1814b2f 100644 --- a/xonstat/templates/main_index.mako +++ b/xonstat/templates/main_index.mako @@ -199,7 +199,7 @@ Leaderboard % endfor
-

More...

+

More...

% endif diff --git a/xonstat/views/game.py b/xonstat/views/game.py index d18da8f..f1ba461 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -12,6 +12,7 @@ from xonstat.views.helpers import RecentGame, recent_games_q log = logging.getLogger(__name__) +# DEPRECATED def _game_index_data(request): game_type_cd = None game_type_descr = None @@ -216,7 +217,9 @@ def game_finder_data(request): query = {} server_id, map_id, player_id = None, None, None - range_start, range_end = None, None + range_start, range_end, game_type_cd = None, None, None + game_type_descr = None + # these become WHERE clauses when present if request.params.has_key('server_id'): server_id = request.params['server_id'] @@ -238,8 +241,18 @@ def game_finder_data(request): range_end = request.params['range_end'] query['range_end'] = range_end + if request.params.has_key('type'): + game_type_cd = request.params['type'] + query['type'] = game_type_cd + try: + game_type_descr = DBSession.query(GameType.descr).\ + filter(GameType.game_type_cd == game_type_cd).\ + one()[0] + except Exception as e: + game_type_cd = None + rgs_q = recent_games_q(server_id=server_id, map_id=map_id, - player_id=player_id) + player_id=player_id, game_type_cd=game_type_cd) recent_games = Page(rgs_q, current_page, url=page_url) @@ -248,6 +261,7 @@ def game_finder_data(request): return { 'recent_games':recent_games, 'query':query, + 'game_type_cd':game_type_cd, } def game_finder(request): diff --git a/xonstat/views/helpers.py b/xonstat/views/helpers.py index 2f2db70..a3b3f53 100644 --- a/xonstat/views/helpers.py +++ b/xonstat/views/helpers.py @@ -1,6 +1,7 @@ import logging import sqlalchemy.sql.expression as expr from datetime import datetime +from sqlalchemy.orm import aliased from xonstat.models import * from xonstat.util import * @@ -75,7 +76,8 @@ class RecentGame(object): return "" % (self.game_id, self.game_type_cd, self.server_name, self.map_name) -def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=None, cutoff=None): +def recent_games_q(server_id=None, map_id=None, player_id=None, + game_type_cd=None, cutoff=None, force_player_id=False): ''' Returns a SQLA query of recent game data. Parameters filter the results returned if they are provided. If not, it is @@ -85,6 +87,8 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non look when querying. Only games that happened on or after the cutoff (which is a datetime object) will be returned. ''' + pgstat_alias = aliased(PlayerGameStat, name='pgstat_alias') + recent_games_q = DBSession.query(Game.game_id, GameType.game_type_cd, Game.winner, Game.start_dt, GameType.descr.label('game_type_descr'), Server.server_id, Server.name.label('server_name'), Map.map_id, @@ -106,9 +110,18 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non recent_games_q = recent_games_q.\ filter(Map.map_id==map_id) + # Note: force_player_id makes the pgstat row returned be from the + # specified player_id. Otherwise it will just look for a game + # *having* that player_id, but returning the #1 player's pgstat row if player_id is not None: - recent_games_q = recent_games_q.\ - filter(PlayerGameStat.player_id==player_id) + if force_player_id: + recent_games_q = recent_games_q.\ + filter(PlayerGameStat.player_id==player_id) + else: + recent_games_q = recent_games_q.\ + filter(PlayerGameStat.rank==1).\ + filter(Game.game_id==pgstat_alias.game_id).\ + filter(pgstat_alias.player_id==player_id) else: recent_games_q = recent_games_q.\ filter(PlayerGameStat.rank==1) diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 94fe8cb..370bace 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -624,7 +624,8 @@ def player_game_index_data(request): filter(Player.active_ind == True).\ one() - rgs_q = recent_games_q(player_id=player.player_id, game_type_cd=game_type_cd) + rgs_q = recent_games_q(player_id=player.player_id, + force_player_id=True, game_type_cd=game_type_cd) games = Page(rgs_q, current_page, items_per_page=10, url=page_url) -- 2.39.2