The view at /elo/<hashkey> will send just Elo info about a player.
This is to facilitate a possible autobalance feature where the
Xonotic server will request Elo values for all of the
players entering the game, then use it (among other things) to
figure out who needs to be switched to make the teams right.
config.add_route("player_hashkey_info_json", "/hashkey/{hashkey}")
config.add_view(player_hashkey_info_json, route_name="player_hashkey_info_json", renderer="jsonp")
+ config.add_route("player_elo_info_json", "/elo/{hashkey}")
+ config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
+
config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
config.add_view(player_accuracy_json, route_name="player_accuracy", renderer="jsonp")
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_elo_info_json
from xonstat.views.game import game_index, game_info, rank_index
from xonstat.views.game import game_index_json, game_info_json, rank_index_json
import datetime
import json
import logging
+import pyramid.httpexceptions
import re
import sqlalchemy as sa
import sqlalchemy.sql.functions as func
'elos': elos,
'ranks': ranks,
}]
+
+
+def player_elo_info_data(request):
+ """
+ Provides elo information on a specific player. Raw data is returned.
+ """
+ hashkey = request.matchdict['hashkey']
+ try:
+ player = DBSession.query(Player).\
+ filter(Player.player_id == Hashkey.player_id).\
+ filter(Player.active_ind == True).\
+ filter(Hashkey.hashkey == hashkey).one()
+
+ elos = get_elos(player.player_id)
+
+ except Exception as e:
+ log.debug(e)
+ raise pyramid.httpexceptions.HTTPNotFound
+
+ return {'elos':elos}
+
+
+def player_elo_info_json(request):
+ """
+ Provides elo information on a specific player. JSON.
+ """
+ elo_info = player_elo_info_data(request)
+
+ elos = {}
+ for gt, elo in elo_info['elos'].items():
+ elos[gt] = to_json(elo.to_dict())
+
+ return [{
+ 'version': 1,
+ 'elos': elos,
+ }]