]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Fetch ranks for the post-match report.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 29 Nov 2015 15:05:08 +0000 (10:05 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 29 Nov 2015 15:05:08 +0000 (10:05 -0500)
The ranks are updated daily, so they don't change game-per-game for an
individual, but having the rank value still tells people how strong a player
is that they've been playing against.

xonstat/views/submission.py

index 67afe6cd3021a6145bc74fe15bb507ebc1c3b65a..79ead377436fb1d227026e27d7d977efe8ba8d97 100644 (file)
@@ -832,6 +832,22 @@ def create_weapon_stats(session, game_meta, game, player, pgstat, events):
     return pwstats
 
 
+def get_ranks(session, player_ids, game_type_cd):
+    """
+    Gets the rank entries for all players in the given list, returning a dict
+    of player_id -> PlayerRank instance. The rank entry corresponds to the
+    game type of the parameter passed in as well.
+    """
+    ranks = {}
+    for pr in session.query(PlayerRank).\
+            filter(PlayerRank.player_id.in_(player_ids)).\
+            filter(PlayerRank.game_type_cd == game_type_cd).\
+            all():
+                ranks[pr.player_id] = pr
+
+    return ranks
+
+
 def submit_stats(request):
     """
     Entry handler for POST stats submissions.
@@ -932,6 +948,9 @@ def submit_stats(request):
         session.commit()
         log.debug('Success! Stats recorded.')
 
+        # ranks are fetched after we've done the "real" processing
+        ranks = get_ranks(session, player_ids, game_type_cd)
+
         # plain text response
         request.response.content_type = 'text/plain'
 
@@ -943,6 +962,7 @@ def submit_stats(request):
                 "player_ids" : player_ids,
                 "hashkeys"   : hashkeys,
                 "elos"       : ep.wip,
+                "ranks"      : ranks,
         }
 
     except Exception as e: