]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/models/map.py
Merge branch 'sev/xolonium4-badges' into 'master'
[xonotic/xonstat.git] / xonstat / models / map.py
1 """
2 Models related to maps.
3 """
4
5 from calendar import timegm
6
7 from xonstat.models.mixins import FuzzyDateMixin, EpochMixin
8 from xonstat.util import pretty_date, strip_colors, html_colors
9
10
11 class Map(FuzzyDateMixin, EpochMixin):
12     """
13     A playable map. Roughly equivalent to a pk3 file, but distinguished by name instead.
14     """
15
16     def __init__(self, name=None):
17         self.name = name
18
19     def __repr__(self):
20         return "<Map({0.map_id}, {0.name}, {0.version})>".format(self)
21
22     def to_dict(self):
23         return {
24             'map_id': self.map_id,
25             'name': self.name,
26             'version': self.version,
27         }
28
29
30 # TODO: investigate if this model is truly a model, or really just a query (i.e. namedtuple)
31 class MapCapTime(object):
32     """
33     Fastest flag capture times per map.
34     """
35
36     def __init__(self, row):
37         self.fastest_cap = row.fastest_cap
38         self.create_dt = row.create_dt
39         self.create_dt_epoch = timegm(row.create_dt.timetuple())
40         self.create_dt_fuzzy = pretty_date(row.create_dt)
41         self.player_id = row.player_id
42         self.player_nick = row.player_nick
43         self.player_nick_stripped = strip_colors(row.player_nick)
44         self.player_nick_html = html_colors(row.player_nick)
45         self.game_id = row.game_id
46         self.server_id = row.server_id
47         self.server_name = row.server_name
48
49     def to_dict(self):
50         return {
51             "fastest_cap": self.fastest_cap.total_seconds(),
52             "create_dt_epoch": self.create_dt_epoch,
53             "create_dt_fuzzy": self.create_dt_fuzzy,
54             "player_id": self.player_id,
55             "player_nick": self.player_nick,
56             "player_nick_stripped": self.player_nick_stripped,
57             "game_id": self.game_id,
58             "server_id": self.server_id,
59             "server_name": self.server_name,
60         }