From 02c0cb0cc14d70962136e3fb5b81e59ce35f8bde Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sat, 8 Sep 2012 14:59:00 -0400 Subject: [PATCH] Handle the halving of weapon stats a little better. Default PlayerWeaponStat rows to all 0 to protect for missing accuracy data. Also halve all of the pwstat members at once instead of checking on each loop. --- xonstat/models.py | 7 +++++++ xonstat/views/submission.py | 17 +++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/xonstat/models.py b/xonstat/models.py index 6de2fa0..6b29c2c 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -157,6 +157,13 @@ class PlayerAchievement(object): class PlayerWeaponStat(object): + def __init__(self): + self.fired = 0 + self.max = 0 + self.hit = 0 + self.actual = 0 + self.frags = 0 + def __repr__(self): return "" % (self.player_weapon_stats_id, self.player_id, self.game_id) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index c248f42..ab5bd33 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -464,28 +464,25 @@ def create_player_weapon_stats(session=None, player=None, if 'acc-' + weapon_cd + '-cnt-fired' in player_events: pwstat.fired = int(round(float( player_events['acc-' + weapon_cd + '-cnt-fired']))) - if is_doubled: - pwstat.fired = pwstat.fired/2 if 'acc-' + weapon_cd + '-fired' in player_events: pwstat.max = int(round(float( player_events['acc-' + weapon_cd + '-fired']))) - if is_doubled: - pwstat.max = pwstat.max/2 if 'acc-' + weapon_cd + '-cnt-hit' in player_events: pwstat.hit = int(round(float( player_events['acc-' + weapon_cd + '-cnt-hit']))) - if is_doubled: - pwstat.hit = pwstat.hit/2 if 'acc-' + weapon_cd + '-hit' in player_events: pwstat.actual = int(round(float( player_events['acc-' + weapon_cd + '-hit']))) - if is_doubled: - pwstat.actual = pwstat.actual/2 if 'acc-' + weapon_cd + '-frags' in player_events: pwstat.frags = int(round(float( player_events['acc-' + weapon_cd + '-frags']))) - if is_doubled: - pwstat.frags = pwstat.frags/2 + + if is_doubled: + pwstat.fired = pwstat.fired/2 + pwstat.max = pwstat.max/2 + pwstat.hit = pwstat.hit/2 + pwstat.actual = pwstat.actual/2 + pwstat.frags = pwstat.frags/2 session.add(pwstat) pwstats.append(pwstat) -- 2.39.2