]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Parse and store the game's duration.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 9 Nov 2012 04:18:55 +0000 (23:18 -0500)
committerJan Behrens <zykure@web.de>
Sun, 23 Dec 2012 14:18:33 +0000 (15:18 +0100)
The duration has been sent for a while as the 'D' line, but
it hasn't really been needed until now; it was just a nice thing
to have. Now Elo calculations are messing up because the warmup
time is being summed into player alivetimes. This duration field
can assist in creating a workaround. Having it, Elo calculations
can know the true maximum game time, so anything higher can be
brought down to the "floor" of the real duration of the match.

xonstat/views/submission.py

index 7b4db4e981c783602118f5c5ce712d19c16bb858..364babb67ff3419fcb34f704f78a1fc8687a5142 100644 (file)
@@ -299,7 +299,8 @@ def get_or_create_map(session=None, name=None):
 
 
 def create_game(session=None, start_dt=None, game_type_cd=None, 
 
 
 def create_game(session=None, start_dt=None, game_type_cd=None, 
-        server_id=None, map_id=None, winner=None, match_id=None):
+        server_id=None, map_id=None, winner=None, match_id=None,
+        duration=None):
     """
     Creates a game. Parameters:
 
     """
     Creates a game. Parameters:
 
@@ -316,6 +317,11 @@ def create_game(session=None, start_dt=None, game_type_cd=None,
                 server_id=server_id, map_id=map_id, winner=winner)
     game.match_id = match_id
 
                 server_id=server_id, map_id=map_id, winner=winner)
     game.match_id = match_id
 
+    try:
+        game.duration = datetime.timedelta(seconds=int(round(float(duration))))
+    except:
+        pass
+
     try:
         session.query(Game).filter(Game.server_id==server_id).\
                 filter(Game.match_id==match_id).one()
     try:
         session.query(Game).filter(Game.server_id==server_id).\
                 filter(Game.match_id==match_id).one()
@@ -562,7 +568,7 @@ def parse_body(request):
             if key in 'S' 'n':
                 value = unicode(value, 'utf-8')
 
             if key in 'S' 'n':
                 value = unicode(value, 'utf-8')
 
-            if key in 'V' 'T' 'G' 'M' 'S' 'C' 'R' 'W' 'I':
+            if key in 'V' 'T' 'G' 'M' 'S' 'C' 'R' 'W' 'I' 'D':
                 game_meta[key] = value
 
             if key == 'P':
                 game_meta[key] = value
 
             if key == 'P':
@@ -671,14 +677,19 @@ def stats_submit(request):
 
         gmap = get_or_create_map(session=session, name=game_meta['M'])
 
 
         gmap = get_or_create_map(session=session, name=game_meta['M'])
 
-        # FIXME: use the gmtime instead of utcnow() when the timezone bug is
-        # fixed
+        # duration is optional
+        if 'D' in game_meta:
+            duration = game_meta['D']
+        else:
+            duration = None
+
         game = create_game(session=session, 
                 start_dt=datetime.datetime.utcnow(),
                 #start_dt=datetime.datetime(
                     #*time.gmtime(float(game_meta['T']))[:6]), 
                 server_id=server.server_id, game_type_cd=game_meta['G'], 
         game = create_game(session=session, 
                 start_dt=datetime.datetime.utcnow(),
                 #start_dt=datetime.datetime(
                     #*time.gmtime(float(game_meta['T']))[:6]), 
                 server_id=server.server_id, game_type_cd=game_meta['G'], 
-                   map_id=gmap.map_id, match_id=game_meta['I'])
+                   map_id=gmap.map_id, match_id=game_meta['I'],
+                   duration=duration)
 
         # find or create a record for each player
         # and add stats for each if they were present at the end
 
         # find or create a record for each player
         # and add stats for each if they were present at the end