]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Handle the halving of weapon stats a little better.
authorAnt Zucaro <azucaro@gmail.com>
Sat, 8 Sep 2012 18:59:00 +0000 (14:59 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sat, 8 Sep 2012 18:59:00 +0000 (14:59 -0400)
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
xonstat/views/submission.py

index 6de2fa05666948a0bd9fcde785a0c1bf83fab754..6b29c2cc9c998f2de698d7bcf617dc6dc65a8228 100644 (file)
@@ -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 "<PlayerWeaponStat(%s, %s, %s)>" % (self.player_weapon_stats_id, self.player_id, self.game_id)
 
index c248f424017c8b1ca3f9c745d58acb77bf91beed..ab5bd336e8560e7af50254581ace691811b3d20b 100644 (file)
@@ -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)