]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add a hashkey view similar to the player_info JSON one.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 4 Dec 2012 02:55:22 +0000 (21:55 -0500)
committerJan Behrens <zykure@web.de>
Sun, 23 Dec 2012 14:18:35 +0000 (15:18 +0100)
This view is driven by hashkey (not player_id) so the Xonotic
server can query for info using something it knows. The response
value is a JSON object containing the things in the player info
page minus the recent weapons and recent games stuff.

The URL pattern is /hashkey/<hashkey value>.

All this is pretty alpha and is subject to change once we truly
determine our needs  Think of this as a proof of concept for
communicating between the game server and the webapp.

xonstat/__init__.py
xonstat/views/__init__.py
xonstat/views/player.py

index e7bfba387aeb46b69998a113cf85ded34a0c93a3..5ee0e4641684e92cbab1c16049903f34dbb7304e 100644 (file)
@@ -9,7 +9,7 @@ def main(global_config, **settings):
     """ This function returns a Pyramid WSGI application.
     """
     # setup the database engine
-    engine = engine_from_config(settings, 'sqlalchemy.')
+    engine = engine_from_config(settings, 'sqlalchemy.', pool_size=5)
     sqlahelper.add_engine(engine)
 
     # initialize database structures
@@ -40,6 +40,9 @@ def main(global_config, **settings):
     config.add_view(player_info,      route_name="player_info",      renderer="player_info.mako")
     config.add_view(player_info_json, route_name="player_info_json", renderer="jsonp")
 
+    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_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")
index f8eb769c260bc5bc29dab07a029aed595e4061a4..879f546e6392618c7312ef53d7e16b47a1190d62 100644 (file)
@@ -3,7 +3,7 @@ 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
+from xonstat.views.player import player_damage_json, player_hashkey_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
index d625dffbe1761d2fb3738f1ede3c9b5159b4717c..66e74eb3e78b14871dbc773bd43582ff4405dfd7 100644 (file)
@@ -787,3 +787,76 @@ def player_damage_json(request):
        games = over how many games to display damage. Can be up to 50.
     """
     return player_damage_data(request)
+
+
+def player_hashkey_info_data(request):
+    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()
+
+        games_played   = get_games_played(player.player_id)
+        overall_stats  = get_overall_stats(player.player_id)
+        fav_maps       = get_fav_maps(player.player_id)
+        elos           = get_elos(player.player_id)
+        ranks          = get_ranks(player.player_id)
+
+    except Exception as e:
+        raise e
+        player         = None
+        games_played   = None
+        overall_stats  = None
+        fav_maps       = None
+        elos           = None
+        ranks          = None
+
+    return {'player':player,
+            'games_played':games_played,
+            'overall_stats':overall_stats,
+            'fav_maps':fav_maps,
+            'elos':elos,
+            'ranks':ranks,
+            }
+
+
+def player_hashkey_info_json(request):
+    """
+    Provides detailed information on a specific player. JSON.
+    """
+
+    # All player_info fields are converted into JSON-formattable dictionaries
+    player_info = player_hashkey_info_data(request)
+
+    player = player_info['player'].to_dict()
+
+    games_played = {}
+    for game in player_info['games_played']:
+        games_played[game.game_type_cd] = to_json(game)
+
+    overall_stats = {}
+    for gt,stats in player_info['overall_stats'].items():
+        overall_stats[gt] = to_json(stats)
+
+    elos = {}
+    for gt,elo in player_info['elos'].items():
+        elos[gt] = to_json(elo.to_dict())
+
+    ranks = {}
+    for gt,rank in player_info['ranks'].items():
+        ranks[gt] = to_json(rank)
+
+    fav_maps = {}
+    for gt,mapinfo in player_info['fav_maps'].items():
+        fav_maps[gt] = to_json(mapinfo)
+
+    return [{
+        'version':          1,
+        'player':           player,
+        'games_played':     games_played,
+        'overall_stats':    overall_stats,
+        'fav_maps':         fav_maps,
+        'elos':             elos,
+        'ranks':            ranks,
+    }]