From be557c7665c3c5cb3d8d9f0785bc7f118ad51697 Mon Sep 17 00:00:00 2001
From: gaazzopa
Date: Wed, 9 Dec 2020 18:39:01 +0100
Subject: [PATCH] Resolved conflicts in report.html.j2
---
cara/apps/calculator/report_generator.py | 25 ++++++++++++++
cara/apps/calculator/templates/report.html.j2 | 33 +++----------------
2 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/cara/apps/calculator/report_generator.py b/cara/apps/calculator/report_generator.py
index 278a0a79..27abbf80 100644
--- a/cara/apps/calculator/report_generator.py
+++ b/cara/apps/calculator/report_generator.py
@@ -113,6 +113,29 @@ def minutes_to_time(minutes: int) -> str:
return f"{hour_string}:{minute_string}"
+def readable_minutes(minutes: int) -> str:
+
+ time = minutes
+ unit = " minute"
+ if time % 60 == 0:
+ time = minutes/60
+ unit = " hour"
+ if time != 1:
+ unit += "s"
+
+ if time.is_integer():
+ time = "{:0.0f}".format(time)
+ else:
+ time = "{0:.2f}".format(time)
+
+ return time + unit
+
+def non_zero_percentage (percentage: int) -> str:
+
+ if percentage < 0.01:
+ return "<0.01%"
+ else:
+ return "{:0.0f}%".format(percentage)
def manufacture_alternative_scenarios(form: FormData) -> typing.Dict[str, models.ExposureModel]:
scenarios = {}
@@ -223,6 +246,8 @@ def build_report(model: models.ExposureModel, form: FormData):
loader=jinja2.FileSystemLoader([cara_templates, calculator_templates]),
undefined=jinja2.StrictUndefined,
)
+ env.filters['non_zero_percentage'] = non_zero_percentage
+ env.filters['readable_minutes'] = readable_minutes
env.filters['minutes_to_time'] = minutes_to_time
env.filters['float_format'] = "{0:.2f}".format
env.filters['int_format'] = "{:0.0f}".format
diff --git a/cara/apps/calculator/templates/report.html.j2 b/cara/apps/calculator/templates/report.html.j2
index 37fbe14e..2f29d914 100644
--- a/cara/apps/calculator/templates/report.html.j2
+++ b/cara/apps/calculator/templates/report.html.j2
@@ -61,33 +61,8 @@
Sliding / Side-Hung
{% endif %}
Opening distance: {{ form.opening_distance }} m
- Windows open:
- {% if form.windows_open == "interval" %}
- {{ form.windows_open }}s of
- {% set windows_duration = form.windows_duration %}
- {% set unit = "minutes" %}
- {% if windows_duration % 60 == 0 %}
- {% set windows_duration = form.windows_duration / 60 %}
- {% set unit = "hours" %}
- {% endif %}
- {% if windows_duration.is_integer() %}
- {% set windows_duration = windows_duration | int_format %}
- {% endif %}
- {{ windows_duration }} {{ unit }} every
- {% set windows_frequency = form.windows_frequency %}
- {% set unit = "minutes" %}
- {% if windows_frequency % 60 == 0 %}
- {% set windows_frequency = form.windows_frequency / 60 %}
- {% set unit = "hours" %}
- {% endif %}
- {% if windows_frequency.is_integer() %}
- {% set windows_frequency = windows_frequency | int_format %}
- {% endif %}
- {{ windows_frequency }} {{ unit }}
- {% else %}
- {{ form.windows_open }}
- {% endif %}
-
+ Windows open: {{ form.windows_duration | readable_minutes}}
+ every {{ form.windows_frequency | readable_minutes}}
When using the natural ventilation option, air flows are calculated using averaged hourly temperatures for the Geneva region, based on historical data for the month selected.
{% else %}
@@ -197,7 +172,7 @@
{% for repeat_event in repeated_events %}
| {{ repeat_event.repeats }} |
- {{ repeat_event.probability_of_infection | int_format }}% |
+ {{ repeat_event.probability_of_infection | non_zero_percentage }} |
{{ repeat_event.expected_new_cases | float_format }} |
{% endfor %}
@@ -220,7 +195,7 @@
{% for scenario_name, scenario_stats in alternative_scenarios.stats.items() %}
| {{ scenario_name }} |
- {{ scenario_stats.probability_of_infection | int_format }}% |
+ {{ scenario_stats.probability_of_infection | non_zero_percentage }} |
{{ scenario_stats.expected_new_cases | float_format }} |
{% endfor %}