From e7c433bd5c1699b64500ee1e273141bd06cba10e Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Tue, 11 Dec 2012 17:28:02 -0500 Subject: [PATCH] Add a JSON Elo view to support autobalance. The view at /elo/ 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. --- xonstat/__init__.py | 3 +++ xonstat/views/__init__.py | 1 + xonstat/views/player.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 5ee0e46..2c02f99 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -43,6 +43,9 @@ def main(global_config, **settings): 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") diff --git a/xonstat/views/__init__.py b/xonstat/views/__init__.py index 879f546..4457849 100644 --- a/xonstat/views/__init__.py +++ b/xonstat/views/__init__.py @@ -4,6 +4,7 @@ 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_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 diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 66e74eb..91d0ebf 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -1,6 +1,7 @@ import datetime import json import logging +import pyramid.httpexceptions import re import sqlalchemy as sa import sqlalchemy.sql.functions as func @@ -860,3 +861,39 @@ def player_hashkey_info_json(request): '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, + }] -- 2.39.2