log = logging.getLogger(__name__)
+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
+
+
+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
+
+
class Submission(object):
"""Parses an incoming POST request for stats submissions."""
# distinct weapons that we have seen fired
self.weapons = set()
+ # number of real players in the match
+ self.real_players = 0
+
# the parsing deque (we use this to allow peeking)
self.q = collections.deque(self.body.split("\n"))
try:
items = self.q.popleft().strip().split(' ', 1)
if len(items) == 1:
+ # Some keys won't have values, like 'L' records where the server isn't actually
+ # participating in any ladders. These can be safely ignored.
return None, None
else:
return items
except:
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)
+
def parse_player(self, key, pid):
"""Construct a player events listing from the submission."""
elif key == 'e':
(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)
elif key == 'n':
player[key] = unicode(value, 'utf-8')
elif key in player_keys:
self.q.appendleft("{} {}".format(key, value))
break
+ if is_real_player(player) and played_in_game(player):
+ self.real_players += 1
+
self.players.append(player)
def parse_team(self, key, tid):
return self
+def elo_submission_category(submission):
+ """Determines the Elo category purely by what is in the submission data."""
+ mod = submission.meta.get("O", "None")
+
+ vanilla_allowed_weapons = {"shotgun", "devastatorblaster", "mortar", "vortex", "electro",
+ "arc", "hagar", "crylink", "machinegun"}
+ insta_allowed_weapons = {"vaporizer", "blaster"}
+ overkill_allowed_weapons = {"hmg", "vortex", "shotgun blaster", "machinegun", "rpc"}
+
+ if mod == "Xonotic":
+ if len(submission.weapons - vanilla_allowed_weapons) == 0:
+ return "vanilla"
+ elif mod == "InstaGib":
+ if len(submission.weapons - insta_allowed_weapons) == 0:
+ return "insta"
+ elif mod == "Overkill":
+ if len(submission.weapons - overkill_allowed_weapons) == 0:
+ return "overkill"
+ else:
+ return "general"
+
+ return "general"
+
+
def parse_stats_submission(body):
"""
Parses the POST request body for a stats submission
)
-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
-
-
-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
-
-
def num_real_players(player_events):
"""
Returns the number of real players (those who played