]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Provide a plaintext response to stats submissions.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 19 Nov 2015 01:29:07 +0000 (20:29 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 19 Nov 2015 01:29:07 +0000 (20:29 -0500)
For all of XonStat's history the POST requests sent in by servers had plain
HTTP responses. This begins to change with this commit, which responds back to
the Xonotic server with meaningful information about /what happened/ during the
match that was just submitted. Of particular importance are the player_ids and
elo delta values that were stored as a result of the game. The template
establishing the format for this is submit_stats.mako. It will be extended
after we decide what other things we want to include.

xonstat/__init__.py
xonstat/templates/submit_stats.mako [new file with mode: 0644]
xonstat/views/submission.py

index 55cce5b4707f1a84d085e1a370c04e58dee64b99..760a6f3284aeabcf0b10d245145e7cf375fd2691 100644 (file)
@@ -55,7 +55,7 @@ def main(global_config, **settings):
 
     # MAIN SUBMISSION ROUTE
     config.add_route("submit_stats", "stats/submit")
-    config.add_view(submit_stats, route_name="submit_stats")
+    config.add_view(submit_stats, route_name="submit_stats", renderer="submit_stats.mako")
 
     # PLAYER ROUTES
     config.add_route("player_game_index",      "/player/{player_id:\d+}/games")
diff --git a/xonstat/templates/submit_stats.mako b/xonstat/templates/submit_stats.mako
new file mode 100644 (file)
index 0000000..7f9af1b
--- /dev/null
@@ -0,0 +1,18 @@
+V 1
+R XonStat/1.0
+T ${now}
+S ${request.route_url('server_info', id=server.server_id)}
+G ${request.route_url('game_info', id=game.game_id)}
+M ${request.route_url('map_info', id=gmap.map_id)}
+% for player_id in player_ids:
+P ${hashkeys[player_id]}
+i ${request.route_url('player_info', id=player_id)}
+% if player_id in elos:
+e elo ${elos[player_id].elo.elo}
+e elo_delta ${elos[player_id].elo_delta}
+e elo_games ${elos[player_id].elo.games}
+e k-factor ${elos[player_id].k}
+e score-per-second ${elos[player_id].score_per_second}
+e alivetime ${elos[player_id].alivetime}
+% endif
+% endfor
index dab96af0a5a1b4ce07a0ede51e1ac58b468987b1..67afe6cd3021a6145bc74fe15bb507ebc1c3b65a 100644 (file)
@@ -5,6 +5,7 @@ import pyramid.httpexceptions
 import re
 import time
 import sqlalchemy.sql.expression as expr
+from calendar import timegm
 from pyramid.response import Response
 from sqlalchemy import Sequence
 from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
@@ -893,6 +894,7 @@ def submit_stats(request):
         # keep track of the players we've seen
         player_ids = []
         pgstats = []
+        hashkeys = {}
         for events in raw_players:
             player = get_or_create_player(
                 session = session,
@@ -904,11 +906,11 @@ def submit_stats(request):
             pgstats.append(pgstat)
 
             if player.player_id > 1:
-                anticheats = create_anticheats(session, pgstat, game, player,
-                    events)
+                anticheats = create_anticheats(session, pgstat, game, player, events)
 
             if player.player_id > 2:
                 player_ids.append(player.player_id)
+                hashkeys[player.player_id] = events['P']
 
             if should_do_weapon_stats(game_type_cd) and player.player_id > 1:
                 pwstats = create_weapon_stats(session, game_meta, game, player,
@@ -929,7 +931,20 @@ def submit_stats(request):
 
         session.commit()
         log.debug('Success! Stats recorded.')
-        return Response('200 OK')
+
+        # plain text response
+        request.response.content_type = 'text/plain'
+
+        return {
+                "now"        : timegm(datetime.datetime.utcnow().timetuple()),
+                "server"     : server,
+                "game"       : game,
+                "gmap"       : gmap,
+                "player_ids" : player_ids,
+                "hashkeys"   : hashkeys,
+                "elos"       : ep.wip,
+        }
+
     except Exception as e:
         if session:
             session.rollback()