Models related to the main index page.
"""
+import datetime
from xonstat.util import html_colors
self.server_name = server_name
self.play_time = play_time
+ def play_time_str(self):
+ hour = 3600
+ day = hour * 24
+
+ if not self.play_time:
+ return "0m"
+
+ total_seconds = self.play_time.total_seconds()
+ if total_seconds >= day:
+ return "{}d".format(round(float(total_seconds) / day, 1))
+ elif day > total_seconds >= hour:
+ return "{}h".format(round(float(total_seconds) / hour, 1))
+ else:
+ return "{}m".format(round(float(total_seconds) / 60, 1))
+
def __repr__(self):
return "<ActiveServer({0.sort_order}, {0.server_id})>".format(self)
<tr>
<th class="small-2">#</th>
<th class="small-7">Server</th>
- <th class="small-3">Games</th>
+ <th class="small-3">Play Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>${ts.sort_order}</td>
<td class="no-stretch"><a href="${request.route_url('server_info', id=ts.server_id)}" title="Go to the server info page for ${ts.server_name}">${ts.server_name}</a></td>
- <td>${ts.games}</td>
+ <td>${ts.play_time_str()}</td>
</tr>
% endfor
</tbody>
<tr>
<th class="small-2">#</th>
<th class="small-7">Server</th>
- <th class="small-3">Games</th>
+ <th class="small-3">Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>${ts.sort_order}</td>
<td class="no-stretch"><a href="${request.route_url('server_info', id=ts.server_id)}" title="Go to the server info page for ${ts.server_name}">${ts.server_name}</a></td>
- <td>${ts.games}</td>
+ <td>${ts.play_time_str()}</td>
</tr>
% endfor
</tbody>