From ace8167fcb3f75af68090c01cd32ad714e04c19c Mon Sep 17 00:00:00 2001 From: agerbaud Date: Wed, 2 Aug 2017 12:54:02 +0200 Subject: [PATCH] added some test charts --- notes/views.py | 4 +- settings.py | 2 +- .../templates/statistiques/index.html | 2 +- statistiques/templates/statistiques/test.html | 25 +++++++++ statistiques/urls.py | 1 + statistiques/views.py | 54 +++++++++++++++++++ 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 statistiques/templates/statistiques/test.html diff --git a/notes/views.py b/notes/views.py index a37ba15..c39aa9b 100644 --- a/notes/views.py +++ b/notes/views.py @@ -102,9 +102,11 @@ class SujetListView(ListView): def info_completed_filter(qs): + COMPLETED_RATIO = 70 # % of total fields completed + excluded_set = set() for sujet in qs: - if sujet.statistiques.info_completed >= 50: + if sujet.statistiques.info_completed >= COMPLETED_RATIO: excluded_set.add(sujet.pk) return qs.exclude(pk__in=excluded_set) diff --git a/settings.py b/settings.py index 0b62f6c..bbc23b2 100644 --- a/settings.py +++ b/settings.py @@ -32,7 +32,7 @@ LOGIN_URL = 'index' if DEBUG: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' else: #TODO: configure a real backend - EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' AUTHENTICATION_BACKENDS = [ 'utilisateurs.backends.CustomUserAuthentication' diff --git a/statistiques/templates/statistiques/index.html b/statistiques/templates/statistiques/index.html index 0924178..5f1e96c 100644 --- a/statistiques/templates/statistiques/index.html +++ b/statistiques/templates/statistiques/index.html @@ -15,7 +15,7 @@ {% block breadcrumbs %} {{ block.super }} -
  • Maraudes
  • +
  • Tests
  • {% endblock %} {% block page_content %} diff --git a/statistiques/templates/statistiques/test.html b/statistiques/templates/statistiques/test.html new file mode 100644 index 0000000..c7250be --- /dev/null +++ b/statistiques/templates/statistiques/test.html @@ -0,0 +1,25 @@ +{% extends "statistiques/base.html" %} +{% load static %} + +{% block title %}{{ block.super }} Maraudes{% endblock %} + + +{% block sidebar %} + {{ block.super }} +
    +
    + {% include "statistiques/filter_form.html" %} +
    +
    +{% endblock %} + +{% block breadcrumbs %} + {{ block.super }} +
  • Tests
  • +{% endblock %} + +{% block page_content %} + {{ par_heure.as_html }} +
    + {{ par_heure_continu.as_html }} +{% endblock %} diff --git a/statistiques/urls.py b/statistiques/urls.py index e792961..ebc211b 100644 --- a/statistiques/urls.py +++ b/statistiques/urls.py @@ -7,5 +7,6 @@ urlpatterns = [ url('^charts/$', views.PieChartView.as_view(), name="pies"), url(r'^details/(?P[0-9]+)/$', views.StatistiquesDetailsView.as_view(), name="details"), url(r'^update/(?P[0-9]+)/$', views.StatistiquesUpdateView.as_view(), name="update"), + url(r'^tests/$', views.TestStatsView.as_view(), name="tests"), ] diff --git a/statistiques/views.py b/statistiques/views.py index 07c672d..1bdefed 100644 --- a/statistiques/views.py +++ b/statistiques/views.py @@ -175,6 +175,60 @@ class PieChartView(FilterMixin, generic.TemplateView): return context +import collections + + +def get_data_table(observations, continuous=False): + return_zero = lambda: 0 + data_table = collections.defaultdict(return_zero) + + for o in observations: + heure_debut = datetime.datetime.strptime("%s" % o.rencontre.heure_debut, "%H:%M:%S") + if continuous: + heure_fin = heure_debut + datetime.timedelta(0, o.rencontre.duree * 60) + else: + heure_fin = heure_debut + + for heure in range(heure_debut.hour, heure_fin.hour + 1): + data_table[heure] += 1 + + return data_table + + + + +class TestStatsView(FilterMixin, generic.TemplateView): + template_name = "statistiques/test.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + observations = self.get_observations_queryset() + + par_heure = get_data_table(observations) + context['par_heure'] = gchart.LineChart( + SimpleDataSource( + [("Heure", "Nbr de rencontres")] + + [(heure, par_heure[heure]) for heure in sorted(par_heure.keys())] + ), + options = { + "title": "Nombre de rencontres par heure (démarrée)" + } + ) + + en_continu = get_data_table(observations, continuous=True) + context['par_heure_continu'] = gchart.LineChart( + SimpleDataSource( + [("Heure", "Nbr de rencontres")] + + [(heure, en_continu[heure]) for heure in sorted(en_continu.keys())] + ), + options = { + "title": "Nombre de rencontres par heure (en cumulé)" + } + ) + + return context + # AjaxMixin