-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.py
566 lines (520 loc) · 24.8 KB
/
tabs.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from datetime import date as dt
import server as sv
# Defines functions
#Figs to display
fig1 = sv.px.line(sv.df['Casos totales']).update_layout(title= "National cases",
yaxis_title='Number of National cases',
xaxis_title='Date')
fig2 = sv.px.line(sv.df_region_current_bypop['bypop']
).update_layout(title= "Regional cases",
yaxis_title='Number of Regional cases',
xaxis_title='Date')
fig3 = sv.px.line(sv.df_seird
).update_layout(title='SEIRD model real data',
yaxis_title='SEIRD cases',
xaxis_title='Date')
fig4 = sv.plotlyseirdgo(sv.t, sv.S, sv.E, sv.I, sv.R, sv.D)
# Main content one
main_content_one = dbc.Col([
dbc.Row([
dbc.Col(
dbc.FormGroup([
dbc.Label("Additional setup"),
html.Br(),
dbc.Checklist(
options=[
{"label": "per 1000 inhabitants", "value": 1},
{"label": "logarithmic scale", "value": 2},
{"label": "moving average", "value": 4, "disabled": False},
],
value=[],
id="national_switches_input",
switch=True,
),
]),style = {'display': 'inline-block'}),
]),
dbc.Row(dbc.Col(dcc.Graph(id='time_series_one', figure=fig1),width=12))],
width=8,
style = { "margin-left": "4rem",
"margin-right": "2rem",
"padding": "2rem 1rem"})
# Main content two
main_content_two = dbc.Col([
dbc.Row([
dbc.Col(
dbc.FormGroup(
[
dbc.Label("Additional setup"),
dbc.Checklist(
options=[
{"label": "per 1000 inhabitants", "value": 1},
{"label": "logarithmic scale", "value": 2},
{"label": "moving average", "value": 3, "disabled": True},
],
value=[],
# labelStyle={'display': 'inline-block'},
id="regional_switches_input",
switch=True,
),
],style = {'display': 'inline-block'})
),
dbc.Col(
dbc.FormGroup([
dbc.Label('Choose Regions'),
html.Br(),
dcc.Dropdown(
options=[
{'label': 'Arica y Parinacota', 'value': 'Arica y Parinacota'},
{'label': 'Tarapacá', 'value': 'Tarapaca'},
{'label': 'Antofagasta', 'value': 'Antofagasta'},
{'label': 'Atacama', 'value': 'Atacama'},
{'label': 'Coquimbo', 'value': 'Coquimbo'},
{'label': 'Valparaíso', 'value': 'Valparaiso'},
{'label': 'Metropolitana', 'value': 'Metropolitana'},
{'label': 'O’Higgins', 'value': 'Del Libertador General Bernardo O’Higgins'},
{'label': 'Maule', 'value': 'Maule'},
{'label': 'Ñuble', 'value': 'Nuble'},
{'label': 'Biobío', 'value': 'Biobio'},
{'label': 'Araucanía', 'value': 'La Araucania'},
{'label': 'Los Ríos', 'value': 'Los Rios'},
{'label': 'Los Lagos', 'value': 'Los Lagos'},
{'label': 'Aysén', 'value': 'Aysen'},
{'label': 'Magallanes', 'value': 'Magallanes y la Antartica'},
],
multi=True,
value=['Arica y Parinacota',
'Tarapaca',
'Antofagasta',
'Atacama',
'Coquimbo',
'Valparaiso',
'Metropolitana',
'Del Libertador General Bernardo O’Higgins',
'Maule',
'Nuble',
'Biobio',
'La Araucania',
'Los Rios',
'Los Lagos',
'Aysen',
'Magallanes y la Antartica'
],
id='regional_dropdown'
)
]), width=8
)
]),
dbc.Row(dbc.Col(dcc.Graph(id='time_series_two',figure=fig2),width=12))],
width=8,
style = {
"margin-left": "4rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
})
## Main content three
main_content_three = dbc.Col([
dbc.Row(dbc.Col(dcc.Graph(id='time_series_three',figure=fig3),width=12))
],
width=8,
style = {
"margin-left": "4rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
})
## Main content four
main_content_four = dbc.Col([
dbc.Row([
dbc.Col(
dbc.FormGroup([
dbc.Label('Choose a Region'),
html.Br(),
dcc.Dropdown(
options=[
{'label': 'Arica y Parinacota', 'value': 'Arica y Parinacota'},
{'label': 'Tarapacá', 'value': 'Tarapaca'},
{'label': 'Antofagasta', 'value': 'Antofagasta'},
{'label': 'Atacama', 'value': 'Atacama'},
{'label': 'Coquimbo', 'value': 'Coquimbo'},
{'label': 'Valparaíso', 'value': 'Valparaiso'},
{'label': 'Metropolitana', 'value': 'Metropolitana'},
{'label': 'O’Higgins', 'value': 'Del Libertador General Bernardo O’Higgins'},
{'label': 'Maule', 'value': 'Maule'},
{'label': 'Ñuble', 'value': 'Nuble'},
{'label': 'Biobío', 'value': 'Biobio'},
{'label': 'Araucanía', 'value': 'La Araucania'},
{'label': 'Los Ríos', 'value': 'Los Rios'},
{'label': 'Los Lagos', 'value': 'Los Lagos'},
{'label': 'Aysén', 'value': 'Aysen'},
{'label': 'Magallanes', 'value': 'Magallanes y la Antartica'},
],
multi=False,
value='Valparaiso',
id='seird_regional_dropdown'
)
]), width=4
),
dbc.Col(
dbc.FormGroup([
dbc.Label('Choose a City'),
html.Br(),
dcc.Dropdown(
options= [{'label': 'Zapallar', 'value': 'Zapallar'}],
multi=False,
value=['Zapallar'],
id='seird_city_dropdown'
)
]), width=4
),
dbc.Col(
dbc.FormGroup([
dbc.Label('Date of first infection'),
html.Br(),
dcc.DatePickerSingle(
day_size=30, # how big the date picker appears
display_format="YYYY-MM-DD",
date='2020-01-01',
min_date_allowed=dt(2020, 1, 1),
max_date_allowed=dt.today(),
initial_visible_month=dt(2020, 1, 15),
placeholder="test",
id='seirdmo_daypicker',
)
]), width=4
),
]),
dbc.Row(dbc.Col(dcc.Graph(id='time_series_four',figure=fig4), width=12))],
width=8,
style = {
"margin-left": "4rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
})
## Tab 1
tab_1 = dbc.Row([
dbc.Col(
html.Div([
html.P("Select variables to display", className="lead"),
html.Br(),
dbc.FormGroup([
dbc.Label('Choose data to display'),
html.Br(),
dcc.Dropdown(
options=[
{'label': 'Total cases', 'value': 'Casos totales'},
{'label': 'Daily cases', 'value': 'Casos nuevos totales'},
{'label': 'Active cases', 'value': 'Casos activos'},
{'label': 'Deaths', 'value': 'Fallecidos'},
{'label': 'Recovered', 'value': 'recovered'},
# {'label': 'Total PCR exams', 'value': 'pcr'},
],
multi=True,
value='Casos totales',
id= 'national_dropdown',
)
]),
dbc.FormGroup([
dbc.Label('Choose a date'),
html.Br(),
dcc.DatePickerRange(
id='national_datepicker',
start_date=dt(2020, 1, 1),
end_date=dt.today(),
display_format="YYYY-MM-DD",
end_date_placeholder_text='Select a date!',
day_size = 30
)
]),
dbc.Button("Apply", id="submit_button_state_one",
color="primary", block=True)
]),
width=3,
style= {
"margin-left": "2rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
"left":0,
"top": 0,
"bottom": 0,
}
), main_content_one
])
## Tab 2
tab_2 = dbc.Row([
dbc.Col(
html.Div([
dbc.FormGroup([
dbc.Label('Choose a date'),
html.Br(),
dcc.DatePickerRange(
start_date=dt(2020, 1, 1),
end_date=dt.today(),
display_format="YYYY-MM-DD",
end_date_placeholder_text='Select a date!',
id='regional_datepicker',
day_size = 30
)
]),
dbc.FormGroup([
dbc.Label('Choose data to display'),
html.Br(),
dcc.Dropdown(
options=[
{'label': 'Total cases', 'value': 'total'},
{'label': 'Active cases', 'value': 'active'},
{'label': 'Deaths', 'value': 'deaths'},
{'label': 'Critical cases', 'value': 'uci'},
{'label': 'Total PCR exams', 'value': 'pcr'},
],
multi=False,
value='active',
id='regional_cases'
)
]),
dbc.Button("Apply", id="submit_button_state_two",
color="primary", block=True)
]),
width=3,
style= {
"margin-left": "2rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
"left":0,
"top": 0,
"bottom": 0,
}
),
main_content_two
]),
## Tab 3
tab_3 = dbc.Row([
dbc.Col(
html.Div([
dbc.FormGroup([
dbc.Label('Choose data to display'),
html.Br(),
dcc.Dropdown(
options=[
{'label': 'Susceptible', 'value': 'Susceptible'},
{'label': 'Exposed', 'value': 'Exposed'},
{'label': 'Infectious', 'value': 'Infectious'},
{'label': 'Recovered', 'value': 'Recovered'},
{'label': 'Dead', 'value': 'Dead'},
],
multi=True,
value=['Susceptible','Exposed','Infectious','Recovered','Dead'],
id="seird_dropdown",
)
]),
dbc.FormGroup([
dbc.Label('Choose a date'),
html.Br(),
dcc.DatePickerRange(
start_date=dt(2020, 3, 2),
end_date=dt.today(),
display_format="YYYY-MM-DD",
end_date_placeholder_text='Select a date!',
id='seird_datepicker',
day_size = 30
)
]),
dbc.Button("Apply", id="submit_button_state_three",
color="primary", block=True)
]),
width=3,
style= {
"margin-left": "2rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
"left":0,
"top": 0,
"bottom": 0,
}
),
main_content_three
])
## Tab 4
tab_4 = dbc.Row([
dbc.Col(
html.Div([
dbc.Row([
dbc.Col([
dbc.Label("Days to predict"),
dbc.Input(
id="seirdmo_days_today", type="number", placeholder="initial_cases",
min=0, max=1_000, step=1, value=700,
)])
]),
dbc.Row([
dbc.Col([
dbc.Label("Initial Cases"),
dbc.Input(
id="seirdmo_initial_cases", type="number", placeholder="initial_cases",
min=0, max=1_000_000, step=1, value=10,
)]),
dbc.Col([
dbc.Label("Initial Deaths"),
dbc.Input(
id="seirdmo_initial_deaths", type="number", placeholder="initial_deaths",
min=0, max=1_000_000, step=1, value=0,
)]),
]),
dbc.Row([
dbc.Col([
dbc.Label("Initial Exposed"),
dbc.Input(
id="seirdmo_initial_exposed", type="number", placeholder="initial_exposed",
min=0, max=1_000_000, step=1, value=0,
)]),
dbc.Col([
dbc.Label("Initial Recovered"),
dbc.Input(
id="seirdmo_initial_recovered", type="number", placeholder="initial_recovered",
min=0, max=1_000_000, step=1, value=0,
)]),
]),
dbc.FormGroup([
dbc.Label("Population"),
dbc.Input(
id="seirdmo_population", type="number", placeholder="population",
min=1_000, max=1_000_000_000, step=1_000, value=18_300_000,
)
]),
dbc.Row([
dbc.Col([
dbc.Label('ICU beds per 1K people'),
dbc.Input(
id="seirdmo_icu_beds", type="number", placeholder="ICU Beds per 1000",
min=0.0, max=100.0, step=0.1, value=34.0,
),
]),
dbc.Col([
dbc.Label('PCR tests per 1K people'),
dbc.Input(
id="seirdmo_pcr", type="number", placeholder="PCR per 1000",
min=0.0, max=100.0, step=0.1, value=34.0,
),
]),
]),
dbc.FormGroup([
dbc.Label('Probability of going to ICU when infected (%)'),
html.Br(),
dcc.Slider(
id='seirdmo_p_I_to_C',
min=0.1,
max=100.0,
step=0.1,
value=20.0,
tooltip={'always_visible': False, "placement": "bottom"}
),
]),
dbc.FormGroup([
dbc.Label('Probability of dying in ICU (%)'),
dcc.Slider(
id='seirdmo_p_C_to_D',
min=0.1,
max=100.0,
step=0.1,
value=5.0,
tooltip={'always_visible': False, "placement": "bottom"}
),
]),
dbc.FormGroup([
dbc.Label('Reproduction rate (R) over time'),
dcc.Slider(
id='seirdmo_r0_slider',
min=0.1,
max=10.0,
step=0.1,
value=2.0,
tooltip={'always_visible': False, "placement": "bottom"}
),
]),
dbc.Button("Apply", id="submit_button_state_four",
color="primary", block=True)
]),
width=3,
style= {
"margin-left": "2rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
"left":0,
"top": 0,
"bottom": 0,
}
),
main_content_four
])
## Tab 5
tab_5 = dbc.Row([
dbc.Col(# first, a jumbotron for the description and title
dbc.Jumbotron(
[
dbc.Container(
[
html.H1("Compartmentalisation", className="display-3"),
html.P(
"SEIRD model explanation",
className="lead",
),
html.Hr(className="my-2"),
dcc.Markdown('''
We separate population into several compartments, for example:
- N: Total population
- S: Susceptible (can still be infected, “healthy”)
- E: Exposed (contracted the disease but is not yet infective)
- I: Infected (active cases)
- R: Recovered (assuming were already infected and can't get infected again)
- D: Dead (passed away from the disease)
Additional variables need to be used, such as:
- β (“beta”): the expected amount of people an infected person infects per day. For example, with a probability of 10% than 10 people will infect 1 person per day (10% · 10 = 1)
- D: delay in number of days that an infected person has to spread the disease
- γ: it's the rate of recovery, or the proportion of infected recovering per day γ:1/D
- R₀: this is the basic reproduction number R₀, which is the total number of people an infected person infects. R₀: β · D. Hence R₀: β / γ
- ρ rate at which people die (e.g. when it takes 6 days to die, ρ will be 1/6)
- α: probability of going from infected to recovered and from infected to dead
'''
)
],
fluid=True,
)
],
fluid=True,
className="jumbotron bg-white text-dark"
),
),
dbc.Col(# first, a jumbotron for the description and title
dbc.Jumbotron(
[
dbc.Container(
[
html.H1("Formulas", className="display-3"),
html.P(
"Calculates SEIRD model change over time",
className="lead",
),
html.Hr(className="my-2"),
dcc.Markdown('''
### Susceptible:
∂S ⁄ ∂t = -β · I · S ⁄ N
### Exposed:
∂E ⁄ ∂t = β · I · S ⁄ N - δ · E
### Infectious:
∂I ⁄ ∂t = δ · E -(1-α) · γ · I -α · ρ · I
### Recovered:
∂R ⁄ ∂t = (1-α) · γ · I
### Dead:
∂R ⁄ ∂t = α · ρ · I
'''
)
],
fluid=True,
)
],
fluid=True,
className="jumbotron bg-white text-dark"
),
)
])