From 6a3fc3caebf4ce4d062c898d5f6c69153d5ea20a Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Mon, 27 May 2024 12:37:28 +0300 Subject: [PATCH] Update stats - include counties data for this year --- backend/donations/views/admin.py | 18 ++++++++++++++---- backend/templates/v1/admin2/index.html | 12 ++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/backend/donations/views/admin.py b/backend/donations/views/admin.py index 2aecc5b2..f9aba350 100644 --- a/backend/donations/views/admin.py +++ b/backend/donations/views/admin.py @@ -38,9 +38,9 @@ def get(self, request, *args, **kwargs): @cache_decorator(timeout=settings.CACHE_TIMEOUT_TINY, cache_key="ADMIN_STATS") def collect_stats(self): return { - "timestamp": timezone.now().strftime("%Y-%m-%d %H:%M:%S"), + "timestamp": timezone.now(), "years": self.get_yearly_data(), - "counties": self.get_conties_data(), + "counties": self.get_counties_data(), "all_time": self.get_all_time_data(), } @@ -77,7 +77,7 @@ def get_yearly_data(): } @staticmethod - def get_conties_data(): + def get_counties_data(): ngos_by_county = { county_stats["county"]: county_stats["count"] for county_stats in Ngo.active.values("county").annotate(count=Count("id")) @@ -86,8 +86,18 @@ def get_conties_data(): county_stats["county"]: county_stats["count"] for county_stats in Donor.objects.values("county").annotate(count=Count("id")) } + donations_by_county_current_year = { + county_stats["county"]: county_stats["count"] + for county_stats in Donor.objects.filter(date_created__year=timezone.now().year) + .values("county") + .annotate(count=Count("id")) + } return { - county: {"ngos": ngos_by_county.get(county, 0), "forms": donations_by_county.get(county, 0)} + county: { + "ngos": ngos_by_county.get(county, 0), + "forms": donations_by_county.get(county, 0), + "forms_current_year": donations_by_county_current_year.get(county, 0), + } for county in settings.LIST_OF_COUNTIES + ["1", "2", "3", "4", "5", "6", "RO"] } diff --git a/backend/templates/v1/admin2/index.html b/backend/templates/v1/admin2/index.html index bdebbad3..6b5020ca 100644 --- a/backend/templates/v1/admin2/index.html +++ b/backend/templates/v1/admin2/index.html @@ -9,7 +9,7 @@

General stats

-

Generate la: {{ stats_dict["timestamp"] }} GMT

+

Generate la: {{ stats_dict["timestamp"].strftime("%Y-%m-%d %H:%M:%S") }} GMT

ONG-uri înregistrate: {{ stats_dict["all_time"]["ngos"] }}

ONG-uri către care s-a donat: {{ stats_dict["all_time"]["ngos_with_forms"] }}

Formulare completate: {{ stats_dict["all_time"]["forms"] }}

@@ -38,13 +38,14 @@

General stats

-

Statistici pe judet (total)

+

Statistici pe județ

- + - + + @@ -54,6 +55,9 @@

Statistici pe judet (total)

+
Judet/SectorJudeț/Sector ONG-uriFormulareFormulare ({{ stats_dict["timestamp"].strftime("%Y") }})Formulare (total)
{{ value["ngos"] }} + {{ value["forms_current_year"] }} + {{ value["forms"] }}