Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add statisitics table to world map view #83

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/dash_app/templates/dash_app/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
{% plotly_header %}
{% endblock %}
{% block content %}
<h1>Reports</h1>
{% if title %}<h1>{{title}}</h1>{% endif %}
{% include 'common/tabs.html' %}
{% if dash_name %}{% plotly_direct name=dash_name %}{% endif %}
{% if table %}
<table class="table table-bordered">
<thead class="thead-light">
<tr>
{% for heading in table.headings %}
<th>{{heading}}</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for item in table.items %}
<tr>
{% for value in item %}
<td>{% if href %}<a href="{{href}}">{{value}}</a>{% else %}{{value}}{% endif %}</td>{% endfor %}
</tr>{% endfor %}
</tbody>
</table>
{% endif %}
{% plotly_footer %}
{% endblock %}
3 changes: 2 additions & 1 deletion app/dash_app/views/allevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def all_events(request):
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "All events"
}
)

Expand Down
3 changes: 2 additions & 1 deletion app/dash_app/views/demographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def demographic_report(request):
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "Demographic metrics"
}
)

Expand Down
3 changes: 2 additions & 1 deletion app/dash_app/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def event_report(request):
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "Event metrics"
}
)

Expand Down
3 changes: 2 additions & 1 deletion app/dash_app/views/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def impact_report(request):
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "Impact metrics"
}
)

Expand Down
3 changes: 2 additions & 1 deletion app/dash_app/views/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def quality_report(request):
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "Quality metrics"
}
)

Expand Down
50 changes: 47 additions & 3 deletions app/dash_app/views/worldmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from dash import html
import pandas as pd
import numpy as np
from django.db.models import Count, F
from metrics.models import Event, Node
from django.db.models import Count, F, Sum, Q
from metrics.models import Event, Quality, Impact, Demographic, Node

def get_event_data():
# Query database to get counts of events by country
Expand All @@ -23,6 +23,31 @@ def get_event_data():
final = pd.merge(df, temp, on='location_country')
return final, total_events


def get_general_statistics():
events_with_metrics = Event.objects.filter(quality__isnull=False)
metrics_count = {
"demographic_count": Demographic.objects.count(),
"impact_count": Impact.objects.count(),
"quality_count": Quality.objects.count(),
"events_count": Event.objects.all().count(),
"events_with_metrics_count": events_with_metrics.distinct().count(),
"events_with_metrics_participants": events_with_metrics.aggregate(sum=Sum("number_participants"))["sum"],
}
aggregates = Event.objects.all().aggregate(
complete_duration=Sum("duration"),
complete_participants=Sum("number_participants"),
complete_trainers=Sum("number_trainers")
)

percentage = int(100 * metrics_count["quality_count"] / aggregates["complete_participants"])
return {
**metrics_count,
**aggregates,
"response_percentage": f"{percentage}%"
}


def world_map(request):
app = DjangoDash("WorldMap")

Expand Down Expand Up @@ -72,11 +97,30 @@ def world_map(request):

dash_config = {"dash_name": "WorldMap"}

table_values = {
"Total number of events": "events_count",
"Total number of days of training": "complete_duration",
"Total number of participants": "complete_participants",
"Total number of trainers": "complete_trainers",
"Total number of feedback responses (quality metrics) received": "quality_count",
"Total number of events for which feedback (quality metrics) collected": "events_with_metrics_count",
"Percentage of participants who provided feedback (quality metrics) for events where feedback was collected": "response_percentage"
}
stats = get_general_statistics()

return render(
request,
'dash_app/template.html',
context={
**get_tabs(request),
**dash_config
**dash_config,
"title": "World map and statistics",
"table": {
"headings": ["Metric", "Value"],
"items": [
[key, stats[item]]
for key, item in table_values.items()
]
}
}
)