Skip to content

Commit

Permalink
Adjusting YES/NO metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Ederporto committed Oct 20, 2023
1 parent 6effd6e commit c39b2d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions metrics/templates/metrics/list_metrics_per_project.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ <h2 id="{{ project_key }}">{{ project_value.project }}</h2>
<tr>
<th scope="row">{{ metric_key }}</th>
<td>{{ metric_value.title }}<br><small>({% translate numeric_key %})</small></td>
<td>{{ numeric_value.done }}</td>
<td>{{ numeric_value.goal }}</td>
<td>{{ numeric_value.done|bool_yesno }}</td>
<td>{{ numeric_value.goal|bool_yesno }}</td>
<td>
<button type="button" class="btn-round btn-{{ numeric_value.done|categorize:numeric_value.goal }}">
{{ numeric_value.done|perc:numeric_value.goal }}
Expand Down
10 changes: 10 additions & 0 deletions metrics/templatetags/metricstags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django import template
from django.utils.translation import gettext_lazy as _

register = template.Library()


Expand All @@ -16,3 +18,11 @@ def perc(a, b):
return "{:.0f}%".format(100*a/b, 1)
except:
return "-"


@register.filter
def bool_yesno(a):
if type(a) == bool:
return _("Yes") if a else _("No")
else:
return a
4 changes: 2 additions & 2 deletions metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_metrics_and_aggregate_per_project():
"Number of partnerships": metric.number_of_partnerships,
"Number of organizers": metric.number_of_organizers,
"Number of people reached through social media": metric.number_of_people_reached_through_social_media,
"Is complete": metric.boolean_type,
"Occurence": metric.boolean_type,
}
done = {
"Wikipedia": reports.aggregate(total=Sum(F("wikipedia_created") + F("wikipedia_edited")))["total"] or 0,
Expand All @@ -121,7 +121,7 @@ def get_metrics_and_aggregate_per_project():
"Number of partnerships": Partner.objects.filter(partners__in=reports).distinct().count() or 0,
"Number of organizers": Organizer.objects.filter(organizers__in=reports).distinct().count() or 0,
"Number of people reached through social media": reports.aggregate(total=Sum(F("number_of_people_reached_through_social_media")))["total"] or 0,
"Is complete": reports.filter(metrics_related__boolean_type=True).exists() or False,
"Occurence": reports.filter(metrics_related__boolean_type=True).exists() or False,
}

result_metrics = {key: {"goal": value, "done": done[key]} for key, value in goal.items() if value != 0}
Expand Down

0 comments on commit c39b2d0

Please sign in to comment.