2 Models related to games.
5 from xonstat.models.mixins import FuzzyDateMixin, EpochMixin
6 from xonstat.util import strip_colors, html_colors
9 class Game(FuzzyDateMixin, EpochMixin):
14 def __init__(self, game_id=None, start_dt=None, game_type_cd=None, server_id=None, map_id=None,
16 self.game_id = game_id
17 self.start_dt = start_dt
18 self.game_type_cd = game_type_cd
19 self.server_id = server_id
24 return "<Game({0.game_id}, {0.start_dt}, {0.game_type_cd}, {0.server_id})>".format(self)
28 'game_id': self.game_id,
29 'start': self.start_dt.strftime('%Y-%m-%dT%H:%M:%SZ'),
30 'game_type_cd': self.game_type_cd,
31 'server_id': self.server_id
35 class PlayerGameStat(object):
37 The individual statistics a player has gained/lost during a game.
40 def __init__(self, player_game_stat_id=None, create_dt=None):
41 self.player_game_stat_id = player_game_stat_id
42 self.create_dt = create_dt
45 return "<PlayerGameStat({0.player_id}, {0.game_id}, {0.create_dt})>".format(self)
50 fastest = round(float(self.fastest.seconds) + (self.fastest.microseconds/1000000.0), 2)
55 'player_game_stat_id': self.player_game_stat_id,
56 'player_id': self.player_id,
57 'game_id': self.game_id,
59 'stripped_nick': self.stripped_nick,
61 'alivetime': self.alivetime.total_seconds(),
63 'deaths': self.deaths,
64 'suicides': self.suicides,
66 'time': self.time.total_seconds() if self.time else None,
67 'captures': self.captures,
68 'pickups': self.pickups,
70 'returns': self.returns,
71 'collects': self.collects,
72 'destroys': self.destroys,
73 'pushes': self.pushes,
74 'carrier_frags': self.carrier_frags,
76 'scoreboardpos': self.scoreboardpos,
78 'revivals': self.revivals,
81 'create_dt': self.create_dt.strftime('%Y-%m-%dT%H:%M:%SZ'),
84 def nick_stripped(self):
86 return "Anonymous Player"
88 return strip_colors(self.nick)
90 def nick_html_colors(self, limit=None):
92 return "Anonymous Player"
94 return html_colors(self.nick, limit)
96 def team_html_color(self):
107 class PlayerWeaponStat(object):
109 The metrics for a single weapon in a game for a player.
112 def __init__(self, player_id=None, game_id=None, weapon_cd=None):
113 self.player_id = player_id
114 self.game_id = game_id
115 self.weapon_cd = weapon_cd
123 return ("<PlayerWeaponStat({0.player_weapon_stats_id}, {0.player_id}, {0.game_id})>"
128 'weapon_cd': self.weapon_cd,
129 'player_weapon_stats_id': self.player_weapon_stats_id,
130 'player_id': self.player_id,
131 'game_id': self.game_id,
135 'actual': self.actual,
140 class TeamGameStat(object):
145 def __init__(self, team_game_stat_id=None, create_dt=None):
146 self.team_game_stat_id = team_game_stat_id
147 self.create_dt = create_dt
150 return "<TeamGameStat({0.team_game_stat_id}, {0.game_id}, {0.team})>".format(self)
154 'team_game_stat_id': self.team_game_stat_id,
155 'game_id': self.game_id,
158 'rounds': self.rounds,
160 'create_dt': self.create_dt.strftime('%Y-%m-%dT%H:%M:%SZ'),
163 # TODO: move this function to util
164 def team_html_color(self):
175 class PlayerGameAnticheat(object):
177 Anticheat metrics sent by the server to identify odd patterns.
180 def __init__(self, player_id=None, game_id=None, key=None, value=None, create_dt=None):
181 self.player_id = player_id
182 self.game_id = game_id
185 self.create_dt = create_dt
188 return "<PlayerGameAnticheat({0.key}, {0.value})>".format(self)
191 class GameType(object):
193 A particular type of game.
197 return "<GameType({0.game_type_cd}, {0.descr}, {0.active_ind})>".format(self)
201 'game_type_cd': self.game_type_cd,
203 'active': self.active_ind,
207 class Weapon(object):
209 A particular type of weapon.
213 return "<Weapon({0.weapon_cd}, {0.descr}, {0.active_ind})>".format(self)
217 'weapon_cd': self.weapon_cd,
219 'active': self.active_ind,
223 class PlayerGameFragMatrix(object):
225 Frags made by an individual player in a single game.
228 def __init__(self, game_id, player_game_stat_id, player_id, player_index, matrix):
229 self.game_id = game_id
230 self.player_game_stat_id = player_game_stat_id
231 self.player_id = player_id
232 self.player_index = player_index
236 return "<PlayerGameFragMatrix({0.game_id}, {0.player_game_stat_id})>".format(self)