Bases: Event
This Event is used to set a specific incidence per region at some point in the code.
It can be used to correct, based on data, the current epidemiological state of the code.
The added infection types are sampled from the currrent ones.
Source code in june/event/incidence_setter.py
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 | class IncidenceSetter(Event):
"""This Event is used to set a specific incidence per region at some point in the code.
It can be used to correct, based on data, the current epidemiological state of the code.
The added infection types are sampled from the currrent ones.
"""
def __init__(
self,
start_time: Union[str, datetime.datetime],
end_time: Union[str, datetime.datetime],
incidence_per_region: Dict[str, float],
):
super().__init__(start_time=start_time, end_time=end_time)
self.incidence_per_region = incidence_per_region
def initialise(self, world):
"""
Args:
world:
"""
pass
def apply(self, world, simulator, activities=None, day_type=None):
"""
Args:
world:
simulator:
activities: (Default value = None)
day_type: (Default value = None)
"""
selectors = simulator.epidemiology.infection_selectors
for region in world.regions:
if region.name in self.incidence_per_region:
target_incidence = self.incidence_per_region[region.name]
people = region.people
infected_people = [person for person in people if person.infected]
incidence = len(infected_people) / len(people)
if incidence > target_incidence:
n_to_remove = int((incidence - target_incidence) * len(people))
to_cure = sample(infected_people, n_to_remove)
for person in to_cure:
person.infection = None
elif incidence < target_incidence:
n_to_add = int((target_incidence - incidence) * len(people))
to_infect = sample(people, k=2 * n_to_add)
infected = choices(infected_people, k=2 * n_to_add)
counter = 0
for person, infected_ref in zip(to_infect, infected):
if person.infected:
continue
counter += 1
selectors.infect_person_at_time(
person,
simulator.timer.now,
infected_ref.infection.infection_id(),
)
if counter == n_to_add:
break
|
apply(world, simulator, activities=None, day_type=None)
Parameters:
Name |
Type |
Description |
Default |
world
|
|
|
required
|
simulator
|
|
|
required
|
activities
|
|
|
None
|
day_type
|
|
|
None
|
Source code in june/event/incidence_setter.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 | def apply(self, world, simulator, activities=None, day_type=None):
"""
Args:
world:
simulator:
activities: (Default value = None)
day_type: (Default value = None)
"""
selectors = simulator.epidemiology.infection_selectors
for region in world.regions:
if region.name in self.incidence_per_region:
target_incidence = self.incidence_per_region[region.name]
people = region.people
infected_people = [person for person in people if person.infected]
incidence = len(infected_people) / len(people)
if incidence > target_incidence:
n_to_remove = int((incidence - target_incidence) * len(people))
to_cure = sample(infected_people, n_to_remove)
for person in to_cure:
person.infection = None
elif incidence < target_incidence:
n_to_add = int((target_incidence - incidence) * len(people))
to_infect = sample(people, k=2 * n_to_add)
infected = choices(infected_people, k=2 * n_to_add)
counter = 0
for person, infected_ref in zip(to_infect, infected):
if person.infected:
continue
counter += 1
selectors.infect_person_at_time(
person,
simulator.timer.now,
infected_ref.infection.infection_id(),
)
if counter == n_to_add:
break
|
initialise(world)
Parameters:
Name |
Type |
Description |
Default |
world
|
|
|
required
|
Source code in june/event/incidence_setter.py
| def initialise(self, world):
"""
Args:
world:
"""
pass
|