Skip to content

Commit

Permalink
Merge branch 'bugfix/precise_breaks' into 'master'
Browse files Browse the repository at this point in the history
Fixed a bug related to the precise breaks

See merge request caimira/caimira!478
  • Loading branch information
lrdossan committed Dec 14, 2023
2 parents 18456f4 + e0867f1 commit 1ce1526
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion caimira/apps/calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
10 changes: 5 additions & 5 deletions caimira/apps/calculator/form_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions caimira/tests/apps/calculator/test_specific_model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1ce1526

Please sign in to comment.