From: Ant Zucaro Date: Sat, 16 Jan 2016 22:36:56 +0000 (-0500) Subject: Move MapCapTime and PlayerCapTime to models. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6b32382a09f8479340c519b65929bb6822d86b3e;p=xonotic%2Fxonstat.git Move MapCapTime and PlayerCapTime to models. The more I thought about it, the more I think that these two classes should live inside the models module. They are nothing more than models for views. So what if they aren't object-relational! --- diff --git a/xonstat/models.py b/xonstat/models.py index a8de35a..e34a295 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -333,6 +333,62 @@ class PlayerGroups(object): return "" % (self.player_id, self.group_name) +class MapCapTime(object): + """Fastest flag capture times per map, assembled from a SQLAlchemy query""" + def __init__(self, row): + self.fastest_cap = row.fastest_cap + self.create_dt = row.create_dt + self.create_dt_epoch = timegm(row.create_dt.timetuple()) + self.create_dt_fuzzy = pretty_date(row.create_dt) + self.player_id = row.player_id + self.player_nick = row.player_nick + self.player_nick_stripped = strip_colors(row.player_nick) + self.player_nick_html = html_colors(row.player_nick) + self.game_id = row.game_id + self.server_id = row.server_id + self.server_name = row.server_name + + def to_dict(self): + return { + "fastest_cap" : self.fastest_cap.total_seconds(), + "create_dt_epoch" : self.create_dt_epoch, + "create_dt_fuzzy" : self.create_dt_fuzzy, + "player_id" : self.player_id, + "player_nick" : self.player_nick, + "player_nick_stripped" : self.player_nick_stripped, + "game_id" : self.game_id, + "server_id" : self.server_id, + "server_name" : self.server_name, + } + + +class PlayerCapTime(object): + """Fastest flag capture times per player, assembled from a SQLAlchemy query""" + def __init__(self, row): + self.fastest_cap = row.fastest_cap + self.create_dt = row.create_dt + self.create_dt_epoch = timegm(row.create_dt.timetuple()) + self.create_dt_fuzzy = pretty_date(row.create_dt) + self.player_id = row.player_id + self.game_id = row.game_id + self.map_id = row.map_id + self.map_name = row.map_name + self.server_id = row.server_id + self.server_name = row.server_name + + def to_dict(self): + return { + "fastest_cap" : self.fastest_cap.total_seconds(), + "create_dt_epoch": self.create_dt_epoch, + "create_dt_fuzzy": self.create_dt_fuzzy, + "game_id":self.game_id, + "map_id": self.map_id, + "map_name": self.map_name, + "server_id": self.server_id, + "server_name": self.server_name, + } + + def initialize_db(engine=None): DBSession.configure(bind=engine) Base.metadata.bind = engine diff --git a/xonstat/views/map.py b/xonstat/views/map.py index a10073d..f43ee35 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -164,33 +164,6 @@ def map_info_json(request): return [{'status':'not implemented'}] -class MapCapTime(object): - def __init__(self, row): - self.fastest_cap = row.fastest_cap - self.create_dt = row.create_dt - self.create_dt_epoch = timegm(row.create_dt.timetuple()) - self.create_dt_fuzzy = pretty_date(row.create_dt) - self.player_id = row.player_id - self.player_nick = row.player_nick - self.player_nick_stripped = strip_colors(row.player_nick) - self.player_nick_html = html_colors(row.player_nick) - self.game_id = row.game_id - self.server_id = row.server_id - self.server_name = row.server_name - - def to_dict(self): - return { - "fastest_cap" : self.fastest_cap.total_seconds(), - "create_dt_epoch" : self.create_dt_epoch, - "create_dt_fuzzy" : self.create_dt_fuzzy, - "player_id" : self.player_id, - "player_nick" : self.player_nick, - "player_nick_stripped" : self.player_nick_stripped, - "game_id" : self.game_id, - "server_id" : self.server_id, - "server_name" : self.server_name, - } - def map_captimes_data(request): map_id = int(request.matchdict['id']) diff --git a/xonstat/views/player.py b/xonstat/views/player.py index a751ace..5f6cba2 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -973,31 +973,6 @@ def player_elo_info_text(request): } -class PlayerCapTime(object): - def __init__(self, row): - self.fastest_cap = row.fastest_cap - self.create_dt = row.create_dt - self.create_dt_epoch = timegm(row.create_dt.timetuple()) - self.create_dt_fuzzy = pretty_date(row.create_dt) - self.player_id = row.player_id - self.game_id = row.game_id - self.map_id = row.map_id - self.map_name = row.map_name - self.server_id = row.server_id - self.server_name = row.server_name - - def to_dict(self): - return { - "fastest_cap" : self.fastest_cap.total_seconds(), - "create_dt_epoch": self.create_dt_epoch, - "create_dt_fuzzy": self.create_dt_fuzzy, - "game_id":self.game_id, - "map_id": self.map_id, - "map_name": self.map_name, - "server_id": self.server_id, - "server_name": self.server_name, - } - def player_captimes_data(request): player_id = int(request.matchdict['player_id']) if player_id <= 2: