added some test charts
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
{% block breadcrumbs %}
|
||||
{{ block.super }}
|
||||
<li>Maraudes</li>
|
||||
<li>Tests</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_content %}
|
||||
|
||||
25
statistiques/templates/statistiques/test.html
Normal file
25
statistiques/templates/statistiques/test.html
Normal 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 %}
|
||||
@@ -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"),
|
||||
]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user