From: Ant Zucaro Date: Thu, 13 Jun 2013 21:27:07 +0000 (-0400) Subject: Store team score information. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=121e93999be9aa246dc4c63631c5414546b7163e;p=xonotic%2Fxonstat.git Store team score information. --- diff --git a/xonstat/models.py b/xonstat/models.py index bda038b..c6d5790 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -260,6 +260,36 @@ class SummaryStat(object): return "" % (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 "" % (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) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index b002454..6c035fe 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -696,6 +696,53 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events): return pgstat +def create_default_team_stat(session, game_type_cd): + """Creates a blanked-out teamstat record for the given game type""" + + # this is what we have to do to get partitioned records in - grab the + # sequence value first, then insert using the explicit ID (vs autogenerate) + seq = Sequence('team_game_stats_team_game_stat_id_seq') + teamstat_id = session.execute(seq) + teamstat = TeamGameStat(team_game_stat_id=teamstat_id, + create_dt=datetime.datetime.utcnow()) + + # all team game modes have a score, so we'll zero that out always + teamstat.score = 0 + + if game_type_cd in 'ca' 'ft' 'lms' 'ka': + teamstat.rounds = 0 + + if game_type_cd == 'ctf': + teamstat.caps = 0 + + return teamstat + + +def create_team_stat(session, game, events): + """Team stats handler for all game types""" + + try: + teamstat = create_default_team_stat(session, game.game_type_cd) + teamstat.game_id = game.game_id + + # we should have a team ID if we have a 'Q' event + if re.match(r'^team#\d+$', events.get('Q', '')): + team = int(events.get('Q').replace('team#', '')) + teamstat.team = team + + # gametype-specific stuff is handled here. if passed to us, we store it + for (key,value) in events.items(): + if key == 'scoreboard-score': teamstat.score = int(round(float(value))) + if key == 'scoreboard-caps': teamstat.caps = int(value) + if key == 'scoreboard-rounds': teamstat.rounds = int(value) + + session.add(teamstat) + except Exception as e: + raise e + + return teamstat + + def create_weapon_stats(session, game_meta, game, player, pgstat, events): """Weapon stats handler for all game types""" pwstats = [] @@ -839,6 +886,12 @@ def submit_stats(request): pwstats = create_weapon_stats(session, game_meta, game, player, pgstat, events) + for events in raw_teams: + try: + teamstat = create_team_stat(session, game, events) + except Exception as e: + raise e + if should_do_elos(game_type_cd): create_elos(session, game) @@ -848,4 +901,4 @@ def submit_stats(request): except Exception as e: if session: session.rollback() - return e + raise e