Show the average, min and max player stats for each server.

This commit is contained in:
A. Svensson 2015-03-07 14:28:17 +01:00
parent f5a0ad7396
commit 3937b92835
2 changed files with 38 additions and 2 deletions

View File

@ -16,5 +16,17 @@ class ServerDetailView(generic.DetailView):
history = PlayerHistory()
points = history.get_points(server)
context['player_history'] = points
# Moving average for the last day
# TODO: remove the hardcoded value
tmp = [players for time, players in points[-96:]]
context['daily_average'] = sum(tmp) / float(len(tmp))
context['daily_min'] = min(tmp)
context['daily_max'] = max(tmp)
tmp = [players for time, players in points]
context['total_average'] = sum(tmp) / float(len(tmp))
context['total_min'] = min(tmp)
context['total_max'] = max(tmp)
return context

View File

@ -17,11 +17,35 @@
<button class="btn btn-default">No homepage</button>
{% endif %}
<h2>Server History</h2>
<h2>Player Population</h2>
<p>Currently online: {{server.current_players}} players</p>
<p>Last updated <span title="{{server.last_updated|date:'r'}} GMT">
{{server.last_updated|timesince}}
</span>ago.</p>
<p>Online players: {{server.current_players}}</p>
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>Average</th>
<th>Min</th>
<th>Max</th>
</tr>
</thead>
<tbody>
<tr>
<th>Daily</th>
<th>{{daily_average|floatformat}}</th>
<th>{{daily_min}}</th>
<th>{{daily_max}}</th>
</tr>
<tr>
<th>Total</th>
<th>{{total_average|floatformat}}</th>
<th>{{total_min}}</th>
<th>{{total_max}}</th>
</tr>
</table>
<div id="chart"></div>
<div id="tooltip"></div>