]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/views/submission.py
Submission no longer has a meta attribute!
[xonotic/xonstat.git] / xonstat / views / submission.py
index 373dc8a91f26cbb07352a50b9bc3561b9ebe811f..0307ca13e92a9a1d216920e2dfde1522ee365edc 100644 (file)
@@ -20,10 +20,7 @@ def is_real_player(events):
     """
     Determines if a given set of events correspond with a non-bot
     """
-    if not events['P'].startswith('bot'):
-        return True
-    else:
-        return False
+    return not events['P'].startswith('bot')
 
 
 def played_in_game(events):
@@ -31,10 +28,7 @@ def played_in_game(events):
     Determines if a given set of player events correspond with a player who
     played in the game (matches 1 and scoreboardvalid 1)
     """
-    if 'matches' in events and 'scoreboardvalid' in events:
-        return True
-    else:
-        return False
+    return 'matches' in events and 'scoreboardvalid' in events
 
 
 class Submission(object):
@@ -106,6 +100,12 @@ class Submission(object):
         # has a human player fired a shot?
         self.human_fired_weapon = False
 
+        # does any human have a non-zero score?
+        self.human_nonzero_score = False
+
+        # does any human have a fastest cap?
+        self.human_fastest = False
+
     def next_item(self):
         """Returns the next key:value pair off the queue."""
         try:
@@ -119,11 +119,24 @@ class Submission(object):
         except:
             return None, None
 
-    def check_for_new_weapon_fired(self, sub_key):
-        """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 add_weapon_fired(self, sub_key):
+        """Adds a weapon to the set of weapons fired during the match (a set)."""
+        self.weapons.add(sub_key.split("-")[1])
+
+    @staticmethod
+    def is_human_player(player):
+        """
+        Determines if a given set of events correspond with a non-bot
+        """
+        return not player['P'].startswith('bot')
+
+    @staticmethod
+    def played_in_game(player):
+        """
+        Determines if a given set of player events correspond with a player who
+        played in the game (matches 1 and scoreboardvalid 1)
+        """
+        return 'matches' in player and 'scoreboardvalid' in player
 
     def parse_player(self, key, pid):
         """Construct a player events listing from the submission."""
@@ -134,6 +147,8 @@ class Submission(object):
         player = {key: pid}
 
         player_fired_weapon = False
+        player_nonzero_score = False
+        player_fastest = False
 
         # Consume all following 'i' 'n' 't'  'e' records
         while len(self.q) > 0:
@@ -146,7 +161,11 @@ class Submission(object):
 
                 if sub_key.endswith("cnt-fired"):
                     player_fired_weapon = True
-                    self.check_for_new_weapon_fired(sub_key)
+                    self.add_weapon_fired(sub_key)
+                elif sub_key == 'scoreboard-score' and int(sub_value) != 0:
+                    player_nonzero_score = True
+                elif sub_key == 'scoreboard-fastest':
+                    player_fastest = True
             elif key == 'n':
                 player[key] = unicode(value, 'utf-8')
             elif key in player_keys:
@@ -156,18 +175,25 @@ class Submission(object):
                 self.q.appendleft("{} {}".format(key, value))
                 break
 
-        played = played_in_game(player)
-        human = is_real_player(player)
+        played = self.played_in_game(player)
+        human = self.is_human_player(player)
 
         if played and human:
             self.humans.append(player)
 
             if player_fired_weapon:
                 self.human_fired_weapon = True
+
+            if player_nonzero_score:
+                self.human_nonzero_score = True
+
+            if player_fastest:
+                self.human_fastest = True
+
         elif played and not human:
             self.bots.append(player)
-        else:
-            self.players.append(player)
+
+        self.players.append(player)
 
     def parse_team(self, key, tid):
         """Construct a team events listing from the submission."""
@@ -218,10 +244,16 @@ class Submission(object):
 
         return self
 
+    def __repr__(self):
+        """Debugging representation of a submission."""
+        return "game_type_cd: {}, mod: {}, players: {}, humans: {}, bots: {}, weapons: {}".format(
+            self.game_type_cd, self.mod, len(self.players), len(self.humans), len(self.bots),
+            self.weapons)
+
 
 def elo_submission_category(submission):
     """Determines the Elo category purely by what is in the submission data."""
-    mod = submission.meta.get("O", "None")
+    mod = submission.mod
 
     vanilla_allowed_weapons = {"shotgun", "devastator", "blaster", "mortar", "vortex", "electro",
                                "arc", "hagar", "crylink", "machinegun"}