From dfa106b9ed87e6286a766d2554ed2c1673b00b5e Mon Sep 17 00:00:00 2001 From: "Alexis A." Date: Tue, 2 Jul 2024 09:13:27 +0200 Subject: [PATCH] feat(RNUPackagesProgressView): add elapsed time( --- project/views/RNUPackagesProgressView.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/project/views/RNUPackagesProgressView.py b/project/views/RNUPackagesProgressView.py index 0d0ec6b4f..626f46f13 100644 --- a/project/views/RNUPackagesProgressView.py +++ b/project/views/RNUPackagesProgressView.py @@ -1,5 +1,6 @@ from django.db.models import F, IntegerField, Sum from django.db.models.functions import Cast +from django.utils import timezone from rest_framework.response import Response from rest_framework.views import APIView @@ -18,8 +19,10 @@ def get(self, request): ) of_those_with_ocsge_count = of_those_with_ocsge.count() diagnostic_to_create_count = diagnostic_to_create.count() + mda_user = User.objects.get(email="rnu.package@mondiagartif.beta.gouv.fr") + diagnostic_created = Project.objects.filter( - user=User.objects.get(email="rnu.package@mondiagartif.beta.gouv.fr"), + user=mda_user, ) diagnostic_created_count = diagnostic_created.count() @@ -59,8 +62,14 @@ def get(self, request): ) ) + time_diff = timezone.now() - mda_user.date_joined + hours = time_diff.seconds // 3600 + minutes = (time_diff.seconds % 3600) // 60 + seconds = time_diff.seconds % 60 + return Response( { + "elapsed_time": f"{hours}h {minutes}m {seconds}s", "diagnostic_to_create_count": diagnostic_to_create_count, "of_those_with_ocsge_count": of_those_with_ocsge_count, "diagnostic_created_count": diagnostic_created_count,