]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Store team score information.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 13 Jun 2013 21:27:07 +0000 (17:27 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 13 Jun 2013 21:27:07 +0000 (17:27 -0400)
xonstat/models.py
xonstat/views/submission.py

index bda038bc82e9ba8b403e43364b5f6561774ca167..c6d57909cd435ab94635a9dcee2b7711f212a46d 100644 (file)
@@ -260,6 +260,36 @@ class SummaryStat(object):
         return "<SummaryStat(total_players=%s, total_games=%s, total_servers=%s)>" % (self.total_players, self.total_games, self.total_servers)
 
 
+class TeamGameStat(object):
+    def __init__(self, team_game_stat_id=None, create_dt=None):
+        self.team_game_stat_id = team_game_stat_id
+        self.create_dt = create_dt
+
+    def __repr__(self):
+        return "<TeamGameStat(%s, %s, %s)>" % (self.team_game_stat_id, self.game_id, self.team)
+
+    def to_dict(self):
+        return {
+            'team_game_stat_id':self.team_game_stat_id,
+            'game_id':self.game_id,
+            'team':self.team,
+            'score':self.score,
+            'rounds':self.rounds,
+            'caps':self.caps,
+            'create_dt':self.create_dt.strftime('%Y-%m-%dT%H:%M:%SZ'),
+        }
+
+    def team_html_color(self):
+        if self.team == 5:
+            return "red"
+        if self.team == 14:
+            return "blue"
+        if self.team == 13:
+            return "yellow"
+        if self.team == 10:
+            return "pink"
+
+
 def initialize_db(engine=None):
     DBSession.configure(bind=engine)
     Base.metadata.bind = engine
@@ -284,6 +314,7 @@ def initialize_db(engine=None):
     player_ranks_table = MetaData.tables['player_ranks']
     player_captimes_table = MetaData.tables['player_map_captimes']
     summary_stats_table = MetaData.tables['summary_stats']
+    team_game_stats_table = MetaData.tables['team_game_stats']
 
     # now map the tables and the objects together
     mapper(PlayerAchievement, achievements_table)
@@ -302,3 +333,4 @@ def initialize_db(engine=None):
     mapper(PlayerRank, player_ranks_table)
     mapper(PlayerCaptime, player_captimes_table)
     mapper(SummaryStat, summary_stats_table)
+    mapper(TeamGameStat, team_game_stats_table)
index b002454e963e418202cdd9a7a7ad12d646994260..6c035fef30e2db76a095a066694968c98d02a5df 100644 (file)
@@ -696,6 +696,53 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
     return pgstat\r
 \r
 \r
+def create_default_team_stat(session, game_type_cd):\r
+    """Creates a blanked-out teamstat 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
+    seq = Sequence('team_game_stats_team_game_stat_id_seq')\r
+    teamstat_id = session.execute(seq)\r
+    teamstat = TeamGameStat(team_game_stat_id=teamstat_id,\r
+            create_dt=datetime.datetime.utcnow())\r
+\r
+    # all team game modes have a score, so we'll zero that out always\r
+    teamstat.score = 0\r
+\r
+    if game_type_cd in 'ca' 'ft' 'lms' 'ka':\r
+        teamstat.rounds = 0\r
+\r
+    if game_type_cd == 'ctf':\r
+        teamstat.caps = 0\r
+\r
+    return teamstat\r
+\r
+\r
+def create_team_stat(session, game, events):\r
+    """Team stats handler for all game types"""\r
+\r
+    try:\r
+        teamstat = create_default_team_stat(session, game.game_type_cd)\r
+        teamstat.game_id = game.game_id\r
+\r
+        # we should have a team ID if we have a 'Q' event\r
+        if re.match(r'^team#\d+$', events.get('Q', '')):\r
+            team = int(events.get('Q').replace('team#', ''))\r
+            teamstat.team = team\r
+\r
+        # gametype-specific stuff is handled here. if passed to us, we store it\r
+        for (key,value) in events.items():\r
+            if key == 'scoreboard-score': teamstat.score = int(round(float(value)))\r
+            if key == 'scoreboard-caps': teamstat.caps = int(value)\r
+            if key == 'scoreboard-rounds': teamstat.rounds = int(value)\r
+\r
+        session.add(teamstat)\r
+    except Exception as e:\r
+        raise e\r
+\r
+    return teamstat\r
+\r
+\r
 def create_weapon_stats(session, game_meta, game, player, pgstat, events):\r
     """Weapon stats handler for all game types"""\r
     pwstats = []\r
@@ -839,6 +886,12 @@ def submit_stats(request):
                 pwstats = create_weapon_stats(session, game_meta, game, player,\r
                         pgstat, events)\r
 \r
+        for events in raw_teams:\r
+            try:\r
+                teamstat = create_team_stat(session, game, events)\r
+            except Exception as e:\r
+                raise e\r
+\r
         if should_do_elos(game_type_cd):\r
             create_elos(session, game)\r
 \r
@@ -848,4 +901,4 @@ def submit_stats(request):
     except Exception as e:\r
         if session:\r
             session.rollback()\r
-        return e\r
+        raise e\r