Resolved conflicts in report.html.j2

This commit is contained in:
gaazzopa 2020-12-09 18:39:01 +01:00
parent f173fd504b
commit be557c7665
2 changed files with 29 additions and 29 deletions

View file

@ -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

View file

@ -61,33 +61,8 @@
Sliding / Side-Hung</p></li>
{% endif %}
<li><p class="data_subtext">Opening distance: {{ form.opening_distance }} m</p></li>
<li><p class="data_subtext">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 %}
</p></li>
<li><p class="data_subtext">Windows open: {{ form.windows_duration | readable_minutes}}
every {{ form.windows_frequency | readable_minutes}}</p></li>
</ul>
<p class="data_subtext data_italic">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.</p>
{% else %}
@ -197,7 +172,7 @@
{% for repeat_event in repeated_events %}
<tr>
<td>{{ repeat_event.repeats }}</td>
<td>{{ repeat_event.probability_of_infection | int_format }}%</td>
<td>{{ repeat_event.probability_of_infection | non_zero_percentage }}</td>
<td style="text-align:right">{{ repeat_event.expected_new_cases | float_format }}</td>
</tr>
{% endfor %}
@ -220,7 +195,7 @@
{% for scenario_name, scenario_stats in alternative_scenarios.stats.items() %}
<tr>
<td>{{ scenario_name }}</td>
<td>{{ scenario_stats.probability_of_infection | int_format }}%</td>
<td>{{ scenario_stats.probability_of_infection | non_zero_percentage }}</td>
<td style="text-align:right">{{ scenario_stats.expected_new_cases | float_format }}</td>
</tr>
{% endfor %}