From 23c89592445b248bf0cf0e3ef023a5b56bf03978 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 14 Dec 2023 14:49:06 +0100 Subject: [PATCH 1/2] fixed bug related to specific breaks --- caimira/apps/calculator/form_data.py | 10 +++++----- .../apps/calculator/test_specific_model_generator.py | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/caimira/apps/calculator/form_data.py b/caimira/apps/calculator/form_data.py index 9d82af94..bdf61d8b 100644 --- a/caimira/apps/calculator/form_data.py +++ b/caimira/apps/calculator/form_data.py @@ -227,15 +227,15 @@ def infected_coffee_break_times(self) -> models.BoundarySequence_t: else: return self.exposed_coffee_break_times() - def generate_specific_break_times(self, population_breaks) -> models.BoundarySequence_t: + def generate_specific_break_times(self, breaks_dict: dict, target: str) -> models.BoundarySequence_t: break_times = [] - for n in population_breaks: + for n in breaks_dict[f'{target}_breaks']: # Parse break times. begin = time_string_to_minutes(n["start_time"]) end = time_string_to_minutes(n["finish_time"]) for time in [begin, end]: # For a specific break, the infected and exposed presence is the same. - if not getattr(self, 'infected_start') < time < getattr(self, 'infected_finish'): + if not getattr(self, f'{target}_start') < time < getattr(self, f'{target}_finish'): raise ValueError(f'All breaks should be within the simulation time. Got {time_minutes_to_string(time)}.') break_times.append((begin, end)) @@ -335,7 +335,7 @@ def present_interval( def infected_present_interval(self) -> models.Interval: if self.specific_breaks != {}: # It means the breaks are specific and not predefined - breaks = self.generate_specific_break_times(self.specific_breaks['infected_breaks']) + breaks = self.generate_specific_break_times(breaks_dict=self.specific_breaks, target='exposed') else: breaks = self.infected_lunch_break_times() + self.infected_coffee_break_times() return self.present_interval( @@ -351,7 +351,7 @@ def population_present_interval(self) -> models.Interval: def exposed_present_interval(self) -> models.Interval: if self.specific_breaks != {}: # It means the breaks are specific and not predefined - breaks = self.generate_specific_break_times(self.specific_breaks['exposed_breaks']) + breaks = self.generate_specific_break_times(breaks_dict=self.specific_breaks, target='exposed') else: breaks = self.exposed_lunch_break_times() + self.exposed_coffee_break_times() return self.present_interval( diff --git a/caimira/tests/apps/calculator/test_specific_model_generator.py b/caimira/tests/apps/calculator/test_specific_model_generator.py index be2ac7dc..baeb2242 100644 --- a/caimira/tests/apps/calculator/test_specific_model_generator.py +++ b/caimira/tests/apps/calculator/test_specific_model_generator.py @@ -39,15 +39,16 @@ def test_specific_population_break_data_structure(population_break_input, error, @pytest.mark.parametrize( ["break_input", "error"], [ - [[{"start_time": "07:00", "finish_time": "11:00"}, ], "All breaks should be within the simulation time. Got 07:00."], - [[{"start_time": "17:00", "finish_time": "18:00"}, ], "All breaks should be within the simulation time. Got 18:00."], - [[{"start_time": "10:00", "finish_time": "11:00"}, {"start_time": "17:00", "finish_time": "20:00"}, ], "All breaks should be within the simulation time. Got 20:00."], - [[{"start_time": "08:00", "finish_time": "11:00"}, {"start_time": "14:00", "finish_time": "15:00"}, ], "All breaks should be within the simulation time. Got 08:00."], + [{'exposed_breaks': [{"start_time": "07:00", "finish_time": "11:00"}, ], 'infected_breaks': []}, "All breaks should be within the simulation time. Got 07:00."], + [{'exposed_breaks': [], 'infected_breaks': [{"start_time": "17:00", "finish_time": "18:00"}, ]}, "All breaks should be within the simulation time. Got 18:00."], + [{'exposed_breaks': [{"start_time": "10:00", "finish_time": "11:00"}, {"start_time": "17:00", "finish_time": "20:00"}, ], 'infected_breaks': []}, "All breaks should be within the simulation time. Got 20:00."], + [{'exposed_breaks': [], 'infected_breaks': [{"start_time": "08:00", "finish_time": "11:00"}, {"start_time": "14:00", "finish_time": "15:00"}, ]}, "All breaks should be within the simulation time. Got 08:00."], ] ) def test_specific_break_time(break_input, error, baseline_form: model_generator.VirusFormData): with pytest.raises(ValueError, match=error): - baseline_form.generate_specific_break_times(break_input) + baseline_form.generate_specific_break_times(breaks_dict=break_input, target='exposed') + baseline_form.generate_specific_break_times(breaks_dict=break_input, target='infected') @pytest.mark.parametrize( From e0867f1b270756b8454208efff791a2451b6bc26 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 14 Dec 2023 14:49:28 +0100 Subject: [PATCH 2/2] updated minor version --- caimira/apps/calculator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 51cc1961..e7ba083c 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -37,7 +37,7 @@ # calculator version. If the calculator needs to make breaking changes (e.g. change # form attributes) then it can also increase its MAJOR version without needing to # increase the overall CAiMIRA version (found at ``caimira.__version__``). -__version__ = "4.14.1" +__version__ = "4.14.2" LOG = logging.getLogger(__name__)