]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Adding player_elo_info_text template for use within Xonotic (basic player info)
authorJan Behrens <zykure@web.de>
Sat, 17 Aug 2013 10:33:01 +0000 (12:33 +0200)
committerJan Behrens <zykure@web.de>
Sat, 17 Aug 2013 10:40:58 +0000 (12:40 +0200)
xonstat/__init__.py
xonstat/templates/player_elo_info_text.mako [new file with mode: 0644]
xonstat/views/__init__.py
xonstat/views/player.py

index 449d3b93e23f614881e0b0da838ac68dada2a4e1..49493d8cfb53bc5dda2406da3be9598b92c59ad7 100644 (file)
@@ -54,7 +54,10 @@ def main(global_config, **settings):
     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")
diff --git a/xonstat/templates/player_elo_info_text.mako b/xonstat/templates/player_elo_info_text.mako
new file mode 100644 (file)
index 0000000..b600045
--- /dev/null
@@ -0,0 +1,19 @@
+V 1
+R XonStat/1.0
+T ${now}
+S ${request.route_url('player_info', id=player.player_id)}
+P ${hashkey}
+n ${player.nick}
+i ${player.player_id}
+% if player.active_ind == True:
+e active-ind 1
+% else:
+e active-ind 0
+% endif
+e location
+% for game_type_cd in elos.keys():
+% if game_type_cd != 'overall':
+G ${game_type_cd}
+e elo ${elos[game_type_cd].elo}
+% endif
+% endfor
index d88a1390eacc8a2cdefd281a7a986e87dcb93427..5073d74aa41cb9746000925651641b9f8d3884de 100644 (file)
@@ -3,8 +3,9 @@ from xonstat.views.player import player_index, player_info, player_game_index
 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
index fa8cde44ded4cfe90d161388130546a6ae45de59..824b980e242369541cc9aec2c897bd849a043146 100644 (file)
@@ -789,6 +789,7 @@ def player_damage_json(request):
 
 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.
@@ -904,6 +905,7 @@ def player_elo_info_data(request):
     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).\
@@ -916,7 +918,11 @@ def player_elo_info_data(request):
         log.debug(e)
         raise pyramid.httpexceptions.HTTPNotFound
 
-    return {'elos':elos}
+    return {
+        'hashkey':hashkey,
+        'player':player,
+        'elos':elos,
+    }
 
 
 def player_elo_info_json(request):
@@ -925,15 +931,42 @@ 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: