forked from wesdoyle/python_epidemic_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preventative_measures.py
52 lines (40 loc) · 1.42 KB
/
preventative_measures.py
1
2
3
4
5
6
7
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
import math
import random
from constants import PreventativeMeasure
class PreventativeMeasures:
"""
Represents a set of strategies for minimizing scope of infection
"""
def __init__(self, hosts, measures, vaccination_rate, percent):
self.hosts = hosts
self.measures = measures
self.vaccination_rate = vaccination_rate
self.percent = percent
def enact(self):
for measure in self.measures:
if measure is PreventativeMeasure.SHELTER_IN_PLACE:
self.shelter_in_place()
if measure is PreventativeMeasure.LIMIT_TRAVEL:
self.limit_travel()
if measure is PreventativeMeasure.VACCINATE_POP:
self.vaccinate_population()
def get_random_sample(self):
return random.sample(
self.hosts,
math.ceil(len(self.hosts) * self.percent)
)
def shelter_in_place(self):
for host in self.get_random_sample():
host.is_sheltering = True
def limit_travel(self):
for host in self.get_random_sample():
host.limit_travel = True
def vaccinate_population(self):
for host in self.get_random_sample():
host.vaccine = Vaccine(self.vaccination_rate)
class Vaccine:
"""
Represents a vaccine that prevents the infection in a receiving host
"""
def __init__(self, drip_rate):
self.drip_rate = drip_rate