]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Support a ton of new fields.
authorAnt Zucaro <azucaro@gmail.com>
Sat, 26 Jan 2013 14:31:31 +0000 (09:31 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sat, 26 Jan 2013 14:31:31 +0000 (09:31 -0500)
xonstat/views/submission.py

index 8607a865d0065185b33e374450e540e9da2b657a..7e19063b2afca570bd8da03a67482389cc45a7e9 100644 (file)
@@ -506,8 +506,8 @@ def get_or_create_player(session=None, hashkey=None, nick=None):
     return player\r
 \r
 \r
-def create_game_stat(session, game_meta, game, server, gmap, player, events):\r
-    """Game stats handler for all game types"""\r
+def create_default_game_stat(session, game_type_cd):\r
+    """Creates a blanked-out pgstat record for the given game type"""\r
 \r
     # this is what we have to do to get partitioned records in - grab the\r
     # sequence value first, then insert using the explicit ID (vs autogenerate)\r
@@ -516,6 +516,58 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
     pgstat = PlayerGameStat(player_game_stat_id=pgstat_id,\r
             create_dt=datetime.datetime.utcnow())\r
 \r
+    if game_type_cd == 'as':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.collects = 0\r
+\r
+    if game_type_cd in 'ca' 'dm' 'duel' 'rune' 'tdm':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = 0\r
+\r
+    if game_type_cd == 'cq':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.captures = 0\r
+        pgstat.drops = 0\r
+\r
+    if game_type_cd == 'ctf':\r
+        pgstat.kills = pgstat.captures = pgstat.pickups = pgstat.drops = 0\r
+        pgstat.returns = pgstat.carrier_frags = 0\r
+\r
+    if game_type_cd == 'cts':\r
+        pgstat.deaths = 0\r
+\r
+    if game_type_cd == 'dom':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.pickups = 0\r
+        pgstat.drops = 0\r
+\r
+    if game_type_cd == 'ft':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.revivals = 0\r
+\r
+    if game_type_cd == 'ka':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.pickups = 0\r
+        pgstat.carrier_frags = 0\r
+        pgstat.time = datetime.timedelta(seconds=0)\r
+\r
+    if game_type_cd == 'kh':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.pickups = 0\r
+        pgstat.captures = pgstat.drops = pgstat.pushes = pgstat.destroys = 0\r
+        pgstat.carrier_frags = 0\r
+\r
+    if game_type_cd == 'lms':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.lives = 0\r
+\r
+    if game_type_cd == 'nb':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.captures = 0\r
+        pgstat.drops = 0\r
+\r
+    if game_type_cd == 'rc':\r
+        pgstat.kills = pgstat.deaths = pgstat.suicides = pgstat.laps = 0\r
+\r
+    return pgstat\r
+\r
+\r
+def create_game_stat(session, game_meta, game, server, gmap, player, events):\r
+    """Game stats handler for all game types"""\r
+\r
+    pgstat = create_default_game_stat(session, game.game_type_cd)\r
+\r
     # these fields should be on every pgstat record\r
     pgstat.game_id       = game.game_id\r
     pgstat.player_id     = player.player_id\r
@@ -526,19 +578,6 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
     pgstat.rank          = int(events.get('rank', None))\r
     pgstat.scoreboardpos = int(events.get('scoreboardpos', pgstat.rank))\r
 \r
-    # defaults for common game types only\r
-    if game.game_type_cd == 'dm' or game.game_type_cd == 'tdm' or game.game_type_cd == 'duel':\r
-        pgstat.kills = 0\r
-        pgstat.deaths = 0\r
-        pgstat.suicides = 0\r
-    elif game.game_type_cd == 'ctf':\r
-        pgstat.kills = 0\r
-        pgstat.captures = 0\r
-        pgstat.pickups = 0\r
-        pgstat.drops = 0\r
-        pgstat.returns = 0\r
-        pgstat.carrier_frags = 0\r
-\r
     if pgstat.nick != player.nick \\r
             and player.player_id > 2 \\r
             and pgstat.nick != 'Anonymous Player':\r
@@ -550,6 +589,7 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
     for (key,value) in events.items():\r
         if key == 'wins': wins = True\r
         if key == 't': pgstat.team = int(value)\r
+\r
         if key == 'scoreboard-drops': pgstat.drops = int(value)\r
         if key == 'scoreboard-returns': pgstat.returns = int(value)\r
         if key == 'scoreboard-fckills': pgstat.carrier_frags = int(value)\r
@@ -559,8 +599,27 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
         if key == 'scoreboard-deaths': pgstat.deaths = int(value)\r
         if key == 'scoreboard-kills': pgstat.kills = int(value)\r
         if key == 'scoreboard-suicides': pgstat.suicides = int(value)\r
-        if key == 'avglatency': pgstat.avg_latency = float(value)\r
+        if key == 'scoreboard-objectives': pgstat.collects = int(value)\r
+        if key == 'scoreboard-captured': pgstat.captures = int(value)\r
+        if key == 'scoreboard-released': pgstat.drops = int(value)\r
+        if key == 'scoreboard-fastest':\r
+            pgstat.fastest = datetime.timedelta(seconds=float(value)/100)\r
+        if key == 'scoreboard-takes': pgstat.pickups = int(value)\r
+        if key == 'scoreboard-ticks': pgstat.drops = int(value)\r
+        if key == 'scoreboard-revivals': pgstat.revivals = int(value)\r
+        if key == 'scoreboard-bctime':\r
+            pgstat.time = datetime.timedelta(seconds=int(value))\r
+        if key == 'scoreboard-bckills': pgstat.carrier_frags = int(value)\r
+        if key == 'scoreboard-losses': pgstat.drops = int(value)\r
+        if key == 'scoreboard-pushes': pgstat.pushes = int(value)\r
+        if key == 'scoreboard-destroyed': pgstat.destroys = int(value)\r
+        if key == 'scoreboard-kckills': pgstat.carrier_frags = int(value)\r
+        if key == 'scoreboard-lives': pgstat.lives = int(value)\r
+        if key == 'scoreboard-goals': pgstat.captures = int(value)\r
+        if key == 'scoreboard-faults': pgstat.drops = int(value)\r
+        if key == 'scoreboard-laps': pgstat.laps = int(value)\r
 \r
+        if key == 'avglatency': pgstat.avg_latency = float(value)\r
         if key == 'scoreboard-captime':\r
             pgstat.fastest_cap = datetime.timedelta(seconds=float(value)/100)\r
             if game.game_type_cd == 'ctf':\r