Skip to content

Commit

Permalink
Add air pollution dataset to Area page
Browse files Browse the repository at this point in the history
This change includes an addition of a filter, which allows for rendering
of subscript written in shorthand
(https://pages.uoregon.edu/ncp/Courses/MathInPlainTextEmail.html).

Currently, this new filter only works if there is only one instance of
subscript, and that it's at the end of the string.
  • Loading branch information
alexander-griffen authored and struan committed Aug 14, 2023
1 parent 067b6bf commit 8243066
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
22 changes: 11 additions & 11 deletions hub/management/commands/import_air_quality_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ class Command(BaseCommand):
}

in_files = {
"pm__10": {
"pollutant": "PM_{10}",
"pm_10": {
"pollutant": "PM10",
"metric": "Annual mean",
"header_label": "pm102021g",
"comments": "Gravimetric units",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mappm102021g.csv",
},
"pm__2_5": {
"pollutant": "PM_{2.5}",
"pm_2_5": {
"pollutant": "PM2.5",
"metric": "Annual mean",
"header_label": "pm252021g",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mappm252021g.csv",
},
"no__2": {
"pollutant": "NO_2",
"no_2": {
"pollutant": "NO2",
"metric": "Annual mean",
"header_label": "no22021",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapno22021.csv",
},
"no__x": {
"pollutant": "NO_X",
"no_x": {
"pollutant": "NOx",
"metric": "Annual mean",
"header_label": "nox2021",
"comments": "µg m\u207B\u00B3 (NO\u2093 as NO\u2082)",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapnox2021.csv",
},
"so__2": {
"pollutant": "SO_2",
"so_2": {
"pollutant": "SO2",
"metric": "Annual mean",
"header_label": "so22021",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapso22021.csv",
Expand All @@ -70,7 +70,7 @@ class Command(BaseCommand):
"pollutant": "Ozone",
"metric": "DGT120",
"header_label": "dgt12021",
"comments": "metric is number of days on which the daily max 8-hr concentration is greater than 120 µg m\u207B\u00B3",
"comments": "number of days on which the daily max 8-hr concentration is greater than 120 µg m\u207B\u00B3",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapdgt12021.csv",
},
"benzene": {
Expand Down
24 changes: 24 additions & 0 deletions hub/templates/hub/area/_place_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ <h5>{{ category.name }}</h5>
{% endfor %}
</body>
</table>
{% elif category.name == 'Air pollution' %}
<table class="table mb-0">
<thead>
<tr>
<th scope="col">Pollutant</th>
<th scope="col">This area</th>
<th scope="col" class="text-muted">UK average</th>
</tr>
</thead>
<tbody>
{% for range in category.data %}
<tr>
<th>
{{ range.label|html_format_dataset_name|safe }}
{% if range.data_type.description %}
<small class="d-block mt-1 fs-8 fw-normal">{{ range.data_type.description|escape }}</small>
{% endif %}
</th>
<td>{{ range.value|floatformat }}%</td>
<td class="text-muted">{{ range.average|floatformat }}%</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
{% if category.data.is_number %}
<p class="card-text mb-0 display-6 lh-1 text-primary">{{ category.data.value|floatformat }}{% if category.data.is_percentage %}%{% endif %}</p>
Expand Down
13 changes: 13 additions & 0 deletions hub/templatetags/hub_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ def pending_account_requests(**kwargs):
userproperties__email_confirmed=True,
userproperties__account_confirmed=False,
).count()


@register.filter
@stringfilter
def html_format_dataset_name(value):
pollutants = {
"PM10": "PM<sub>10</sub>",
"PM2.5": "PM<sub>2.5</sub>",
"NO2": "NO<sub>2</sub>",
"NOx": "NO<sub>X</sub>",
"SO2": "SO<sub>2</sub>",
}
return pollutants.get(value, value)

0 comments on commit 8243066

Please sign in to comment.