From 04f5adb0164041e4ccdf878b611387b0fbad46a1 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Wed, 1 Feb 2017 07:04:24 -0500 Subject: [PATCH] Add a check for humans who have fired a weapon during parsing. --- xonstat/views/submission.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index ab75cf0..0d3a2bb 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -65,6 +65,9 @@ class Submission(object): # distinct weapons that we have seen fired self.weapons = set() + # has a human player fired a shot? + self.human_fired_weapon = False + # the parsing deque (we use this to allow peeking) self.q = collections.deque(self.body.split("\n")) @@ -82,11 +85,10 @@ class Submission(object): return None, None def check_for_new_weapon_fired(self, sub_key): - """Checks if a given player key (subkey, actually) is a new weapon fired in the match.""" - if sub_key.endswith("cnt-fired"): - weapon = sub_key.split("-")[1] - if weapon not in self.weapons: - self.weapons.add(weapon) + """Checks if a given weapon fired event is a new one for the match.""" + weapon = sub_key.split("-")[1] + if weapon not in self.weapons: + self.weapons.add(weapon) def parse_player(self, key, pid): """Construct a player events listing from the submission.""" @@ -96,6 +98,8 @@ class Submission(object): player = {key: pid} + player_fired_weapon = False + # Consume all following 'i' 'n' 't' 'e' records while len(self.q) > 0: (key, value) = self.next_item() @@ -105,8 +109,9 @@ class Submission(object): (sub_key, sub_value) = value.split(' ', 1) player[sub_key] = sub_value - # keep track of the distinct weapons fired during the match - self.check_for_new_weapon_fired(sub_key) + if sub_key.endswith("cnt-fired"): + player_fired_weapon = True + self.check_for_new_weapon_fired(sub_key) elif key == 'n': player[key] = unicode(value, 'utf-8') elif key in player_keys: @@ -118,8 +123,12 @@ class Submission(object): played = played_in_game(player) human = is_real_player(player) + if played and human: self.humans.append(player) + + if player_fired_weapon: + self.human_fired_weapon = True elif played and not human: self.bots.append(player) else: -- 2.39.2