various and messy patchs...
This commit is contained in:
@@ -8,6 +8,7 @@ from django.db.models import (Field, NullBooleanField,
|
||||
from graphos.sources.simple import SimpleDataSource
|
||||
from graphos.renderers import gchart
|
||||
|
||||
from maraudes.models import Rencontre
|
||||
from notes.models import Sujet
|
||||
from .models import GroupeLieux
|
||||
|
||||
@@ -186,6 +187,27 @@ class AgePieChart(PieWrapper):
|
||||
super().__init__(data=data, title="Âge")
|
||||
|
||||
|
||||
|
||||
class IndividuGroupeChart(PieWrapper):
|
||||
|
||||
def __init__(self, queryset):
|
||||
data = [("individu/groupe", "count")]
|
||||
|
||||
# Cast parent Rencontre objects
|
||||
queryset = Rencontre.objects.filter(
|
||||
pk__in=queryset.values_list('rencontre')
|
||||
)
|
||||
|
||||
counts = collections.defaultdict(lambda: 0)
|
||||
for rencontre in queryset:
|
||||
counts[rencontre.groupe_ou_individu()] += 1
|
||||
print(counts)
|
||||
|
||||
for label, count in counts.items():
|
||||
data += [(label, count)]
|
||||
super().__init__(data=data, title="Individu ou Groupe")
|
||||
|
||||
|
||||
class RencontreParSujetChart(PieWrapper):
|
||||
|
||||
labels = (('Rencontre unique', (1,)),
|
||||
@@ -229,6 +251,17 @@ class RencontreParMoisChart(gchart.ColumnChart):
|
||||
)
|
||||
|
||||
|
||||
|
||||
def gen_heure_minute(_from, to):
|
||||
start_hour = _from.hour
|
||||
stop_hour, stop_min = to.hour, to.minute
|
||||
|
||||
for hour in range(start_hour, stop_hour + 1):
|
||||
yield datetime.time(hour, 0)
|
||||
if not (hour == stop_hour and 30 > stop_min):
|
||||
yield datetime.time(hour, 30)
|
||||
|
||||
|
||||
class RencontreParHeureChart(gchart.AreaChart):
|
||||
def __init__(self, queryset):
|
||||
data = [("Heure", "Rencontres démarrées", "Au total (démarré + en cours)")]
|
||||
@@ -238,9 +271,10 @@ class RencontreParHeureChart(gchart.AreaChart):
|
||||
data += [(heure, par_heure[heure], en_continu[heure]) for heure in sorted(par_heure.keys())]
|
||||
else:
|
||||
data += [("Heure", 0, 0)]
|
||||
|
||||
super().__init__(SimpleDataSource(data),
|
||||
options={
|
||||
"title": "Fréquentation de la maraude en fonction de l'heure (par quart d'heure)"
|
||||
"title": "Fréquentation de la maraude en fonction de l'heure (par quart d'heure)",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -8,4 +8,5 @@ urlpatterns = [
|
||||
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'^frequentation/$', views.FrequentationChartsView.as_view(), name="frequentation"),
|
||||
url(r'^comparatif/$', views.ComparatifHeures.as_view(), name="comparatif"),
|
||||
]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
@@ -141,13 +142,42 @@ class FrequentationChartsView(MultipleChartsView):
|
||||
('Par mois', charts.RencontreParMoisChart),
|
||||
('Par heure', charts.RencontreParHeureChart),
|
||||
('Par sujet', charts.RencontreParSujetChart),
|
||||
('Par lieu', charts.RencontreParLieuChart)
|
||||
('Par lieu', charts.RencontreParLieuChart),
|
||||
('Individu ou Groupe', charts.IndividuGroupeChart),
|
||||
])
|
||||
|
||||
def get_queryset(self):
|
||||
return self.get_observations_queryset()
|
||||
|
||||
|
||||
class ComparatifHeures(MultipleChartsView):
|
||||
title = "Comparaison décalage heures"
|
||||
_charts = OrderedDict([
|
||||
('Par mois', charts.RencontreParMoisChart),
|
||||
('Par heure', charts.RencontreParHeureChart),
|
||||
('Par sujet', charts.RencontreParSujetChart),
|
||||
('Par lieu', charts.RencontreParLieuChart)
|
||||
])
|
||||
|
||||
def get_queryset(self):
|
||||
#return self.get_observations_queryset()
|
||||
debut_essai = datetime.datetime(2017, 11, 23)
|
||||
|
||||
# Horaires démarrés le 23novembre 2017, calcul de la période effective d'application
|
||||
duree_periode_essai = datetime.datetime.now() - debut_essai
|
||||
|
||||
if self.year == 2017:
|
||||
debut_periode = debut_essai.replace(year=2016)
|
||||
fin_periode = debut_periode + duree_periode_essai
|
||||
elif self.year == 2018:
|
||||
debut_periode = debut_essai
|
||||
fin_periode = debut_essai + duree_periode_essai
|
||||
else:
|
||||
debut_periode, fin_periode = (None, None)
|
||||
|
||||
print(debut_periode, fin_periode)
|
||||
return Observation.objects.filter(created_date__range=(debut_periode, fin_periode))
|
||||
|
||||
# AjaxMixin
|
||||
class AjaxOrRedirectMixin(object):
|
||||
""" For view that should be retrieved by Ajax only. If not,
|
||||
|
||||
Reference in New Issue
Block a user