]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add two helper methods to simplify.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 21 Jan 2013 21:39:41 +0000 (16:39 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 21 Jan 2013 21:39:41 +0000 (16:39 -0500)
xonstat/views/submission.py

index 71b86cabcb8f54c3dac0b77fc3eafea1b5c90783..02d883f295196892d39b62ef9ec8acb8636bccfe 100644 (file)
@@ -228,6 +228,25 @@ def has_required_metadata(metadata):
     return flg_has_req_metadata\r
 \r
 \r
+def should_do_weapon_stats(game_type_cd):\r
+    """True of the game type should record weapon stats. False otherwise."""\r
+    if game_type_cd in 'cts':\r
+        return False\r
+    else:\r
+        return True\r
+\r
+\r
+def should_do_elos(game_type_cd):\r
+    """True of the game type should process Elos. False otherwise."""\r
+    elo_game_types = ('duel', 'dm', 'ctf', 'tdm', 'kh',\r
+            'ka', 'ft', 'freezetag')\r
+\r
+    if game_type_cd in elo_game_types:\r
+        return True\r
+    else:\r
+        return False\r
+\r
+\r
 def register_new_nick(session, player, new_nick):\r
     """\r
     Change the player record's nick to the newly found nick. Store the old\r
@@ -530,9 +549,6 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
 \r
 def create_weapon_stats(session, game_meta, game, player, pgstat, events):\r
     """Weapon stats handler for all game types"""\r
-    if game.game_type_cd in 'cts' or player.player_id == 1:\r
-        return []\r
-\r
     pwstats = []\r
 \r
     # Version 1 of stats submissions doubled the data sent.\r
@@ -597,11 +613,6 @@ def create_weapon_stats(session, game_meta, game, player, pgstat, events):
 \r
 def create_elos(session, game):\r
     """Elo handler for all game types."""\r
-\r
-    # the following game types do not record elo\r
-    if game.game_type_cd in 'cts':\r
-        return None\r
-\r
     try:\r
         process_elos(game, session)\r
     except Exception as e:\r
@@ -630,7 +641,9 @@ def submit_stats(request):
         do_precondition_checks(request, game_meta, raw_players)\r
 \r
         # the "duel" gametype is fake\r
-        if num_real_players(raw_players) == 2 and game_meta['G'] == 'dm':\r
+        if len(raw_players) == 2 \\r
+            and num_real_players(raw_players) == 2 \\r
+            and game_meta['G'] == 'dm':\r
             game_meta['G'] = 'duel'\r
 \r
         #----------------------------------------------------------------------\r
@@ -671,10 +684,12 @@ def submit_stats(request):
             pgstat = create_game_stat(session, game_meta, game, server,\r
                     gmap, player, events)\r
 \r
-            pwstats = create_weapon_stats(session, game_meta, game, player,\r
-                    pgstat, events)\r
+            if should_do_weapon_stats(game_type_cd) and player.player_id > 1:\r
+                pwstats = create_weapon_stats(session, game_meta, game, player,\r
+                        pgstat, events)\r
 \r
-        create_elos(session, game)\r
+        if should_do_elos(game_type_cd):\r
+            create_elos(session, game)\r
 \r
         session.commit()\r
         log.debug('Success! Stats recorded.')\r