Affichage de statistiques sur la page d'import

This commit is contained in:
Jean-Marie Favreau 2025-03-14 23:50:36 +01:00
parent 5dffc1f0b2
commit df18e9d88f
3 changed files with 331 additions and 262 deletions

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ from django.core.files.storage import default_storage
from django.core.mail import send_mail from django.core.mail import send_mail
from django.db import connection, models from django.db import connection, models
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 Lower from django.db.models.functions import Lower, ExtractDay
from django.template.defaultfilters import date as _date from django.template.defaultfilters import date as _date
from django.template.defaultfilters import slugify from django.template.defaultfilters import slugify
from django.template.loader import render_to_string from django.template.loader import render_to_string
@ -2728,6 +2728,27 @@ class RecurrentImport(models.Model):
else: else:
return None return None
def get_foresight_quality(self):
from statistics import median, mean, stdev
values = [
x["foresight"]
for x in Event.objects.filter(import_sources__contains=[self.source])
.annotate(foresight=ExtractDay(F("start_day") - F("created_date")))
.values("foresight")
]
if len(values) == 0:
return []
result = [
[_("minimum"), min(values)],
[_("maximum"), max(values)],
[_("mean"), round(mean(values), 2)],
[_("median"), median(values)],
]
if len(values) > 2:
result.append([_("standard deviation"), round(stdev(values), 2)])
return result
class BatchImportation(models.Model): class BatchImportation(models.Model):
class STATUS(models.TextChoices): class STATUS(models.TextChoices):

View File

@ -5,9 +5,11 @@
{% load cat_extra %} {% load cat_extra %}
{% load i18n %} {% load i18n %}
{% load utils_extra %} {% load utils_extra %}
{% load static %}
{% load tag_extra %} {% load tag_extra %}
{% block entete_header %} {% block entete_header %}
{% css_categories %} {% css_categories %}
<script src="{% static 'js/d3.v7.min.js' %}"></script>
{% endblock %} {% endblock %}
{% block sidemenu-bouton %} {% block sidemenu-bouton %}
<li> <li>
@ -83,6 +85,28 @@
</li> </li>
</ul> </ul>
</header> </header>
{% with object.get_foresight_quality as stat %}
{% if stat|length > 0 %}
<h2>Qualité de l'anticipation</h2>
<p>
On s'intéresse à la différence entre la date de publication d'un événement et la date effective de l'événement. Plus le nombre de jours qui les sépare est élevé, plus
la source anticipe ses événements, et peut être considérée comme une source fiable.
</p>
<table>
<thead>
<th class="label"></th>
{% for v in stat %}<th>{{ v.0 }}</th>{% endfor %}
</thead>
<tbody>
<tr>
<th class="label">Nb jours</th>
{% for v in stat %}<th>{{ v.1 }}</th>{% endfor %}
</tr>
</tbody>
</table>
{% endif %}
{% endwith %}
<h2>Liste des imports</h2>
{% include "agenda_culturel/batch-imports-inc.html" with objects=paginator_filter %} {% include "agenda_culturel/batch-imports-inc.html" with objects=paginator_filter %}
<footer> <footer>
<span>{% include "agenda_culturel/paginator.html" %}</span> <span>{% include "agenda_culturel/paginator.html" %}</span>