From 04b8e91639ce7d364a7c5b8d65125087e0436a1c Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 17 May 2024 17:05:10 +0200 Subject: [PATCH] updated new cases method --- caimira/apps/calculator/report_generator.py | 2 +- .../apps/templates/base/calculator.report.html.j2 | 9 ++++----- .../apps/templates/cern/calculator.report.html.j2 | 4 ++-- caimira/models.py | 14 +++++++++----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/caimira/apps/calculator/report_generator.py b/caimira/apps/calculator/report_generator.py index fae89ef5..cf6ab070 100644 --- a/caimira/apps/calculator/report_generator.py +++ b/caimira/apps/calculator/report_generator.py @@ -431,7 +431,7 @@ def manufacture_alternative_scenarios(form: VirusFormData) -> typing.Dict[str, m scenarios['Neither ventilation nor masks'] = without_mask_or_vent.build_mc_model() else: - no_short_range_alternative = dataclass_utils.replace(form, short_range_interactions=[]) + no_short_range_alternative = dataclass_utils.replace(form, short_range_interactions=[], total_people=form.total_people - form.short_range_total_people) scenarios['Base scenario without short-range interactions'] = no_short_range_alternative.build_mc_model() return scenarios diff --git a/caimira/apps/templates/base/calculator.report.html.j2 b/caimira/apps/templates/base/calculator.report.html.j2 index bcf904b7..1c11b192 100644 --- a/caimira/apps/templates/base/calculator.report.html.j2 +++ b/caimira/apps/templates/base/calculator.report.html.j2 @@ -56,16 +56,15 @@
{% set long_range_prob_inf = prob_inf %} {% set long_range_expected_cases = expected_new_cases %} - {% set total_expected_new_cases = expected_new_cases %} {# Update values if short range option is "short_range_yes" #} {% if form.short_range_option == "short_range_yes" %} {% set scenario = alternative_scenarios.stats.values() | first %} {# Probability of infection values #} {% set long_range_prob_inf = scenario.probability_of_infection %} - {% set long_range_expected_cases = scenario.expected_new_cases %} {# Expected new case values #} - {% set total_expected_new_cases = scenario.expected_new_cases + expected_new_cases %} + {% set long_range_expected_cases = scenario.expected_new_cases %} + {% if form.exposure_option == 'p_probabilistic_exposure' %} {% set long_range_prob_probabilistic_exposure = scenario.prob_probabilistic_exposure %} {% endif %} @@ -134,12 +133,12 @@ {% block report_summary %}
{% if form.short_range_option == "short_range_yes" %}
{% endif %} {% block probabilistic_exposure_probability %} diff --git a/caimira/apps/templates/cern/calculator.report.html.j2 b/caimira/apps/templates/cern/calculator.report.html.j2 index d482b1dc..0e0a0175 100644 --- a/caimira/apps/templates/cern/calculator.report.html.j2 +++ b/caimira/apps/templates/cern/calculator.report.html.j2 @@ -70,7 +70,7 @@ {% if form.short_range_option == "short_range_yes" %}
@@ -84,7 +84,7 @@ {% endif %} diff --git a/caimira/models.py b/caimira/models.py index 389c082c..82387f58 100644 --- a/caimira/models.py +++ b/caimira/models.py @@ -1817,13 +1817,17 @@ class ExposureModel: "with dynamic occupancy") """ - The expect_new_cases should always take the long-range infection_probability and multiply by the occupants exposed to long-range. + The expected_new_cases has two different use case scenarios: + 1) Long-range only: take the infection_probability and multiply by the occupants exposed to long-range. + 2) Short- and long-range: take the infection_probability of long-range multiplied by the occupants exposed to long-range only, added + to the infection_probability of short- and long-range multiplied by the occupants exposed to short-range only. """ - # If short-range interaction are defined, the total exposed people - # is only those of the short-range interactions. - exposed = self.exposed_to_short_range if self.short_range != () else self.exposed.number - return self.infection_probability() * exposed / 100 + if self.short_range != (): + new_cases_long_range = nested_replace(self, {'short_range': (),}).infection_probability() * (self.exposed.number - self.exposed_to_short_range) + return (new_cases_long_range + (self.infection_probability() * self.exposed_to_short_range)) / 100 + + return self.infection_probability() * self.exposed.number / 100 def reproduction_number(self) -> _VectorisedFloat: """