added some test charts

This commit is contained in:
agerbaud
2017-08-02 12:54:02 +02:00
parent 0ffc83e056
commit ace8167fcb
6 changed files with 85 additions and 3 deletions

View File

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

View File

@@ -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'

View File

@@ -15,7 +15,7 @@
{% block breadcrumbs %}
{{ block.super }}
<li>Maraudes</li>
<li>Tests</li>
{% endblock %}
{% block page_content %}

View File

@@ -0,0 +1,25 @@
{% extends "statistiques/base.html" %}
{% load static %}
{% block title %}{{ block.super }} Maraudes{% endblock %}
{% block sidebar %}
{{ block.super }}
<div class="panel panel-primary">
<div class="panel-body text-right">
{% include "statistiques/filter_form.html" %}
</div>
</div>
{% endblock %}
{% block breadcrumbs %}
{{ block.super }}
<li>Tests</li>
{% endblock %}
{% block page_content %}
{{ par_heure.as_html }}
<hr />
{{ par_heure_continu.as_html }}
{% endblock %}

View File

@@ -7,5 +7,6 @@ urlpatterns = [
url('^charts/$', views.PieChartView.as_view(), name="pies"),
url(r'^details/(?P<pk>[0-9]+)/$', views.StatistiquesDetailsView.as_view(), name="details"),
url(r'^update/(?P<pk>[0-9]+)/$', views.StatistiquesUpdateView.as_view(), name="update"),
url(r'^tests/$', views.TestStatsView.as_view(), name="tests"),
]

View File

@@ -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