Configure required minimum players using the ini file.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 20 Oct 2011 11:11:04 +0000 (07:11 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 20 Oct 2011 11:11:04 +0000 (07:11 -0400)
development.ini
xonstat/views/submission.py

index 9c8cc6cc4a015f6ab0cab2a2c77bea41fa43acc0..b3c83729c4b4c5ab71121077530e34a253425d7a 100644 (file)
@@ -6,15 +6,19 @@ debug_notfound = false
 debug_routematch = false
 debug_templates = true
 default_locale_name = en
-sqlalchemy.url = postgresql+psycopg2://xonstat:xonstat@localhost:5432/xonstatdb
+sqlalchemy.url = postgresql+psycopg2://xonstat:xonstat@localhost:5433/xonstatdb
 session.type = file
 session.data_dir = %(here)s/data/sessions/data
 session.lock_dir = %(here)s/data/sessions/lock
 session.key = xonstat
-session.secret = 433fa4b080c2147c79c0ed1cb54e3ce81371fb33
+session.secret = CHANGEMECHANGEMECHANGEME
 jinja2.directories = xonstat:templates
 mako.directories = xonstat:templates
 
+# how many "real" players are required before the data
+# is stored in the database
+xonstat.minimum_required_players = 1
+
 [pipeline:main]
 pipeline =
     egg:WebError#evalerror
@@ -51,7 +55,7 @@ handlers =
 qualname = xonstat
 
 [logger_sqlalchemy]
-level = INFO
+level = WARN
 handlers =
 qualname = sqlalchemy.engine
 # "level = INFO" logs SQL queries.
index 88c4bb2839de9f72cb2d24de2668de7f23101e9b..89e4920eb5f029067bca7c918ddca28ce80dcf3f 100755 (executable)
@@ -2,6 +2,7 @@ import datetime
 import logging\r
 import re\r
 import time\r
+from pyramid.config import get_current_registry\r
 from pyramid.response import Response\r
 from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound\r
 from xonstat.models import *\r
@@ -18,13 +19,20 @@ def has_minimum_real_players(player_events):
     """\r
     flg_has_min_real_players = True\r
 \r
+    settings = get_current_registry().settings\r
+    try: \r
+        minimum_required_players = int(\r
+                settings['xonstat.minimum_required_players'])\r
+    except:\r
+        minimum_required_players = 2\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
+    if real_players < minimum_required_players:\r
         flg_has_min_real_players = False\r
 \r
     return flg_has_min_real_players\r
@@ -37,10 +45,10 @@ def has_required_metadata(metadata):
     """\r
     flg_has_req_metadata = True\r
 \r
-    if 'T' not in game_meta or\\r
-        'G' not in game_meta or\\r
-        'M' not in game_meta or\\r
-        'S' not in game_meta:\r
+    if 'T' not in metadata or\\r
+        'G' not in metadata or\\r
+        'M' not in metadata or\\r
+        'S' not in metadata:\r
             flg_has_req_metadata = False\r
 \r
     return flg_has_req_metadata\r
@@ -443,7 +451,7 @@ def stats_submit(request):
                 start_dt=datetime.datetime(\r
                     *time.gmtime(float(game_meta['T']))[:6]), \r
                 server_id=server.server_id, game_type_cd=game_meta['G'], \r
-                map_id=gmap.map_id, winner=winner)\r
+                map_id=gmap.map_id)\r
     \r
         # find or create a record for each player\r
         # and add stats for each if they were present at the end\r