]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/views/submission.py
Remove more refs to sqlahelper.
[xonotic/xonstat.git] / xonstat / views / submission.py
index a830a3f14c59499fadb6f9cbead27efa9be509ec..567d8a4777ba67eb3e6b3c48be0d32a8230e4b37 100644 (file)
@@ -346,6 +346,10 @@ def has_minimum_real_players(settings, submission):
     except:
         minimum_required_players = 2
 
+    # Make an exception for CTS since it can be done by individuals and there is no Elo anyway
+    if submission.game_type_cd == "cts":
+        minimum_required_players = 1
+
     return len(submission.humans) >= minimum_required_players
 
 
@@ -405,6 +409,13 @@ def should_do_weapon_stats(game_type_cd):
     return game_type_cd not in {'cts'}
 
 
+def should_do_frag_matrix(game_type_cd):
+    """True if the game type should record frag matrix values. False otherwise."""
+    return game_type_cd in {
+        'as', 'ca', 'ctf', 'dm', 'dom', 'ft', 'freezetag', 'ka', 'kh', 'rune', 'tdm',
+    }
+
+
 def gametype_elo_eligible(game_type_cd):
     """True of the game type should process Elos. False otherwise."""
     return game_type_cd in {'duel', 'dm', 'ca', 'ctf', 'tdm', 'ka', 'ft'}
@@ -612,7 +623,7 @@ def create_game(session, game_type_cd, server_id, map_id, match_id, start_dt, du
     game.mod = mod[:64]
 
     # There is some drift between start_dt (provided by app) and create_dt
-    # (default in the database), so we'll make them the same until this is 
+    # (default in the database), so we'll make them the same until this is
     # resolved.
     game.create_dt = start_dt
 
@@ -703,10 +714,6 @@ def create_default_game_stat(session, game_type_cd):
     if game_type_cd in 'ca' 'dm' 'duel' 'rune' 'tdm':
         pgstat.kills = pgstat.deaths = pgstat.suicides = 0
 
-    if game_type_cd == 'cq':
-        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.captures = 0
-        pgstat.drops = 0
-
     if game_type_cd == 'ctf':
         pgstat.kills = pgstat.captures = pgstat.pickups = pgstat.drops = 0
         pgstat.returns = pgstat.carrier_frags = 0
@@ -731,16 +738,10 @@ def create_default_game_stat(session, game_type_cd):
         pgstat.captures = pgstat.drops = pgstat.pushes = pgstat.destroys = 0
         pgstat.carrier_frags = 0
 
-    if game_type_cd == 'lms':
-        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.lives = 0
-
     if game_type_cd == 'nb':
         pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.captures = 0
         pgstat.drops = 0
 
-    if game_type_cd == 'rc':
-        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.laps = 0
-
     return pgstat
 
 
@@ -850,7 +851,7 @@ def create_default_team_stat(session, game_type_cd):
     # all team game modes have a score, so we'll zero that out always
     teamstat.score = 0
 
-    if game_type_cd in 'ca' 'ft' 'lms' 'ka':
+    if game_type_cd in 'ca' 'ft' 'ka':
         teamstat.rounds = 0
 
     if game_type_cd == 'ctf':
@@ -1145,10 +1146,14 @@ def submit_stats(request):
             pgstat = create_game_stat(session, game, gmap, player, events)
             pgstats.append(pgstat)
 
-            frag_matrix = create_frag_matrix(session, submission.player_indexes, pgstat, events)
+            if should_do_frag_matrix(submission.game_type_cd):
+                create_frag_matrix(session, submission.player_indexes, pgstat, events)
 
             # player ranking opt-out
-            if 'r' in events and events['r'] != '0':
+            if 'r' in events and events['r'] == '0':
+                log.debug("Excluding player {} from ranking calculations (opt-out)"
+                          .format(pgstat.player_id))
+            else:
                 elo_pgstats.append(pgstat)
 
             if player.player_id > 1: