Skip to content

Commit

Permalink
Update stats
Browse files Browse the repository at this point in the history
- include counties data for this year
  • Loading branch information
tudoramariei committed May 27, 2024
1 parent 51cbfde commit 6a3fc3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 14 additions & 4 deletions backend/donations/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}

Expand Down Expand Up @@ -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"))
Expand All @@ -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"]
}

Expand Down
12 changes: 8 additions & 4 deletions backend/templates/v1/admin2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="row">
<div class="col-xs-12">
<h3>General stats</h3>
<p><small>Generate la: {{ stats_dict["timestamp"] }} GMT</small></p>
<p><small>Generate la: {{ stats_dict["timestamp"].strftime("%Y-%m-%d %H:%M:%S") }} GMT</small></p>
<p>ONG-uri înregistrate: <strong>{{ stats_dict["all_time"]["ngos"] }}</strong></p>
<p>ONG-uri către care s-a donat: <strong>{{ stats_dict["all_time"]["ngos_with_forms"] }}</strong></p>
<p>Formulare completate: <strong>{{ stats_dict["all_time"]["forms"] }}</strong></p>
Expand Down Expand Up @@ -38,13 +38,14 @@ <h3>General stats</h3>

<div class="row">
<div class="col-xs-12">
<h4>Statistici pe judet (total)</h4>
<h4>Statistici pe județ</h4>
<table class="table">
<thead>
<tr>
<th>Judet/Sector</th>
<th>Județ/Sector</th>
<th>ONG-uri</th>
<th>Formulare</th>
<th>Formulare ({{ stats_dict["timestamp"].strftime("%Y") }})</th>
<th>Formulare (total)</th>
</tr>
</thead>
<tbody>
Expand All @@ -54,6 +55,9 @@ <h4>Statistici pe judet (total)</h4>
<td>
{{ value["ngos"] }}
</td>
<td>
{{ value["forms_current_year"] }}
</td>
<td>
{{ value["forms"] }}
</td>
Expand Down

0 comments on commit 6a3fc3c

Please sign in to comment.