Commit 2677317c authored by fred's avatar fred

add some statistics

parent 7603eaa5
{% extends "base.html" %}
{% load i18n %}
{% block appbar %}
<h2>Nonstop - Statisticss</h2>
{% endblock %}
{% block content %}
<div class="nonstop-stats">
{% for zone in zones %}
<h3>{{ zone.title }} <span>({{zone.start}} → {{zone.end}})</span></h3>
<ul>
<li>Number of tracks: {{zone.stats.count}}
<ul>
<li>Instru: {{zone.stats.instru}} ({{zone.stats.instru_percentage}})</li>
<li>SABAM: {{zone.stats.sabam}} ({{zone.stats.sabam_percentage}})</li>
<li>CFWB: {{zone.stats.cfwb}} ({{zone.stats.cfwb_percentage}})</li>
</ul></li>
</ul>
{% endfor %}
</div>
{% endblock %}
from django.conf.urls import url
from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView
from .views import SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView, TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView
urlpatterns = [
# Example: /2012/nov/10/
url(r'^$', RedirectTodayView.as_view(), name='nonstop-today'),
url(r'^stats/$', StatisticsView.as_view(), name='stats-view'),
url(r'^tracks/(?P<pk>\d+)/$', TrackDetailView.as_view(), name='track-view'),
url(r'^artists/$', ArtistListView.as_view(), name='artist-list'),
url(r'^artists/(?P<pk>\d+)/$', ArtistDetailView.as_view(), name='artist-view'),
......
......@@ -4,12 +4,13 @@ from cStringIO import StringIO
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.views.generic.base import RedirectView
from django.views.generic.base import RedirectView, TemplateView
from django.views.generic.dates import DayArchiveView
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import SomaLogLine, Track, Artist
from emissions.models import Nonstop
class SomaDayArchiveView(DayArchiveView):
queryset = SomaLogLine.objects.all()
......@@ -57,3 +58,46 @@ class ArtistDetailView(DetailView):
class ArtistListView(ListView):
model = Artist
class ZoneStats(object):
def __init__(self, zone):
self.zone = zone
def count(self, **kwargs):
return Track.objects.filter(nonstop_zones=self.zone, **kwargs).count()
def percentage(self, **kwargs):
total = self.count()
if total == 0:
return '-'
return str(100 * self.count(**kwargs) / total)
def instru(self):
return self.count(instru=True)
def instru_percentage(self):
return self.percentage(instru=True)
def sabam(self):
return self.count(sabam=True)
def sabam_percentage(self):
return self.percentage(sabam=True)
def cfwb(self):
return self.count(cfwb=True)
def cfwb_percentage(self):
return self.percentage(cfwb=True)
class StatisticsView(TemplateView):
template_name = 'nonstop/statistics.html'
def get_context_data(self, **kwargs):
context = super(StatisticsView, self).get_context_data(**kwargs)
context['zones'] = Nonstop.objects.all().order_by('start')
for zone in context['zones']:
zone.stats = ZoneStats(zone)
return context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment