config.add_route("player_game_index_json", "/player/{player_id:\d+}/games.json")
config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp")
- config.add_route("player_hashkey_info_text", "/player/me")
- config.add_view(player_hashkey_info_text, route_name="player_hashkey_info_text", renderer="player_hashkey_info_text.mako")
-
config.add_route("player_info", "/player/{id:\d+}")
config.add_view(player_info, route_name="player_info", renderer="player_info.mako")
- config.add_route("player_hashkey_info_json", "/player/me.json")
- config.add_view(player_hashkey_info_json, route_name="player_hashkey_info_json", renderer="jsonp")
+ config.add_route("player_info_json", "/player/{id:\d+}.json")
+ config.add_view(player_info_json, route_name="player_info_json", renderer="jsonp")
config.add_route("player_hashkey_info_text", "/player/me")
config.add_view(player_hashkey_info_text, route_name="player_hashkey_info_text", renderer="player_hashkey_info_text.mako")
- config.add_route("player_info_json", "/player/{id:\d+}.json")
- config.add_view(player_info_json, route_name="player_info_json", renderer="jsonp")
+ config.add_route("player_hashkey_info_json", "/player/me.json")
+ config.add_view(player_hashkey_info_json, route_name="player_hashkey_info_json", renderer="jsonp")
config.add_route("player_elo_info_text", "/player/{hashkey}/elo.txt")
config.add_view(player_elo_info_text, route_name="player_elo_info_text", renderer="player_elo_info_text.mako")
config.add_route("player_index_json", "/players.json")
config.add_view(player_index_json, route_name="player_index_json", renderer="jsonp")
- config.add_route("player_captimes", "/player/{id:\d+}/captimes")
+ config.add_route("player_captimes", "/player/{player_id:\d+}/captimes")
config.add_view(player_captimes, route_name="player_captimes", renderer="player_captimes.mako")
- config.add_route("player_captimes_json", "/player/{id:\d+}/captimes.json")
+ config.add_route("player_captimes_json", "/player/{player_id:\d+}/captimes.json")
config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
config.add_route("player_weaponstats_data_json", "/player/{id:\d+}/weaponstats.json")
def __repr__(self):
return "<PlayerCaptime(pid=%s, map_id=%s)>" % (self.player_id, self.map_id)
+ def fuzzy_date(self):
+ return pretty_date(self.create_dt)
+
+ def epoch(self):
+ return timegm(self.create_dt.timetuple())
+
class SummaryStat(object):
def __repr__(self):
<%inherit file="base.mako"/>
<%namespace name="nav" file="nav.mako" />
+<%namespace file="navlinks.mako" import="navlinks" />
+
+<%block name="navigation">
+${nav.nav('maps')}
+</%block>
<%block name="title">
Map captimes
</%block>
+% if len(captimes) == 0:
+<h2>Sorry, no caps yet. Get playing!</h2>
+<p><a href="${map_url}">Back to map info page</a></p>
+% else:
<div class="row">
<div class="span12">
<h2>${map.name}</h2>
- <p><a href="${map_url}">Back to map info page</a></p>
+ <p><a href="${request.route_url('map_info', id=map.map_id)}">Back to map info page</a></p>
<h3>Fastest Flag Captures:</h3>
</tr>
</thead>
<tbody>
- % for ct in captimes:
+ % for ct in captimes.items:
<tr>
<td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
<td>${ct.fastest_cap.total_seconds()} seconds</td>
</div>
</div>
+<!-- navigation links -->
+${navlinks("map_captimes", captimes.page, captimes.last_page, id=map_id, search_query=request.GET)}
+% endif
<%inherit file="base.mako"/>
<%namespace name="nav" file="nav.mako" />
+<%namespace file="navlinks.mako" import="navlinks" />
+
+<%block name="navigation">
+${nav.nav('players')}
+</%block>
<%block name="title">
Player captimes
</tr>
</thead>
<tbody>
- % for ct in captimes:
+ % for ct in captimes.items:
<tr>
<td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
<td>${ct.fastest_cap.total_seconds()} seconds</td>
</div>
</div>
+<!-- navigation links -->
+${navlinks("player_captimes", captimes.page, captimes.last_page, player_id=player_id, search_query=request.GET)}
% endif
def map_captimes_data(request):
map_id = int(request.matchdict['id'])
-
- MapCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+
+ if request.params.has_key('page'):
+ current_page = request.params['page']
+ else:
+ current_page = 1
+
+ MapCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap',
+ 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
'player_id', 'player_nick', 'player_nick_stripped', 'player_nick_html',
'game_id', 'server_id', 'server_name'])
- dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id',
- 'server_id', 'server_name', 'player_nick').\
- from_statement(
- "SELECT ct.fastest_cap, "
- "ct.create_dt, "
- "ct.player_id, "
- "ct.game_id, "
- "g.server_id, "
- "s.name server_name, "
- "pgs.nick player_nick "
- "FROM player_map_captimes ct, "
- "games g, "
- "maps m, "
- "servers s, "
- "player_game_stats pgs "
- "WHERE ct.map_id = :map_id "
- "AND g.game_id = ct.game_id "
- "AND g.server_id = s.server_id "
- "AND m.map_id = ct.map_id "
- "AND pgs.player_id = ct.player_id "
- "AND pgs.game_id = ct.game_id "
- "ORDER BY ct.fastest_cap "
- "LIMIT 25"
- ).params(map_id=map_id).all()
-
mmap = DBSession.query(Map).filter_by(map_id=map_id).one()
- map_captimes = []
- for row in dbquery:
- map_captimes.append(MapCaptimes(
- fastest_cap=row.fastest_cap,
- create_dt=row.create_dt,
- create_dt_epoch=timegm(row.create_dt.timetuple()),
- create_dt_fuzzy=pretty_date(row.create_dt),
- player_id=row.player_id,
- player_nick=row.player_nick,
- player_nick_stripped=strip_colors(row.player_nick),
- player_nick_html=html_colors(row.player_nick),
- game_id=row.game_id,
- server_id=row.server_id,
- server_name=row.server_name,
- ))
+ #mct_q = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id',
+ # 'server_id', 'server_name', 'player_nick').\
+ # from_statement(
+ # "SELECT ct.fastest_cap, "
+ # "ct.create_dt, "
+ # "ct.player_id, "
+ # "ct.game_id, "
+ # "g.server_id, "
+ # "s.name server_name, "
+ # "pgs.nick player_nick "
+ # "FROM player_map_captimes ct, "
+ # "games g, "
+ # "maps m, "
+ # "servers s, "
+ # "player_game_stats pgs "
+ # "WHERE ct.map_id = :map_id "
+ # "AND g.game_id = ct.game_id "
+ # "AND g.server_id = s.server_id "
+ # "AND m.map_id = ct.map_id "
+ # "AND pgs.player_id = ct.player_id "
+ # "AND pgs.game_id = ct.game_id "
+ # "ORDER BY ct.fastest_cap "
+ # "LIMIT 25"
+ # ).params(map_id=map_id)
+
+ #try:
+ if True:
+ mct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
+ PlayerCaptime.player_id, PlayerCaptime.game_id,
+ Game.server_id, Server.name.label('server_name'),
+ PlayerGameStat.nick.label('player_nick')).\
+ filter(PlayerCaptime.map_id==map_id).\
+ filter(PlayerCaptime.game_id==Game.game_id).\
+ filter(PlayerCaptime.map_id==Map.map_id).\
+ filter(Game.server_id==Server.server_id).\
+ filter(PlayerCaptime.player_id==PlayerGameStat.player_id).\
+ filter(PlayerCaptime.game_id==PlayerGameStat.game_id).\
+ order_by(expr.asc(PlayerCaptime.fastest_cap))
+
+ map_captimes = Page(mct_q, current_page, items_per_page=20, url=page_url)
+
+ map_captimes.items = [MapCaptimes(
+ fastest_cap=row.fastest_cap,
+ create_dt=row.create_dt,
+ create_dt_epoch=timegm(row.create_dt.timetuple()),
+ create_dt_fuzzy=pretty_date(row.create_dt),
+ player_id=row.player_id,
+ player_nick=row.player_nick,
+ player_nick_stripped=strip_colors(row.player_nick),
+ player_nick_html=html_colors(row.player_nick),
+ game_id=row.game_id,
+ server_id=row.server_id,
+ server_name=row.server_name,
+ ) for row in map_captimes.items]
+
+ #except Exception as e:
+ else:
+ map = None
+ map_captimes = None
return {
- 'captimes':map_captimes,
'map_id':map_id,
- 'map_url':request.route_url('map_info', id=map_id),
'map':mmap,
+ 'captimes':map_captimes,
}
def map_captimes(request):
import pyramid.httpexceptions
import sqlalchemy as sa
import sqlalchemy.sql.functions as func
+import sqlalchemy.sql.expression as expr
from calendar import timegm
from collections import namedtuple
from webhelpers.paginate import Page
(idfp, status) = verify_request(request)
log.debug("d0_blind_id verification: idfp={0} status={1}\n".format(idfp, status))
- hashkey = request.matchdict['hashkey']
-<<<<<<< HEAD
log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
"----- END REQUEST BODY -----\n\n")
-=======
+
+ hashkey = request.matchdict['hashkey']
# the incoming hashkey is double quoted, and WSGI unquotes once...
hashkey = unquote(hashkey)
->>>>>>> master
try:
player = DBSession.query(Player).\
def player_captimes_data(request):
- player_id = int(request.matchdict['id'])
+ player_id = int(request.matchdict['player_id'])
if player_id <= 2:
player_id = -1;
- PlayerCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
- 'player_id', 'game_id', 'map_id', 'map_name', 'server_id', 'server_name'])
+ if request.params.has_key('page'):
+ current_page = request.params['page']
+ else:
+ current_page = 1
- dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id', 'map_id',
- 'map_name', 'server_id', 'server_name').\
- from_statement(
- "SELECT ct.fastest_cap, "
- "ct.create_dt, "
- "ct.player_id, "
- "ct.game_id, "
- "ct.map_id, "
- "m.name map_name, "
- "g.server_id, "
- "s.name server_name "
- "FROM player_map_captimes ct, "
- "games g, "
- "maps m, "
- "servers s "
- "WHERE ct.player_id = :player_id "
- "AND g.game_id = ct.game_id "
- "AND g.server_id = s.server_id "
- "AND m.map_id = ct.map_id "
- #"ORDER BY ct.fastest_cap "
- "ORDER BY ct.create_dt desc"
- ).params(player_id=player_id).all()
+ PlayerCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap',
+ 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+ 'player_id', 'game_id', 'map_id', 'map_name', 'server_id', 'server_name'])
player = DBSession.query(Player).filter_by(player_id=player_id).one()
- player_captimes = []
- for row in dbquery:
- player_captimes.append(PlayerCaptimes(
+ #pct_q = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id', 'map_id',
+ # 'map_name', 'server_id', 'server_name').\
+ # from_statement(
+ # "SELECT ct.fastest_cap, "
+ # "ct.create_dt, "
+ # "ct.player_id, "
+ # "ct.game_id, "
+ # "ct.map_id, "
+ # "m.name map_name, "
+ # "g.server_id, "
+ # "s.name server_name "
+ # "FROM player_map_captimes ct, "
+ # "games g, "
+ # "maps m, "
+ # "servers s "
+ # "WHERE ct.player_id = :player_id "
+ # "AND g.game_id = ct.game_id "
+ # "AND g.server_id = s.server_id "
+ # "AND m.map_id = ct.map_id "
+ # #"ORDER BY ct.fastest_cap "
+ # "ORDER BY ct.create_dt desc"
+ # ).params(player_id=player_id)
+
+ try:
+ pct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
+ PlayerCaptime.player_id, PlayerCaptime.game_id, PlayerCaptime.map_id,
+ Map.name.label('map_name'), Game.server_id, Server.name.label('server_name')).\
+ filter(PlayerCaptime.player_id==player_id).\
+ filter(PlayerCaptime.game_id==Game.game_id).\
+ filter(PlayerCaptime.map_id==Map.map_id).\
+ filter(Game.server_id==Server.server_id).\
+ order_by(expr.asc(PlayerCaptime.fastest_cap)) # or PlayerCaptime.create_dt
+
+ player_captimes = Page(pct_q, current_page, items_per_page=20, url=page_url)
+
+ # replace the items in the canned pagination class with more rich ones
+ player_captimes.items = [PlayerCaptimes(
fastest_cap=row.fastest_cap,
create_dt=row.create_dt,
create_dt_epoch=timegm(row.create_dt.timetuple()),
map_id=row.map_id,
map_name=row.map_name,
server_id=row.server_id,
- server_name=row.server_name,
- ))
+ server_name=row.server_name
+ ) for row in player_captimes.items]
+
+ except Exception as e:
+ player = None
+ player_captimes = None
return {
- 'captimes':player_captimes,
'player_id':player_id,
- 'player_url':request.route_url('player_info', id=player_id),
'player':player,
+ 'captimes':player_captimes,
+ #'player_url':request.route_url('player_info', id=player_id),
}