-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlassa_server.py
118 lines (86 loc) · 4.05 KB
/
lassa_server.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
Author : Daniel Quezada
PI : Dr. Sampson Akwafuo
File Name : lassa_server.py
Date : 7/9/22
"""
from lassa_model import lassaModel
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.UserParam import UserSettableParameter
from mesa.visualization.modules import ChartModule
def agent_portrayal(agent):
# Susceptible human
portrayal = {"Shape":"hum-sc.png", "Filled":"true", "Layer":1}
# Infected human
if agent.is_human == True and agent.infected:
portrayal["Shape"] = "hum-if.png"
portrayal["Layer"] = 0
# Susceptible rat
elif agent.is_human == False and not agent.infected:
portrayal["Shape"] = "rat-sc.png"
portrayal["Layer"] = 2
# Infeceted rat
elif agent.is_human == False and agent.infected:
portrayal["Shape"] = "rat-if.png"
portrayal["Layer"] = 3
return portrayal
# Setups how the grid is going to be displayed on the webpage
grid = CanvasGrid(agent_portrayal, 50, 50, 1000, 1000)
# Creates our SIR graph
sir_graph = ChartModule(
[{"Label":"Susceptible Humans", "Color":"SlateBlue"},
{"Label":"Infected Humans", "Color":"Salmon"},
{"Label":"Removed Humans", "Color":"LimeGreen"}],
data_collector_name='datacollector', canvas_height=1000, canvas_width=1000
)
# Set up user sliders
num_human_slider = UserSettableParameter(
'slider', "Number of Human Agents", 300, 100, 500, 1)
num_rat_slider = UserSettableParameter(
'slider', "Number of Rat Agents", 500, 100, 700, 1)
adoption_rate_slider = UserSettableParameter(
'slider', "Human Agents that Adopt Intervention Strategies(%)", 0, 0, 100, 1)
hum_case_fatality_slider = UserSettableParameter(
'slider', "Probability that infected human dies every step", 1, 1, 10, 1)
hum_init_infection_slider = UserSettableParameter(
'slider', "Probability of Human Initial Infection(%)", 5, 1, 100, 1)
rat_init_infection_slider = UserSettableParameter(
'slider', "Probability of Rat Initial Infection(%)", 30, 1, 100, 1)
hum_transmissibility_slider = UserSettableParameter(
'slider', "Transmissibilty between H2H", 20, 1, 100, 1)
rat_transmissibility_slider = UserSettableParameter(
'slider', "Transmissibilty between R2H", 35, 1, 100, 1)
hum_level_of_movement_slider = UserSettableParameter(
'slider', "Level of movement for humans", 25, 1, 100, 1)
rat_level_of_movement_slider = UserSettableParameter(
'slider', "Level of movement for rats", 65, 1, 100, 1)
hum_contagious_period_slider = UserSettableParameter(
'slider', "Contagious period for humans(days)", 21, 7, 30, 1)
rat_contagious_period_slider = UserSettableParameter(
'slider', "Contagious period for rats(days)", 45, 21, 90, 1)
# Set up user checkboxes
hum_rodenticide_checkbox = UserSettableParameter(
'checkbox', "Humans that use rodenticide", value=False)
rat_trap_checkbox = UserSettableParameter(
'checkbox', "Humans that use rat traps", value=False)
server = ModularServer(lassaModel, [sir_graph, grid], "Intervention Strategies for the Control of Periodic Lassa Fever Outbreaks",
{
"N_humans": num_human_slider,
"N_rats": num_rat_slider,
"adoption_rate":adoption_rate_slider,
"hum_case_fatality":hum_case_fatality_slider,
"width":50,
"height":50,
"hum_init_infection": hum_init_infection_slider,
"rat_init_infection": rat_init_infection_slider,
"hum_transmissibility": hum_transmissibility_slider,
"rat_transmissibility": rat_transmissibility_slider,
"hum_level_of_movement": hum_level_of_movement_slider,
"rat_level_of_movement": rat_level_of_movement_slider,
"contagious_period_hum": hum_contagious_period_slider,
"contagious_period_rat": rat_contagious_period_slider,
"rodenticide": hum_rodenticide_checkbox,
"rat_trap": rat_trap_checkbox
}
)