Basic statistics.

This commit is contained in:
Jim Driessen
2017-05-02 15:25:15 +02:00
parent cbc70be451
commit 0b926a4356
12 changed files with 84 additions and 1 deletions

View File

@ -39,7 +39,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'marietje',
'queues',
'songs'
'songs',
'stats'
]
MIDDLEWARE = [

View File

@ -33,6 +33,8 @@
<li{% if request.path == url %} class="active"{% endif %}><a href="{{ url }}">Upload</a></li>
{% url 'songs:manage' as url %}
<li{% if request.path == url %} class="active"{% endif %}><a href="{{ url }}">Manage</a></li>
{% url 'stats:stats' as url %}
<li{% if request.path == url %} class="active"{% endif %}><a href="{{ url }}">Stats</a></li>
{% if user.is_superuser %}
{% url 'admin:index' as url %}
<li><a href="{{ url }}">Admin</a></li>

View File

@ -33,4 +33,5 @@ urlpatterns = [
url(r'^songs/', include('songs.urls')),
url(r'^api/', include('api.urls')),
url(r'^playerapi/', include('playerapi.urls')),
url(r'^stats/', include('stats.urls')),
]

View File

3
marietje/stats/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
marietje/stats/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class StatsConfig(AppConfig):
name = 'stats'

View File

3
marietje/stats/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,46 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}Stats{% endblock %}
{% block content %}
<h1>Statistics</h1>
<h2>Uploads</h2>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>User</th>
<th># Songs</th>
</tr>
</thead>
<tbody>
{% for stat in upload_stats %}
<tr>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<h2>Requests</h2>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>User</th>
<th># Requests</th>
</tr>
</thead>
<tbody>
{% for stat in request_stats %}
<tr>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

3
marietje/stats/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

9
marietje/stats/urls.py Normal file
View File

@ -0,0 +1,9 @@
from django.conf.urls import url
from . import views
app_name = 'stats'
urlpatterns = [
url(r'^$', views.stats, name='stats'),
]

10
marietje/stats/views.py Normal file
View File

@ -0,0 +1,10 @@
from django.shortcuts import render
from django.db.models import Count
from songs.models import Song
from queues.models import PlaylistSong
def stats(request):
upload_stats = Song.objects.all().exclude(user_id=None).values('user__name').annotate(total=Count('id')).order_by('-total')
request_stats = PlaylistSong.objects.all().exclude(user_id=None).values('user__name').annotate(total=Count('id')).order_by('-total')
return render(request, 'stats/stats.html', {'upload_stats': upload_stats, 'request_stats': request_stats})