Skip to content

Commit

Permalink
wip speed up individual page loads
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Nov 11, 2024
1 parent 4fb6bd5 commit ff9b402
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dashboard/comprehensiveness.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file converts raw comprehensiveness data to percentages, and calculates averages.

from cache import json_cache
from data import get_publisher_stats, publisher_name, publishers_ordered_by_title

columns = {
Expand Down Expand Up @@ -191,6 +192,7 @@ def generate_row(publisher):
return row


@json_cache('comprehensiveness.json')
def table():
"""Generate comprehensiveness table data for every publisher and return as a generator object"""

Expand Down
3 changes: 3 additions & 0 deletions dashboard/forwardlooking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import datetime


from cache import json_cache
from data import get_publisher_stats, publisher_name, publishers_ordered_by_title

# Create a variable with the current year as an integer
Expand Down Expand Up @@ -100,6 +102,7 @@ def generate_row(publisher):
return row


@json_cache("forwardlooking.json")
def table():
"""Generate forward-looking table data for every publisher and return as a generator object"""

Expand Down
2 changes: 2 additions & 0 deletions dashboard/humanitarian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file builds a table to show humanitarian reporting for each publisher

import common
from cache import json_cache
from data import get_publisher_stats, publishers_ordered_by_title

# Set column groupings, to be displayed in the user output
Expand All @@ -16,6 +17,7 @@
]


@json_cache("humanitarian.json")
def table():
"""Generate data for the humanitarian table"""

Expand Down
2 changes: 2 additions & 0 deletions dashboard/summary_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import comprehensiveness
import forwardlooking
import timeliness
from cache import json_cache
from data import get_publisher_stats, publishers_ordered_by_title, secondary_publishers

# Set column groupings, to be displayed in the user output
Expand Down Expand Up @@ -34,6 +35,7 @@ def convert_to_float(x):
return 0


@json_cache("summary_stats.json")
def table():
"""Generate data for the publisher forward-looking table"""

Expand Down
2 changes: 1 addition & 1 deletion dashboard/templates/dates.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% for publisher_title,publisher in publishers_ordered_by_title %}
{% set publisher_stats = func.get_publisher_stats(publisher) %}
<tr>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[publisher]) }}">{{ publisher_title }}</a></td>
<td><a href="{% if publisher %}{{ url("dash-headlines-publisher-detail", args=[publisher]) }}{% endif %}">{{ publisher_title }}</a></td>
<td>{% if publisher_stats.date_extremes.min.overall %}{{ publisher_stats.date_extremes.min.overall }}{% endif %}</td>
<td>{% if publisher_stats.date_extremes.max.overall %}{{ publisher_stats.date_extremes.max.overall }}{% endif %}</td>
<td>{% if publisher_stats.date_extremes.max.by_type['start-actual'] %}{{ publisher_stats.date_extremes.max.by_type['start-actual'] }}{% endif %}</td>
Expand Down
5 changes: 3 additions & 2 deletions dashboard/templates/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ <h3 class="panel-title">File Sizes</h3>
<tbody>
{% for package, activities in current_stats.inverted_file.activities.items() %}
<tr>
<td class="break"><a href="{{ url("dash-headlines-publisher-detail", args=[func.dataset_to_publisher(package[:-4])]) }}">{{ publisher_name[func.dataset_to_publisher(package[:-4])] }}</a></td>
<td class="break"><a href="http://iatiregistry.org/dataset/{{ package[:-4] }}">{{ package[:-4] }}</a></td>
{% set publisher=func.dataset_to_publisher(package) %}
<td class="break"><a href="{% if publisher %}{{ url("dash-headlines-publisher-detail", args=[publisher]) }}{% endif %}">{{ publisher_name[func.dataset_to_publisher(package)] }}</a></td>
<td class="break"><a href="http://iatiregistry.org/dataset/{{ package }}">{{ package }}</a></td>
<td>{{ activities }}</td>
<td>{{ current_stats.inverted_file.organisations.get(package) }}</td>
<td data-bytes="{{ current_stats.inverted_file.file_size.get(package) }}">{{ current_stats.inverted_file.file_size.get(package)|filesizeformat }}</td>
Expand Down
2 changes: 1 addition & 1 deletion dashboard/templates/timeliness_timelag.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3 class="panel-title">Table of Time lag assessments</h3>
<tbody>
{% for publisher, publisher_title, per_month, assessment, hft in timeliness.publisher_timelag_sorted() %}
<tr>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{{ url('dash-headlines-publisher-detail', args=[publisher]) }}">{{ publisher_title }}</a></td>
<td style="border-right: 1px solid #ddd; border-left: 1px solid #ddd;"><a href="{% if publisher %}{{ url('dash-headlines-publisher-detail', args=[publisher]) }}{% endif %}">{{ publisher_title }}</a></td>
{% for month in timeliness.previous_months_reversed %}
<td {% if not per_month[month] %}class="text-muted"{% endif %}>{{ per_month[month] or 0 }}</td>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/templates/traceability.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% for publisher_title,publisher in publishers_ordered_by_title %}
{% set publisher_stats = func.get_publisher_stats(publisher) %}
<tr>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[publisher]) }}">{{ publisher_title }}</a></td>
<td><a href="{% if publisher %}{{ url("dash-headlines-publisher-detail", args=[publisher]) }}{% endif %}">{{ publisher_title }}</a></td>
<td>
{%- if publisher_stats.traceable_activities_by_publisher_id -%}
{{ '{:,}'.format(publisher_stats.traceable_activities_by_publisher_id) }}
Expand Down
10 changes: 6 additions & 4 deletions dashboard/templates/xml.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ <h3 class="panel-title">Files where XML is not well-formed</h3>
{% for dataset, invalid in current_stats.inverted_file.invalidxml.items() %}
{% if invalid %}
<tr>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[func.dataset_to_publisher(dataset[:-4])]) }}">{{ func.dataset_to_publisher(dataset[:-4]) }}</a></td>
<td><a href="http://iatiregistry.org/dataset/{{ dataset[:-4] }}">{{ dataset[:-4] }}</a></td>
{% set publisher=func.dataset_to_publisher(package) %}
<td><a href="{% if publisher %}{{ url("dash-headlines-publisher-detail", args=[publisher]) }}{% endif %}">{{ publisher }}</a></td>
<td><a href="http://iatiregistry.org/dataset/{{ dataset }}">{{ dataset }}</a></td>
</tr>
{% endif %}
{% endfor %}
Expand All @@ -55,8 +56,9 @@ <h3 class="panel-title">Files with non-standard roots</h3>
{% for dataset, nonstandard in current_stats.inverted_file.nonstandardroots.items() %}
{% if nonstandard %}
<tr>
<td><a href="{{ url('dash-headlines-publisher-detail', args=[func.dataset_to_publisher(dataset[:-4])]) }}">{{ func.dataset_to_publisher(dataset[:-4]) }}</a></td>
<td><a href="http://iatiregistry.org/dataset/{{ dataset[:-4] }}">{{ dataset[:-4] }}</a></td>
{% set publisher=func.dataset_to_publisher(package) %}
<td><a href="{% if publisher %}{{ url("dash-headlines-publisher-detail", args=[publisher]) }}{% endif %}">{{ publisher }}</a></td>
<td><a href="http://iatiregistry.org/dataset/{{ dataset }}">{{ dataset }}</a></td>
</tr>
{% endif %}
{% endfor %}
Expand Down
5 changes: 4 additions & 1 deletion dashboard/timeliness.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dateutil.relativedelta import relativedelta

import filepaths
from cache import json_cache
from data import JSONDir, get_publisher_stats, get_registry_id_matches, publisher_name


Expand Down Expand Up @@ -56,6 +57,7 @@ def previous_months_generator(d):
this_year = datetime.datetime.today().year


@json_cache("timeliness_frequency.json")
def publisher_frequency():
"""Generate the publisher frequency data"""

Expand Down Expand Up @@ -185,11 +187,12 @@ def first_published_band_index(first_published_band):
].index(first_published_band)


@json_cache("timeliness_timelag.json")
def publisher_timelag():
return [
(
publisher,
publisher_name.get(publisher),
publisher_name.get(publisher, ""),
agg["transaction_months_with_year"],
agg["timelag"],
has_future_transactions(publisher),
Expand Down
2 changes: 1 addition & 1 deletion dashboard/ui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = [".dashboard.iatistandard.org", "testserver", "localhost"]


# Application definition
Expand Down

0 comments on commit ff9b402

Please sign in to comment.