Cache the stats page

This commit is contained in:
Daan Sprenkels
2018-08-16 16:58:19 +02:00
parent 3f22056157
commit 60084cfe04
5 changed files with 135 additions and 53 deletions

View File

@ -6,10 +6,20 @@
{% block content %}
<h1>Statistics</h1>
<div class="row">
{% if not stats %}
<div class="alert alert-danger">
<strong>Stats unavailable :(</strong>
</div>
{% else %}
{% if current_age_text %}
<div class="alert alert-info">
<strong>{{ current_age_text }}</strong>
{% endif %}
</div>
<div class="col-md-6">
<h2>Uploads</h2>
<h4>Total: {{ total_uploads }}</h4>
<h4>Top {{ stats_top_count }}:</h4>
<h4>Total: {{ stats.total_uploads }}</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -20,7 +30,7 @@
</tr>
</thead>
<tbody>
{% for stat in upload_stats %}
{% for stat in stats.upload_stats %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
@ -33,8 +43,8 @@
</div>
<div class="col-md-6">
<h2>Requests</h2>
<h4>Total: {{ total_requests }}</h4>
<h4>Top {{ stats_top_count }}:</h4>
<h4>Total: {{ stats.total_requests }}</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -45,11 +55,11 @@
</tr>
</thead>
<tbody>
{% for stat in request_stats %}
{% for stat in stats.request_stats %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }} ({% widthratio stat.total total_requests 100 %}%)</td>
<td>{{ stat.total }} ({% widthratio stat.total stats.total_requests 100 %}%)</td>
</tr>
{% endfor %}
</tbody>
@ -58,7 +68,7 @@
</div>
<div class="col-md-6">
<h2>Unique requests</h2>
<h4>Top {{ stats_top_count }}:</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -69,11 +79,11 @@
</tr>
</thead>
<tbody>
{% for stat in unique_request_stats %}
{% for stat in stats.unique_request_stats %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }} ({{stat.ratio }}%)</td>
<td>{{ stat.total }} ({{ stat.ratio }}%)</td>
</tr>
{% endfor %}
</tbody>
@ -82,7 +92,7 @@
</div>
<div class="col-md-6">
<h2>Most played songs</h2>
<h4>Top {{ stats_top_count }}:</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -94,7 +104,7 @@
</tr>
</thead>
<tbody>
{% for stat in most_played_songs %}
{% for stat in stats.most_played_songs %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
@ -108,7 +118,7 @@
</div>
<div class="col-md-6">
<h2>Most played songs last 14 days</h2>
<h4>Top {{ stats_top_count }}:</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -120,7 +130,7 @@
</tr>
</thead>
<tbody>
{% for stat in most_played_songs_14_days %}
{% for stat in stats.most_played_songs_14_days %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
@ -132,5 +142,6 @@
</table>
</div>
</div>
{% endif %}
</div>
{% endblock %}