Commit cea16a83 authored by Openscop's avatar Openscop

[+] [stat] Prendre en compte les nouvelles manifestations dans le calcul des statistiques

[f] [stat] Corriger erreur de calcul (création qui apparait en 2019)
parent 99022cc8
......@@ -67,17 +67,31 @@
</tr>
<tr>
<th>Nombre d'avis demandés</th>
{% for key, value in stat.count_avis_par_annee.items %}
{% for key, value in stat.nb_avis_par_annee.items %}
<td>{{ value }}</td>
{% endfor %}
<td class="table-info">{{ stat.count_avis }}</td>
<td class="table-info">{{ stat.nb_avis }}</td>
</tr>
<tr>
<th>Nombre de pré-avis demandés</th>
{% for key, value in stat.count_preavis_par_annee.items %}
{% for key, value in stat.nb_preavis_par_annee.items %}
<td>{{ value }}</td>
{% endfor %}
<td class="table-info">{{ stat.count_preavis }}</td>
<td class="table-info">{{ stat.nb_preavis }}</td>
</tr>
<tr>
<th>Nombre d'actions majeures réalisées par les utilisateurs</th>
{% for key, value in stat.nb_action_par_annee.items %}
<td>{{ value }}</td>
{% endfor %}
<td class="table-info">{{ stat.nb_action }}</td>
</tr>
<tr>
<th>Nombre de notifications envoyées par la plateforme</th>
{% for key, value in stat.nb_notification_par_annee.items %}
<td>{{ value }}</td>
{% endfor %}
<td class="table-info">{{ stat.nb_notification }}</td>
</tr>
</tbody>
</table>
......
......@@ -4,10 +4,14 @@ from django.contrib.sessions.models import Session
from django.db.models import Count
from django.utils import timezone
from core.models import User
from events.models import Manifestation
from agreements.models import Avis
from sub_agreements.models import PreAvis
from events.models import Manifestation as EventsManifestation
from evenements.models import Manif as EvenementManif
from agreements.models import Avis as AgreementsAvis
from sub_agreements.models import PreAvis as SubAgreementsPreAvis
from instructions.models import Avis as InstructionAvis
from instructions.models import PreAvis as InstructionPreAvis
from organisateurs.models import Organisateur
from notifications.models import Action, Notification
from collections import OrderedDict
......@@ -32,7 +36,7 @@ class Stat(TemplateView):
critere = kwargs.get('critere')
data = {}
for y in range(2014, timezone.now().year + 2):
filter = critere + "__contains"
filter = critere + "__year"
data[y] = liste.filter(**{filter: y}).count()
return OrderedDict(sorted(data.items(), key=lambda t: t[0]))
......@@ -43,16 +47,24 @@ class Stat(TemplateView):
stat['connected_user'] = self.get_current_users().count()
stat['nb_utilisateur'] = User.objects.count()
stat['nb_utilisateur_par_annee'] = self.count_by_year(liste = User.objects, critere = "date_joined")
stat['nb_utilisateur_par_annee'] = self.count_by_year(liste=User.objects, critere="date_joined")
stat['nb_organisateur'] = Organisateur.objects.count()
stat['nb_organisateur_par_annee'] = self.count_by_year(liste = Organisateur.objects, critere = "user__date_joined")
stat['nb_manif_prevue'] = Manifestation.objects.count()
stat['nb_manif_prevue_par_annee'] = self.count_by_year(liste = Manifestation.objects, critere = "begin_date")
stat['nb_manif_cree'] = Manifestation.objects.count()
stat['nb_manif_cree_par_annee'] = self.count_by_year(liste = Manifestation.objects, critere = "creation_date")
stat['nb_organisateur_par_annee'] = self.count_by_year(liste=Organisateur.objects, critere="user__date_joined")
stat['nb_manif_prevue'] = EventsManifestation.objects.count() + EvenementManif.objects.count()
# stat['nb_manif_prevue_par_annee'] = self.count_by_year(liste = EventsManifestation.objects, critere = "begin_date")
ancien = self.count_by_year(liste=EventsManifestation.objects, critere="begin_date")
nouveau = self.count_by_year(liste=EvenementManif.objects, critere="date_debut")
stat['nb_manif_prevue_par_annee'] = OrderedDict(
[(key, ancien[key] + nouveau[key]) for key in ancien.keys()])
stat['nb_manif_cree'] = EventsManifestation.objects.count() + EvenementManif.objects.count()
# stat['nb_manif_cree_par_annee'] = self.count_by_year(liste = EventsManifestation.objects, critere = "creation_date")
ancien = self.count_by_year(liste=EventsManifestation.objects, critere="creation_date")
nouveau = self.count_by_year(liste=EvenementManif.objects, critere="date_creation")
stat['nb_manif_cree_par_annee'] = OrderedDict(
[(key, ancien[key] + nouveau[key]) for key in ancien.keys()])
# Code commenté car execution très lente
# stat['nb_manif_validee'] = [m.processing() for m in Manifestation.objects.all()].count(True)
......@@ -61,17 +73,35 @@ class Stat(TemplateView):
# data[y] = [m.processing() for m in Manifestation.objects.filter(begin_date__contains=y).all()].count(True)
# stat['nb_manif_validee_par_annee'] = data
stat['nb_manif_une_commune'] = Manifestation.objects.annotate(nbr_cities=Count('crossed_cities')).filter(nbr_cities=1).count()
stat['nb_manif_une_commune_par_annee'] = self.count_by_year(liste = Manifestation.objects.annotate(nbr_cities=Count('crossed_cities')).filter(nbr_cities=1), critere = "begin_date")
stat['count_avis'] = Avis.objects.all().count()
stat['count_avis_par_annee'] = self.count_by_year(liste = Avis.objects, critere = "request_date")
stat['count_preavis'] = PreAvis.objects.count()
stat['count_preavis_par_annee'] = self.count_by_year(liste = PreAvis.objects, critere = "request_date")
stat['nb_manif_une_commune'] = EventsManifestation.objects.annotate(nbr_cities=Count('crossed_cities')).filter(
nbr_cities=1).count() + EvenementManif.objects.annotate(nbr_cities=Count('villes_traversees')).filter(
nbr_cities=1).count()
# stat['nb_manif_une_commune_par_annee'] = self.count_by_year(liste = EventsManifestation.objects.annotate(nbr_cities=Count('crossed_cities')).filter(nbr_cities=1), critere = "begin_date")
ancien = self.count_by_year(
liste=EventsManifestation.objects.annotate(nbr_cities=Count('crossed_cities')).filter(nbr_cities=1),
critere="begin_date")
nouveau = self.count_by_year(
liste=EvenementManif.objects.annotate(nbr_cities=Count('villes_traversees')).filter(nbr_cities=1),
critere="date_debut")
stat['nb_manif_une_commune_par_annee'] = OrderedDict(
[(key, ancien[key] + nouveau[key]) for key in ancien.keys()])
stat['nb_avis'] = AgreementsAvis.objects.count() + InstructionAvis.objects.count()
ancien = self.count_by_year(liste=AgreementsAvis.objects, critere="request_date")
nouveau = self.count_by_year(liste=InstructionAvis.objects, critere="date_demande")
stat['nb_avis_par_annee'] = OrderedDict([(key, ancien[key] + nouveau[key]) for key in ancien.keys()])
stat['nb_preavis'] = SubAgreementsPreAvis.objects.count() + InstructionPreAvis.objects.count()
ancien = self.count_by_year(liste=SubAgreementsPreAvis.objects, critere="request_date")
nouveau = self.count_by_year(liste=InstructionPreAvis.objects, critere="date_demande")
stat['nb_preavis_par_annee'] = OrderedDict([(key, ancien[key] + nouveau[key]) for key in ancien.keys()])
stat['nb_action'] = Action.objects.count()
stat['nb_action_par_annee'] = self.count_by_year(liste=Action.objects, critere="creation_date")
stat['nb_notification'] = Notification.objects.count()
stat['nb_notification_par_annee'] = self.count_by_year(liste=Notification.objects, critere="creation_date")
context = super().get_context_data(**kwargs)
context['stat'] = stat
return context
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment