diff --git a/maraudes/notes.py b/maraudes/notes.py index b6d5c75..2fda646 100644 --- a/maraudes/notes.py +++ b/maraudes/notes.py @@ -23,14 +23,14 @@ class Observation(Note): def note_labels(self): return [self.rencontre.lieu, self.rencontre.heure_debut] - def note_bg_colors(self): return ("info", "info") + def note_bg_colors(self): return "info", "info" class Appel(Note): entrant = models.BooleanField( "Appel entrant ?") def note_labels(self): return ["Reçu" if self.entrant else "Émis", self.created_by] - def note_bg_colors(self): return ("warning", "info") + def note_bg_colors(self): return "warning", "info" class Signalement(Note): @@ -38,5 +38,5 @@ class Signalement(Note): source = models.ForeignKey("utilisateurs.Organisme") def note_labels(self): return [self.source, self.created_by] - def note_bg_colors(self): return ('danger', 'info') + def note_bg_colors(self): return 'danger', 'info' diff --git a/statistiques/admin.py b/statistiques/admin.py index ec50db8..cf62d6d 100644 --- a/statistiques/admin.py +++ b/statistiques/admin.py @@ -1,4 +1,8 @@ from django.contrib import admin - +from .models import GroupeLieux # Register your models here. +@admin.register(GroupeLieux) +class GroupLieuxAdmin(admin.ModelAdmin): + model = GroupeLieux + filter_horizontal = ["lieux"] \ No newline at end of file diff --git a/statistiques/charts.py b/statistiques/charts.py index 7bea703..3c9134a 100644 --- a/statistiques/charts.py +++ b/statistiques/charts.py @@ -9,6 +9,7 @@ from graphos.sources.simple import SimpleDataSource from graphos.renderers import gchart from notes.models import Sujet +from .models import GroupeLieux NOM_MOIS = { 1: "Janvier", @@ -274,3 +275,24 @@ class RencontreParHeureChart(gchart.AreaChart): data[intervalle] += 1 return data + + +class RencontreParLieuChart(PieWrapper): + + @property + def labels(self): + for groupe_lieux in GroupeLieux.objects.all(): + yield (groupe_lieux.label, + tuple(groupe_lieux.lieux.values_list('pk', flat=True)) + ) + + def get_count_for_group(self, lieu_pks): + return self.queryset.filter(rencontre__lieu__pk__in=lieu_pks).count() + + def __init__(self, queryset): + self.queryset = queryset + data = [('Lieu de rencontre', 'Nombre de rencontres')] + if self.queryset: + data += [(label, self.get_count_for_group(lieu_pks)) for label, lieu_pks in self.labels] + super().__init__(data=data, + title="Fréquentation par lieu") \ No newline at end of file diff --git a/statistiques/models.py b/statistiques/models.py index 022a1f0..289fb5c 100644 --- a/statistiques/models.py +++ b/statistiques/models.py @@ -90,3 +90,17 @@ class FicheStatistique(models.Model): class Meta: verbose_name = "Fiche statistique" + + + +class GroupeLieux(models.Model): + label = models.CharField(max_length=128, primary_key=True) + lieux = models.ManyToManyField("maraudes.Lieu") + + def __str__(self): + return "" % (self.label, self.lieux.count()) + + class Meta: + verbose_name = "Groupe de lieux" + verbose_name_plural = "Groupes de lieux" + diff --git a/statistiques/views.py b/statistiques/views.py index 07f4abe..d4c1412 100644 --- a/statistiques/views.py +++ b/statistiques/views.py @@ -141,6 +141,7 @@ class FrequentationChartsView(MultipleChartsView): ('Par mois', charts.RencontreParMoisChart), ('Par heure', charts.RencontreParHeureChart), ('Par sujet', charts.RencontreParSujetChart), + ('Par lieu', charts.RencontreParLieuChart) ]) def get_queryset(self):