From ddfe1584673ae9ba57e718c0cbae5866ef30e32d Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 29 Jun 2023 16:24:15 +0100 Subject: [PATCH] added report data --- .../templates/base/calculator.report.html.j2 | 16 ++++++++ caimira/models.py | 5 +-- .../tests/models/test_dynamic_population.py | 40 +++++++++++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/caimira/apps/templates/base/calculator.report.html.j2 b/caimira/apps/templates/base/calculator.report.html.j2 index 08a4596f..cdbd26d0 100644 --- a/caimira/apps/templates/base/calculator.report.html.j2 +++ b/caimira/apps/templates/base/calculator.report.html.j2 @@ -528,6 +528,19 @@
  • HEPA amount: {{ form.hepa_amount }} m³ / hour

  • {% endif %} +
  • From Fitting: + {% if form.ventilation_type == "from_fitting" %} + Yes + + + {% for ventilation in form.CO2_fitting_result['ventilation_values'] %} + + {% endfor %} +
    Ventilation value (ACH)
    {{ventilation}}
    + {% else %} + No

  • + {% endif %} +

    @@ -578,6 +591,9 @@ {% elif form.activity_type == "gym" %} Gym - For comparison only, all persons doing heavy physical exercise, breathing and not speaking. {% endif %} + {% if form.CO2_data_option %} +

    Exhalation rate from fitting algorithm - {{form.CO2_fitting_result['exhalation_rate'] | round(2, 'floor')}} m³/h

    + {% endif %}

    {% if form.short_range_option == "short_range_yes" %}
  • diff --git a/caimira/models.py b/caimira/models.py index 1d068088..a9f2c0ec 100644 --- a/caimira/models.py +++ b/caimira/models.py @@ -1578,10 +1578,7 @@ class ExposureModel: c_model.ventilation.air_exchange(c_model.room, time)) for time in c_model.state_change_times()))): raise ValueError("If the diameter is an array, none of the ventilation parameters " "or virus decay constant can be arrays at the same time.") - if not isinstance(self.exposed.number, int): - raise NotImplementedError("Cannot use dynamic occupancy for" - " the exposed population") - + @method_cache def population_state_change_times(self) -> typing.List[float]: """ diff --git a/caimira/tests/models/test_dynamic_population.py b/caimira/tests/models/test_dynamic_population.py index 4bca0f73..8fe6b891 100644 --- a/caimira/tests/models/test_dynamic_population.py +++ b/caimira/tests/models/test_dynamic_population.py @@ -27,7 +27,7 @@ def full_exposure_model(): short_range=(), exposed=models.Population( number=10, - presence=models.SpecificInterval(((8, 12), (13, 17), )), + presence=models.SpecificInterval(((8, 12), (13, 17), )), mask=models.Mask.types['No mask'], activity=models.Activity.types['Seated'], host_immunity=0. @@ -51,11 +51,37 @@ def baseline_infected_population_number(): @pytest.fixture -def dynamic_single_exposure_model(full_exposure_model, baseline_infected_population_number): +def baseline_exposed_population_number(): + return models.Population( + number=models.IntPiecewiseConstant( + (8, 12, 13, 17), (10, 0, 10)), + presence=None, + mask=models.Mask.types['No mask'], + activity=models.Activity.types['Seated'], + host_immunity=0., + ) + + +@pytest.fixture +def dynamic_infected_single_exposure_model(full_exposure_model, baseline_infected_population_number): return dc_utils.nested_replace(full_exposure_model, {'concentration_model.infected': baseline_infected_population_number, }) +@pytest.fixture +def dynamic_exposed_single_exposure_model(full_exposure_model, baseline_exposed_population_number): + return dc_utils.nested_replace(full_exposure_model, + {'exposed': baseline_exposed_population_number, }) + + +@pytest.fixture +def dynamic_population_exposure_model(full_exposure_model, baseline_infected_population_number ,baseline_exposed_population_number): + return dc_utils.nested_replace(full_exposure_model, { + 'concentration_model.infected': baseline_infected_population_number, + 'exposed': baseline_exposed_population_number, + }) + + @pytest.mark.parametrize( "time", [4., 8., 10., 12., 13., 14., 16., 20., 24.], @@ -91,16 +117,16 @@ def test_population_number(full_exposure_model: models.ExposureModel, [4., 8., 10., 12., 13., 14., 16., 20., 24.], ) def test_concentration_model_dynamic_population(full_exposure_model: models.ExposureModel, - dynamic_single_exposure_model: models.ExposureModel, + dynamic_infected_single_exposure_model: models.ExposureModel, time: float): - assert full_exposure_model.concentration(time) == dynamic_single_exposure_model.concentration(time) + assert full_exposure_model.concentration(time) == dynamic_infected_single_exposure_model.concentration(time) @pytest.mark.parametrize("number_of_infected",[1, 2, 3, 4, 5]) @pytest.mark.parametrize("time",[9., 12.5, 16.]) def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureModel, - dynamic_single_exposure_model: models.ExposureModel, + dynamic_infected_single_exposure_model: models.ExposureModel, time: float, number_of_infected: int): @@ -112,8 +138,8 @@ def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureM } ) - npt.assert_almost_equal(static_multiple_exposure_model.concentration(time), dynamic_single_exposure_model.concentration(time) * number_of_infected) - npt.assert_almost_equal(static_multiple_exposure_model.deposited_exposure(), dynamic_single_exposure_model.deposited_exposure() * number_of_infected) + npt.assert_almost_equal(static_multiple_exposure_model.concentration(time), dynamic_infected_single_exposure_model.concentration(time) * number_of_infected) + npt.assert_almost_equal(static_multiple_exposure_model.deposited_exposure(), dynamic_infected_single_exposure_model.deposited_exposure() * number_of_infected) @pytest.mark.parametrize(