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.
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")
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")
<link href="/static/css/sprites.css" rel="stylesheet">
</%block>
+<%block name="title">
+Game Index
+</%block>
+
% if len(recent_games) > 0:
+
+##### ROW OF GAME TYPE ICONS #####
+<div class="row">
+ <div class="span12 tabbable">
+ <ul class="nav nav-tabs">
+ % for gt in ('overall','duel','ctf','dm','tdm','ca','kh','ft','lms','as','dom','nb','cts','rc'):
+ <li
+ % if game_type_cd == gt or (game_type_cd is None and gt == 'overall'):
+ class="active"
+ % endif
+ >
+
+ % if gt == 'overall':
+ <a href="${request.route_url("game_index")}" alt="${gt}" title="" data-toggle="none">
+ % else:
+ <a href="${request.route_url("game_index", _query={'type':gt})}" alt="${gt}" title="" data-toggle="none">
+ % endif
+ <span class="sprite sprite-${gt}"> </span><br />
+ ${gt} <br />
+ </a>
+ </li>
+ % endfor
+ </ul>
+ <br />
+ </div>
+</div>
+
+##### RECENT GAMES TABLE #####
<div class="row">
<div class="span12">
- <h3>Recent Games</h3>
<table class="table table-hover table-condensed">
<thead>
<tr>
</div> <!-- /row -->
<!-- navigation links -->
-${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
% endfor
</tbody>
</table>
- <p><a href="${request.route_url('game_finder')}">More...</a></p>
+ <p><a href="${request.route_url('game_index')}">More...</a></p>
</div> <!-- /span12 -->
</div> <!-- /row -->
% endif
log = logging.getLogger(__name__)
+# DEPRECATED
def _game_index_data(request):
game_type_cd = None
game_type_descr = None
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']
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)
return {
'recent_games':recent_games,
'query':query,
+ 'game_type_cd':game_type_cd,
}
def game_finder(request):
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 *
return "<RecentGame(id=%s, gametype=%s, server=%s, map=%s)>" % (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
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,
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)
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)