]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add a function to determine the Elo category.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 29 Jan 2017 14:18:03 +0000 (09:18 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 29 Jan 2017 14:18:03 +0000 (09:18 -0500)
xonstat/views/submission.py

index 6fa73400ecc5c40d224c3fd2cd57e6cbdc89cf2a..b942f09821675bf437ff466744f826a8199b3025 100644 (file)
@@ -16,6 +16,27 @@ from xonstat.util import strip_colors, qfont_decode, verify_request, weapon_map
 log = logging.getLogger(__name__)
 
 
 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."""
 
 class Submission(object):
     """Parses an incoming POST request for stats submissions."""
 
@@ -127,6 +148,30 @@ class Submission(object):
         return self
 
 
         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 parse_stats_submission(body):
     """
     Parses the POST request body for a stats submission
@@ -330,27 +375,6 @@ def do_precondition_checks(request, game_meta, raw_players):
         )
 
 
         )
 
 
-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
 def num_real_players(player_events):
     """
     Returns the number of real players (those who played