]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/elo.py
Highlight the filtered game mode.
[xonotic/xonstat.git] / xonstat / elo.py
index 48a24e831bfd1a6dddbec61130aeb2314d63dfc2..60da5311a15c3bad02a90df3e625979ac9278733 100644 (file)
@@ -1,3 +1,4 @@
+import datetime
 import logging
 import math
 import random
@@ -63,8 +64,15 @@ def process_elos(game, session, game_type_cd=None):
             filter(PlayerGameStat.player_id > 2).\
             all():
                 # scores are per second
-                scores[p] = s/float(a.seconds)
-                alivetimes[p] = a.seconds
+                # with a short circuit to handle alivetimes > game
+                # durations, which can happen due to warmup being
+                # included (most often in duels)
+                if game.duration is not None and a.seconds > game.duration.seconds:
+                    scores[p] = s/float(game.duration.seconds)
+                    alivetimes[p] = game.duration.seconds
+                else:
+                    scores[p] = s/float(a.seconds)
+                    alivetimes[p] = a.seconds
 
     player_ids = scores.keys()
 
@@ -178,6 +186,7 @@ def update_elos(game, session, elos, scores, ep):
 
         elos[pid].elo = new_elo
         elos[pid].games += 1
+        elos[pid].update_dt = datetime.datetime.utcnow()
 
         log.debug("Setting Player {0}'s Elo delta to {1}. Elo is now {2} (was {3}).".format(pid, elo_deltas[pid], new_elo, old_elo))