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_elo_info_json", "/elo/{hashkey}")
+ config.add_route("player_elo_info_text", "/elo/{hashkey}")
+ config.add_view(player_elo_info_text, route_name="player_elo_info_text", renderer="player_elo_info_text.mako")
+
+ config.add_route("player_elo_info_json", "/elo/{hashkey}.json") ## FIXME - doesn't seem to work?
config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
from xonstat.views.player import player_accuracy
from xonstat.views.player import player_index_json, player_info_json
from xonstat.views.player import player_game_index_json, player_accuracy_json
-from xonstat.views.player import player_damage_json, player_hashkey_info_json
-from xonstat.views.player import player_hashkey_info_text, player_elo_info_json
+from xonstat.views.player import player_damage_json
+from xonstat.views.player import player_elo_info_text, player_elo_info_json
+from xonstat.views.player import player_hashkey_info_text, player_hashkey_info_json
from xonstat.views.player import player_captimes, player_captimes_json
from xonstat.views.game import game_index, game_info, rank_index
def player_hashkey_info_data(request):
(idfp, status) = verify_request(request)
+ print "player_hashkey_info_data [idfp={0} status={1}]".format(idfp, status)
# if config is to *not* verify requests and we get nothing back, this
# query will return nothing and we'll 404.
Provides elo information on a specific player. Raw data is returned.
"""
hashkey = request.matchdict['hashkey']
+ print "player_elo_info_data [hashkey={0}]".format(hashkey)
try:
player = DBSession.query(Player).\
filter(Player.player_id == Hashkey.player_id).\
log.debug(e)
raise pyramid.httpexceptions.HTTPNotFound
- return {'elos':elos}
+ return {
+ 'hashkey':hashkey,
+ 'player':player,
+ 'elos':elos,
+ }
def player_elo_info_json(request):
"""
elo_info = player_elo_info_data(request)
+ player = player_info['player'].to_dict()
+
elos = {}
for gt, elo in elo_info['elos'].items():
elos[gt] = to_json(elo.to_dict())
return [{
'version': 1,
+ 'player': player,
'elos': elos,
}]
+
+def player_elo_info_text(request):
+ """
+ Provides elo information on a specific player. Plain text.
+ """
+ # UTC epoch
+ now = timegm(datetime.datetime.utcnow().timetuple())
+
+ # All player_info fields are converted into JSON-formattable dictionaries
+ elo_info = player_elo_info_data(request)
+
+ # this is a plain text response, if we don't do this here then
+ # Pyramid will assume html
+ request.response.content_type = 'text/plain'
+
+ return {
+ 'version': 1,
+ 'now': now,
+ 'hashkey': elo_info['hashkey'],
+ 'player': elo_info['player'],
+ 'elos': elo_info['elos'],
+ }
+
+
def player_captimes_data(request):
player_id = int(request.matchdict['id'])
if player_id <= 2: