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
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)
mapper(PlayerRank, player_ranks_table)
mapper(PlayerCaptime, player_captimes_table)
mapper(SummaryStat, summary_stats_table)
+ mapper(TeamGameStat, team_game_stats_table)
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
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
except Exception as e:\r
if session:\r
session.rollback()\r
- return e\r
+ raise e\r