Skip to content

Commit

Permalink
refactor: Added summary stats, forward looking and humanitarian to stats
Browse files Browse the repository at this point in the history
Refactored the summary statistics, forward looking and humanitarian
pages in the publishing statistics section.  Refactored the templates,
completed the url routes, and wrote view functions.
  • Loading branch information
chrisarridge committed Nov 4, 2024
1 parent 71fd284 commit 4b6e5e1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
6 changes: 3 additions & 3 deletions dashboard/templates/forwardlooking.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% import '_partials/boxes.html' as boxes %}
{% import '_partials/boxes.html' as boxes with context %}
{% block content %}
<ul class="list-inline" style="padding: 1em">
<li><a href="#h_table">Table</a></li>
Expand All @@ -20,7 +20,7 @@
<div class="panel panel-default" id="h_table">

<div class="panel-heading">
<span class="pull-right"><a href="{{ url_for('static', filename='forwardlooking.csv') }}">(This table as CSV)</a></span>
<span class="pull-right"><a href="{{ static('data/csv/forwardlooking.csv') }}">(This table as CSV)</a></span>
<h3 class="panel-title">Activities with Forward Looking Budget Allocations</h3>
</div>

Expand Down Expand Up @@ -61,7 +61,7 @@ <h3 class="panel-title">Activities with Forward Looking Budget Allocations</h3>
<tbody>
{% for row in forwardlooking.table() %}
<tr>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url_for('publisher', publisher=row.publisher) }}">{{ row.publisher_title }}</a></td>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url('dash-headlines-publisher-detail', args=[row.publisher]) }}">{{ row.publisher_title }}</a></td>

{% for column in row.year_columns %}
{% for year in forwardlooking.years %}
Expand Down
8 changes: 4 additions & 4 deletions dashboard/templates/humanitarian.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% import '_partials/boxes.html' as boxes %}
{% import '_partials/boxes.html' as boxes with context %}
{% block content %}

<ul class="list-inline" style="padding: 1em">
Expand All @@ -10,15 +10,15 @@

<div class="panel panel-default" id="h_table">
<div class="panel-heading">
<span class="pull-right"><a href="{{ url_for('static', filename='humanitarian.csv') }}">(This table as CSV)</a></span>
<span class="pull-right"><a href="{{ static('data/csv/humanitarian.csv') }}">(This table as CSV)</a></span>
<h3 class="panel-title">Humanitarian</h3>
</div>


<div class="panel-body">
<p>This table assesses the extent to which IATI publishers are reporting on humanitarian attributes.</p>

<p>The statistics on this page do not form part of the <a href="{{ url_for('basic_page', page_name='summary_stats') }}">Summary Statstics</a>.</p>
<p>The statistics on this page do not form part of the <a href="{{ url('dash-publishingstats-summarystats') }}">Summary Statstics</a>.</p>

{% include '_partials/tablesorter_instructions.html' %}
</div>
Expand All @@ -35,7 +35,7 @@ <h3 class="panel-title">Humanitarian</h3>
<tbody>
{% for row in humanitarian.table() %}
<tr>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url_for('publisher', publisher=row.publisher) }}">{{ row.publisher_title }}</a></td>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url('dash-headlines-publisher-detail', args=[row.publisher]) }}">{{ row.publisher_title }}</a></td>
{% for column_slug, _ in humanitarian.columns %}
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;">
{%- if column_slug == 'publisher_type' -%}
Expand Down
16 changes: 8 additions & 8 deletions dashboard/templates/summary_stats.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% import '_partials/boxes.html' as boxes %}
{% import '_partials/boxes.html' as boxes with context %}
{% block content %}

<ul class="list-inline" style="padding: 1em">
Expand All @@ -12,7 +12,7 @@

<div class="panel panel-default" id="h_table">
<div class="panel-heading">
<span class="pull-right"><a href="{{ url_for('static', filename='summary_stats.csv') }}">(This table as CSV)</a></span>
<span class="pull-right"><a href="{{ static('data/csv/summary_stats.csv') }}">(This table as CSV)</a></span>
<h3 class="panel-title">Summary Statistics</h3>
</div>

Expand All @@ -37,7 +37,7 @@ <h3 class="panel-title">Summary Statistics</h3>
<tbody>
{% for row in summary_stats.table() %}
<tr>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url_for('publisher', publisher=row.publisher) }}">{{ row.publisher_title }}</a></td>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url('dash-headlines-publisher-detail', args=[row.publisher]) }}">{{ row.publisher_title }}</a></td>
{% for column_slug, column_header in summary_stats.columns %}
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;">{% if column_slug == "publisher_type" %}{{ row[column_slug] }}{% else %}{{ row[column_slug] | round_nicely }}{% endif %}</th>
{% endfor %}
Expand All @@ -55,10 +55,10 @@ <h3 class="panel-title">Narrative</h3>
</div>
<div class="panel-body">
<h4>Timeliness</h5>
<p>This is calculated by scoring the assessments made on the <a href="{{ url_for('basic_page', page_name='timeliness') }}">
frequency</a> and <a href="{{ url_for('basic_page', page_name='timeliness_timelag') }}">timelag</a> pages on a scale of
<p>This is calculated by scoring the assessments made on the <a href="{{ url('dash-publishingstats-timeliness') }}">
frequency</a> and <a href="{{ url('dash-publishingstats-timeliness-timelag') }}">timelag</a> pages on a scale of
0 to 4 (as below), dividing the sum of the two scores by 8, and expressing the result as
a percentage. The methodology used in making the assesments is detailed on the <a href="{{ url_for('basic_page', page_name='timeliness') }}">frequency</a> and <a href="{{ url_for('basic_page', page_name='timeliness_timelag') }}">timelag</a> pages.
a percentage. The methodology used in making the assesments is detailed on the <a href="{{ url('dash-publishingstats-timeliness') }}">frequency</a> and <a href="{{ url('dash-publishingstats-timeliness-timelag') }}">timelag</a> pages.
</p>

<table class="table table-striped">
Expand Down Expand Up @@ -118,12 +118,12 @@ <h4>Timeliness</h5>

<h4>Forward looking</h4>
<p>The average percentage of current activities with budgets for each of the years {{ current_year }} - {{ current_year + 2 }}.
The component values and a detailed methodology are displayed on the <a href="{{ url_for('basic_page', page_name='forwardlooking') }}">forward looking</a> page.
The component values and a detailed methodology are displayed on the <a href="{{ url('dash-publishingstats-forwardlooking') }}">forward looking</a> page.
</p>


<h4>Comprehensiveness</h4>
<p>The average of <a href="{{ url_for('basic_page', page_name='comprehensiveness') }}">comprehensiveness</a> averages for core, financials and value-added. The core average has a double-weighting.</p>
<p>The average of <a href="{{ url('dash-publishingstats-comprehensiveness') }}">comprehensiveness</a> averages for core, financials and value-added. The core average has a double-weighting.</p>


<h4>Score</h4>
Expand Down
6 changes: 3 additions & 3 deletions dashboard/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
# Publishing statistics pages.
path('publishing-statistics/timeliness', ui.views.pubstats_timeliness, name="dash-publishingstats-timeliness"),
path('publishing-statistics/timeliness-timelag', ui.views.pubstats_timeliness_timelag, name="dash-publishingstats-timeliness-timelag"),
path('publishing-statistics/forward-looking', lambda x: None, name="dash-publishingstats-forwardlooking"),
path('publishing-statistics/forward-looking', ui.views.pubstats_forwardlooking, name="dash-publishingstats-forwardlooking"),
path('publishing-statistics/comprehensiveness', ui.views.pubstats_comprehensiveness, name="dash-publishingstats-comprehensiveness"),
path('publishing-statistics/comprehensiveness/core', ui.views.pubstats_comprehensiveness_core, name="dash-publishingstats-comprehensiveness-core"),
path('publishing-statistics/comprehensiveness/financials', ui.views.pubstats_comprehensiveness_financials, name="dash-publishingstats-comprehensiveness-financials"),
path('publishing-statistics/comprehensiveness/value-added', ui.views.pubstats_comprehensiveness_valueadded, name="dash-publishingstats-comprehensiveness-valueadded"),
path('publishing-statistics/coverage', lambda x: None, name="dash-publishingstats-coverage"),
path('publishing-statistics/summary-statistics', lambda x: None, name="dash-publishingstats-summarystats"),
path('publishing-statistics/humanitarian-reporting', lambda x: None, name="dash-publishingstats-humanitarian"),
path('publishing-statistics/summary-statistics', ui.views.pubstats_summarystats, name="dash-publishingstats-summarystats"),
path('publishing-statistics/humanitarian-reporting', ui.views.pubstats_humanitarian, name="dash-publishingstats-humanitarian"),

# Redirects to support any users with bookmarks to pages on the old Dashboard.
# path('timeliness.html', redirect("dash-publishingstats-timeliness")),
Expand Down
31 changes: 31 additions & 0 deletions dashboard/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# so not sure where they should fit. I've not included them in the page_view_names so hopefully
# an exception will be raised if they are referenced somewhere.

import datetime
import dateutil.parser
import subprocess
import json
Expand All @@ -15,8 +16,11 @@

import comprehensiveness
import config
import forwardlooking
import humanitarian
import text
import timeliness
import summary_stats
import ui.template_funcs
import vars

Expand Down Expand Up @@ -160,6 +164,7 @@ def _make_context(page_name: str):
metadata=metadata,
slugs=slugs,
datetime_data=dateutil.parser.parse(metadata['created_at']).strftime('%-d %B %Y (at %H:%M %Z)'),
current_year=datetime.datetime.now(datetime.UTC).year,
stats_url='https://stats.codeforiati.org',
stats_gh_url=STATS_GH_URL,
commit_hash=COMMIT_HASH,
Expand Down Expand Up @@ -418,32 +423,58 @@ def pubstats_comprehensiveness(request):
context["comprehensiveness"] = comprehensiveness
return HttpResponse(template.render(context, request))


def pubstats_comprehensiveness_core(request):
template = loader.get_template("comprehensiveness_core.html")
context = _make_context("comprehensiveness")
context["comprehensiveness"] = comprehensiveness
return HttpResponse(template.render(context, request))


def pubstats_comprehensiveness_financials(request):
template = loader.get_template("comprehensiveness_financials.html")
context = _make_context("comprehensiveness")
context["comprehensiveness"] = comprehensiveness
return HttpResponse(template.render(context, request))


def pubstats_comprehensiveness_valueadded(request):
template = loader.get_template("comprehensiveness_valueadded.html")
context = _make_context("comprehensiveness")
context["comprehensiveness"] = comprehensiveness
return HttpResponse(template.render(context, request))


def pubstats_timeliness(request):
template = loader.get_template("timeliness.html")
context = _make_context("timeliness")
context["timeliness"] = timeliness
return HttpResponse(template.render(context, request))


def pubstats_timeliness_timelag(request):
template = loader.get_template("timeliness_timelag.html")
context = _make_context("timeliness")
context["timeliness"] = timeliness
return HttpResponse(template.render(context, request))


def pubstats_summarystats(request):
template = loader.get_template("summary_stats.html")
context = _make_context("summary_stats")
context["summary_stats"] = summary_stats
return HttpResponse(template.render(context, request))


def pubstats_forwardlooking(request):
template = loader.get_template("forwardlooking.html")
context = _make_context("forwardlooking")
context["forwardlooking"] = forwardlooking
return HttpResponse(template.render(context, request))


def pubstats_humanitarian(request):
template = loader.get_template("humanitarian.html")
context = _make_context("humanitarian")
context["humanitarian"] = humanitarian
return HttpResponse(template.render(context, request))

0 comments on commit 4b6e5e1

Please sign in to comment.