]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add a minimum required players function
authorAnt Zucaro <azucaro@gmail.com>
Tue, 18 Oct 2011 22:28:54 +0000 (18:28 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 18 Oct 2011 22:28:54 +0000 (18:28 -0400)
xonstat/views/submission.py

index a196610547fdc3cfed9200a731168628c02560c5..88c4bb2839de9f72cb2d24de2668de7f23101e9b 100755 (executable)
@@ -9,6 +9,27 @@ from xonstat.util import strip_colors
 \r
 log = logging.getLogger(__name__)\r
 \r
+\r
+def has_minimum_real_players(player_events):\r
+    """\r
+    Determines if the collection of player events has enough "real" players\r
+    to store in the database. The minimum setting comes from the config file\r
+    under the setting xonstat.minimum_real_players.\r
+    """\r
+    flg_has_min_real_players = True\r
+\r
+    real_players = 0\r
+    for events in player_events:\r
+        if is_real_player(events):\r
+            real_players += 1\r
+\r
+    #TODO: put this into a config setting in the ini file?\r
+    if real_players < 1:\r
+        flg_has_min_real_players = False\r
+\r
+    return flg_has_min_real_players\r
+\r
+\r
 def has_required_metadata(metadata):\r
     """\r
     Determines if a give set of metadata has enough data to create a game,\r
@@ -411,13 +432,7 @@ def stats_submit(request):
                     "Can't continue.")\r
             raise Exception("Required game meta fields (T, G, M, or S) missing.")\r
     \r
-        real_players = 0\r
-        for events in players:\r
-            if is_real_player(events):\r
-                real_players += 1\r
-\r
-        #TODO: put this into a config setting in the ini file?\r
-        if real_players < 1:\r
+        if not has_minimum_real_players(players):\r
             raise Exception("The number of real players is below the minimum. "\\r
                     "Stats will be ignored.")\r
 \r