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

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})