]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Support teamscores when parsing, but do not store them yet.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 10 May 2013 02:27:23 +0000 (22:27 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 10 May 2013 02:27:23 +0000 (22:27 -0400)
xonstat/views/submission.py

index fd70934d0d53d8744059b0067b81df7d7b87c764..b002454e963e418202cdd9a7a7ad12d646994260 100644 (file)
@@ -25,6 +25,10 @@ def parse_stats_submission(body):
     game_meta = {}\r
     events = {}\r
     players = []\r
+    teams = []\r
+\r
+    # we're not in either stanza to start\r
+    in_P = in_Q = False\r
 \r
     for line in body.split('\n'):\r
         try:\r
@@ -34,16 +38,34 @@ def parse_stats_submission(body):
             if key in 'S' 'n':\r
                 value = unicode(value, 'utf-8')\r
 \r
-            if key not in 'P' 'n' 'e' 't' 'i':\r
+            if key not in 'P' 'Q' 'n' 'e' 't' 'i':\r
                 game_meta[key] = value\r
 \r
-            if key == 'P':\r
-                # if we were working on a player record already, append\r
-                # it and work on a new one (only set team info)\r
-                if len(events) > 0:\r
+            if key == 'Q' or key == 'P':\r
+                #log.debug('Found a {0}'.format(key))\r
+                #log.debug('in_Q: {0}'.format(in_Q))\r
+                #log.debug('in_P: {0}'.format(in_P))\r
+                #log.debug('events: {0}'.format(events))\r
+\r
+                # check where we were before and append events accordingly\r
+                if in_Q and len(events) > 0:\r
+                    #log.debug('creating a team (Q) entry')\r
+                    teams.append(events)\r
+                    events = {}\r
+                elif in_P and len(events) > 0:\r
+                    #log.debug('creating a player (P) entry')\r
                     players.append(events)\r
                     events = {}\r
 \r
+                if key == 'P':\r
+                    #log.debug('key == P')\r
+                    in_P = True\r
+                    in_Q = False\r
+                elif key == 'Q':\r
+                    #log.debug('key == Q')\r
+                    in_P = False\r
+                    in_Q = True\r
+\r
                 events[key] = value\r
 \r
             if key == 'e':\r
@@ -57,11 +79,13 @@ def parse_stats_submission(body):
             # no key/value pair - move on to the next line\r
             pass\r
 \r
-    # add the last player we were working on\r
-    if len(events) > 0:\r
+    # add the last entity we were working on\r
+    if in_P and len(events) > 0:\r
         players.append(events)\r
+    elif in_Q and len(events) > 0:\r
+        teams.append(events)\r
 \r
-    return (game_meta, players)\r
+    return (game_meta, players, teams)\r
 \r
 \r
 def is_blank_game(gametype, players):\r
@@ -756,7 +780,7 @@ def submit_stats(request):
                 "----- END REQUEST BODY -----\n\n")\r
 \r
         (idfp, status) = verify_request(request)\r
-        (game_meta, raw_players) = parse_stats_submission(request.body)\r
+        (game_meta, raw_players, raw_teams) = parse_stats_submission(request.body)\r
         revision = game_meta.get('R', 'unknown')\r
         duration = game_meta.get('D', None)\r
 \r