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 %}