Models related to the main index page.
"""
+import datetime
from xonstat.util import html_colors
"""
def __repr__(self):
- return ("<SummaryStat(total_players={}, total_games={}, total_servers={})>"
- .format(self.total_players, self.total_games, self.total_servers))
+ return ("<SummaryStat(total_players={0.total_players}, total_games={0.total_games}, "
+ "total_servers={0.total_servers})>".format(self))
class ActivePlayer(object):
return html_colors(self.nick)
def __repr__(self):
- return "<ActivePlayer({}, {})>".format(self.sort_order, self.player_id)
+ return "<ActivePlayer({0.sort_order}, {0.player_id})>".format(self)
class ActiveServer(object):
A record in the "Most Active Servers" list.
"""
- def __init__(self, sort_order=None, server_id=None, server_name=None, games=None):
+ def __init__(self, sort_order=None, server_id=None, server_name=None, play_time=None):
self.sort_order = sort_order
self.server_id = server_id
self.server_name = server_name
- self.games = games
+ self.play_time = play_time
+
+ def play_time_str(self, max_segments=3):
+ if not self.play_time:
+ return "0m"
+
+ days, seconds = divmod(self.play_time.total_seconds(), 60*60*24)
+ hours, seconds = divmod(seconds, 60*60)
+ mins, seconds = divmod(seconds, 60)
+
+ parts = []
+ if days > 0 and len(parts) < max_segments:
+ parts.append("{}d".format(int(days)))
+
+ if hours > 0 and len(parts) < max_segments:
+ if len(parts) > 0:
+ prefix = ", "
+ else:
+ prefix = ""
+
+ parts.append("{}{}h".format(prefix, int(hours)))
+
+ if mins > 0 and len(parts) < max_segments:
+ if len(parts) > 0:
+ prefix = ", "
+ else:
+ prefix = ""
+
+ parts.append("{}{}m".format(prefix, int(mins)))
+
+ return "".join(parts)
def __repr__(self):
- return "<ActiveServer({}, {})>".format(self.sort_order, self.server_id)
+ return "<ActiveServer({0.sort_order}, {0.server_id})>".format(self)
class ActiveMap(object):
self.games = games
def __repr__(self):
- return "<ActiveMap({}, {})>".format(self.sort_order, self.map_id)
+ return "<ActiveMap({0.sort_order}, {0.map_id})>".format(self)