cleans up code of 'statistiques' module
This commit is contained in:
@@ -32,13 +32,6 @@ LABELS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# TODO: Retrieve charts data from cache to avoid recalculating on each request
|
|
||||||
class CachedDataSource:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# TODO: Clean up...
|
|
||||||
|
|
||||||
|
|
||||||
class FieldValuesCountDataSource(SimpleDataSource):
|
class FieldValuesCountDataSource(SimpleDataSource):
|
||||||
""" Generates data from a limited set of choices.
|
""" Generates data from a limited set of choices.
|
||||||
|
|
||||||
@@ -192,7 +185,6 @@ class AgePieChart(PieWrapper):
|
|||||||
super().__init__(data=data, title="Âge")
|
super().__init__(data=data, title="Âge")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IndividuGroupeChart(PieWrapper):
|
class IndividuGroupeChart(PieWrapper):
|
||||||
|
|
||||||
def __init__(self, queryset):
|
def __init__(self, queryset):
|
||||||
@@ -257,7 +249,6 @@ class RencontreParMoisChart(ColumnWrapper):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def gen_heure_minute(_from, to):
|
def gen_heure_minute(_from, to):
|
||||||
start_hour = _from.hour
|
start_hour = _from.hour
|
||||||
stop_hour, stop_min = to.hour, to.minute
|
stop_hour, stop_min = to.hour, to.minute
|
||||||
@@ -335,4 +326,4 @@ class RencontreParLieuChart(PieWrapper):
|
|||||||
if self.queryset:
|
if self.queryset:
|
||||||
data += [(label, self.get_count_for_group(lieu_pks)) for label, lieu_pks in self.labels]
|
data += [(label, self.get_count_for_group(lieu_pks)) for label, lieu_pks in self.labels]
|
||||||
super().__init__(data=data,
|
super().__init__(data=data,
|
||||||
title="Fréquentation par lieu")
|
title="Fréquentation par lieu")
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.db.utils import OperationalError
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
from .models import FicheStatistique
|
from .models import FicheStatistique
|
||||||
|
|
||||||
class StatistiquesForm(forms.ModelForm):
|
|
||||||
|
|
||||||
|
class StatistiquesForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FicheStatistique
|
model = FicheStatistique
|
||||||
exclude = ["sujet"]
|
exclude = ["sujet"]
|
||||||
@@ -16,8 +15,10 @@ def get_year_range():
|
|||||||
).order_by(
|
).order_by(
|
||||||
'sujet__premiere_rencontre'
|
'sujet__premiere_rencontre'
|
||||||
)
|
)
|
||||||
year = lambda f: f.sujet.premiere_rencontre.year
|
|
||||||
|
def year(fiche):
|
||||||
|
return fiche.sujet.premiere_rencontre.year
|
||||||
|
|
||||||
# Need to call exists() in a try block
|
# Need to call exists() in a try block
|
||||||
# to avoid raising exception on first migration
|
# to avoid raising exception on first migration
|
||||||
try:
|
try:
|
||||||
@@ -30,6 +31,6 @@ def get_year_range():
|
|||||||
else:
|
else:
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
class SelectRangeForm(forms.Form):
|
|
||||||
|
|
||||||
|
class SelectRangeForm(forms.Form):
|
||||||
period = forms.ChoiceField(label="Année", choices=[(0, 'Tout')] + [(i, str(i)) for i in get_year_range()])
|
period = forms.ChoiceField(label="Année", choices=[(0, 'Tout')] + [(i, str(i)) for i in get_year_range()])
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ class FicheStatistique(models.Model):
|
|||||||
verbose_name = "Fiche statistique"
|
verbose_name = "Fiche statistique"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GroupeLieux(models.Model):
|
class GroupeLieux(models.Model):
|
||||||
label = models.CharField(max_length=128, primary_key=True)
|
label = models.CharField(max_length=128, primary_key=True)
|
||||||
lieux = models.ManyToManyField("maraudes.Lieu")
|
lieux = models.ManyToManyField("maraudes.Lieu")
|
||||||
@@ -103,4 +102,3 @@ class GroupeLieux(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Groupe de lieux"
|
verbose_name = "Groupe de lieux"
|
||||||
verbose_name_plural = "Groupes de lieux"
|
verbose_name_plural = "Groupes de lieux"
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ class ComparatifHeures(MultipleChartsView):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
#return self.get_observations_queryset()
|
# Return self.get_observations_queryset()
|
||||||
debut_essai = datetime.datetime(2017, 11, 23)
|
debut_essai = datetime.datetime(2017, 11, 23)
|
||||||
|
|
||||||
# Horaires démarrés le 23novembre 2017, calcul de la période effective d'application
|
# Horaires démarrés le 23novembre 2017, calcul de la période effective d'application
|
||||||
@@ -178,8 +178,9 @@ class ComparatifHeures(MultipleChartsView):
|
|||||||
print(debut_periode, fin_periode)
|
print(debut_periode, fin_periode)
|
||||||
return Observation.objects.filter(created_date__range=(debut_periode, fin_periode))
|
return Observation.objects.filter(created_date__range=(debut_periode, fin_periode))
|
||||||
|
|
||||||
|
|
||||||
# AjaxMixin
|
# AjaxMixin
|
||||||
class AjaxOrRedirectMixin(object):
|
class AjaxOrRedirectMixin:
|
||||||
""" For view that should be retrieved by Ajax only. If not,
|
""" For view that should be retrieved by Ajax only. If not,
|
||||||
redirects to the primary view where these are displayed """
|
redirects to the primary view where these are displayed """
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user