]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/models/main.py
Remove more refs to sqlahelper.
[xonotic/xonstat.git] / xonstat / models / main.py
1 """
2 Models related to the main index page.
3 """
4
5 import datetime
6 from xonstat.util import html_colors
7
8
9 class SummaryStat(object):
10     """
11     The high level summary line that is shown on the main page.
12     """
13
14     def __repr__(self):
15         return ("<SummaryStat(total_players={0.total_players}, total_games={0.total_games}, "
16                 "total_servers={0.total_servers})>".format(self))
17
18
19 class ActivePlayer(object):
20     """
21     A record in the "Most Active Players" list.
22     """
23
24     def __init__(self, sort_order=None, player_id=None, nick=None, alivetime=None):
25         self.sort_order = sort_order
26         self.player_id = player_id
27         self.nick = nick
28         self.alivetime = alivetime
29
30     def nick_html_colors(self):
31         return html_colors(self.nick)
32
33     def __repr__(self):
34         return "<ActivePlayer({0.sort_order}, {0.player_id})>".format(self)
35
36
37 class ActiveServer(object):
38     """
39     A record in the "Most Active Servers" list.
40     """
41
42     def __init__(self, sort_order=None, server_id=None, server_name=None, play_time=None):
43         self.sort_order = sort_order
44         self.server_id = server_id
45         self.server_name = server_name
46         self.play_time = play_time
47
48     def play_time_str(self, max_segments=3):
49         if not self.play_time:
50             return "0m"
51
52         days, seconds = divmod(self.play_time.total_seconds(), 60*60*24)
53         hours, seconds = divmod(seconds, 60*60)
54         mins, seconds = divmod(seconds, 60)
55
56         parts = []
57         if days > 0 and len(parts) < max_segments:
58             parts.append("{}d".format(int(days)))
59
60         if hours > 0 and len(parts) < max_segments:
61             if len(parts) > 0:
62                 prefix = ", "
63             else:
64                 prefix = ""
65
66             parts.append("{}{}h".format(prefix, int(hours)))
67
68         if mins > 0 and len(parts) < max_segments:
69             if len(parts) > 0:
70                 prefix = ", "
71             else:
72                 prefix = ""
73
74             parts.append("{}{}m".format(prefix, int(mins)))
75
76         return "".join(parts)
77
78     def __repr__(self):
79         return "<ActiveServer({0.sort_order}, {0.server_id})>".format(self)
80
81
82 class ActiveMap(object):
83     """
84     A record in the "Most Active Maps" list.
85     """
86
87     def __init__(self, sort_order=None, map_id=None, map_name=None, games=None):
88         self.sort_order = sort_order
89         self.map_id = map_id
90         self.map_name = map_name
91         self.games = games
92
93     def __repr__(self):
94         return "<ActiveMap({0.sort_order}, {0.map_id})>".format(self)