From: Ant Zucaro Date: Fri, 9 Nov 2012 04:18:55 +0000 (-0500) Subject: Parse and store the game's duration. X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonstat.git;a=commitdiff_plain;h=f09e6d3517d3765bb12fbf650bef6524361e6fad Parse and store the game's duration. 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. --- diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index 7b4db4e..364babb 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -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, - 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: @@ -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 + 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() @@ -562,7 +568,7 @@ def parse_body(request): 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': @@ -671,14 +677,19 @@ def stats_submit(request): 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'], - 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