]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Use categories in submissions.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 30 Apr 2017 12:20:42 +0000 (08:20 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 30 Apr 2017 12:20:42 +0000 (08:20 -0400)
xonstat/elo.py
xonstat/views/submission.py

index 60e7505d1d65135d2cd53d4032b804da01743c8c..2e2ba761884b18d11e30247d746f5ad8c063d412 100644 (file)
@@ -99,11 +99,14 @@ class EloProcessor:
     """EloProcessor is a container for holding all of the intermediary AND
     final values used to calculate Elo deltas for all players in a given
     game."""
-    def __init__(self, session, game, pgstats):
+    def __init__(self, session, game, pgstats, category):
 
         # game which we are processing
         self.game = game
 
+        # which type of Elo category we are processing
+        self.category = category
+
         # work-in-progress values, indexed by player
         self.wip = {}
 
@@ -138,14 +141,16 @@ class EloProcessor:
 
         # Fetch current Elo values for all players. For players that don't yet 
         # have an Elo record, we'll give them a default one.
-        for e in session.query(PlayerElo).\
-                filter(PlayerElo.player_id.in_(self.wip.keys())).\
-                filter(PlayerElo.game_type_cd==game.game_type_cd).all():
+        for e in session.query(PlayerElo)\
+                .filter(PlayerElo.player_id.in_(self.wip.keys()))\
+                .filter(PlayerElo.game_type_cd==game.game_type_cd)\
+                .filter(PlayerElo.category==self.category)\
+                .all():
                     self.wip[e.player_id].elo = e
 
         for pid in self.wip.keys():
             if self.wip[pid].elo is None:
-                self.wip[pid].elo = PlayerElo(pid, game.game_type_cd, ELOPARMS.initial)
+                self.wip[pid].elo = PlayerElo(pid, game.game_type_cd, ELOPARMS.initial, category)
 
             # determine k reduction
             self.wip[pid].k = KREDUCTION.eval(self.wip[pid].elo.games, self.wip[pid].alivetime,
index 28026adb03eb71517d053d3d8f8dcc72caba54fa..3f45a7fce5168c83014df6eaa9fd4bd49deaffaa 100644 (file)
@@ -1126,7 +1126,11 @@ def submit_stats(request):
             create_team_stat(session, game, events)
 
         if server.elo_ind and gametype_elo_eligible(submission.game_type_cd):
-            ep = EloProcessor(session, game, pgstats)
+            category = elo_submission_category(submission)
+            if not server.categories or category not in server.categories:
+                category = "general"
+
+            ep = EloProcessor(session, game, pgstats, category)
             ep.save(session)
             elos = ep.wip
         else: