Ajout d'une synthèse par mois

This commit is contained in:
Jean-Marie Favreau 2025-03-04 23:10:32 +01:00
parent 8b20b9fbff
commit 8f752ae7f9
4 changed files with 45 additions and 6 deletions

View File

@ -25,6 +25,10 @@
<div class="large-table"> <div class="large-table">
<div id="cal-heatmap-startday"></div> <div id="cal-heatmap-startday"></div>
</div> </div>
<p>
On retrouve une synthèse par mois du tableau précédent, sous forme d'une moyenne du nombre d'événements par jour pour chaque mois.
</p>
{% include "agenda_culturel/statistics_per_month.html" with data=stats_months_by_startday %}
<h2>Par jour de création sur l'agenda</h2> <h2>Par jour de création sur l'agenda</h2>
<p> <p>
Pour chaque date, on retrouve le nombre d'événements qui ont été créé ce jour-là, par import automatique ou par création manuelle. Pour chaque date, on retrouve le nombre d'événements qui ont été créé ce jour-là, par import automatique ou par création manuelle.
@ -34,6 +38,10 @@
<div class="large-table"> <div class="large-table">
<div id="cal-heatmap-creation"></div> <div id="cal-heatmap-creation"></div>
</div> </div>
<p>
On retrouve une synthèse par mois du tableau précédent, sous forme d'une moyenne du nombre de création d'événements par jour pour chaque mois.
</p>
{% include "agenda_culturel/statistics_per_month.html" with data=stats_months_by_creation %}
<h2>Par ville</h2> <h2>Par ville</h2>
<p>Nombre d'événements référencés par ville.</p> <p>Nombre d'événements référencés par ville.</p>
<ul> <ul>

View File

@ -0,0 +1,15 @@
{% load utils_extra %}
<div class="large-table">
<table>
<thead>
<th class="label"></th>
{% for v in data %}<th>{{ v.month|date:"M Y" }}</th>{% endfor %}
</thead>
<tbody>
<tr>
<th class="label">Nb</th>
{% for v in data %}<th>{{ v.total|per_day:v.month }}</th>{% endfor %}
</tr>
</tbody>
</table>
</div>

View File

@ -1,4 +1,5 @@
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
import calendar
from string import ascii_uppercase as auc from string import ascii_uppercase as auc
from urllib.parse import urlparse from urllib.parse import urlparse
@ -224,3 +225,9 @@ def navigation_links(filter, category):
+ '">ce mois-ci</a></li>' + '">ce mois-ci</a></li>'
) )
return mark_safe(result) return mark_safe(result)
@register.filter
def per_day(nb, month):
weekday, number_of_days = calendar.monthrange(month.year, month.month)
return "%.1f" % (nb / number_of_days)

View File

@ -16,6 +16,7 @@ from django.core.cache import cache
from django.core.mail import mail_admins from django.core.mail import mail_admins
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import Count, F, Func, OuterRef, Q, Subquery from django.db.models import Count, F, Func, OuterRef, Q, Subquery
from django.db.models.functions import TruncMonth
from django.http import ( from django.http import (
Http404, Http404,
HttpResponse, HttpResponse,
@ -2674,6 +2675,7 @@ def view_tag(request, t, past=False):
def statistics(request): def statistics(request):
stats = {} stats = {}
stats_months = {}
first = {} first = {}
last = {} last = {}
@ -2702,12 +2704,17 @@ def statistics(request):
r += after * 7 r += after * 7
first[v] = (last[v] - timedelta(days=r)).replace(day=1) first[v] = (last[v] - timedelta(days=r)).replace(day=1)
stats[v] = ( ev_days = ev_published.annotate(day=F(v)).filter(
ev_published.annotate(day=F(v)) Q(day__lte=last[v]) & Q(day__gte=first[v])
.filter(Q(day__lte=last[v]) & Q(day__gte=first[v])) )
.values("day")
.annotate(total=Count("day")) stats[v] = ev_days.values("day").annotate(total=Count("day")).order_by("day")
.order_by("day")
stats_months[v] = (
ev_days.annotate(month=TruncMonth("day"))
.values("month")
.annotate(total=Count("month"))
.order_by("month")
) )
nb_by_city = ( nb_by_city = (
@ -2721,6 +2728,8 @@ def statistics(request):
context = { context = {
"stats_by_startday": stats["start_day"], "stats_by_startday": stats["start_day"],
"stats_by_creation": stats["created_date__date"], "stats_by_creation": stats["created_date__date"],
"stats_months_by_startday": stats_months["start_day"],
"stats_months_by_creation": stats_months["created_date__date"],
"first_by_startday": first["start_day"], "first_by_startday": first["start_day"],
"last_by_startday": last["start_day"], "last_by_startday": last["start_day"],
"first_by_creation": first["created_date__date"], "first_by_creation": first["created_date__date"],