-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
497 lines (447 loc) · 17.5 KB
/
app.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
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from dash.dependencies import Input, Output
import plotly.graph_objs as go
df2 = pd.read_csv(
'Data_ DRC.1.csv')
df = pd.read_csv(
'Data_ DRC Ebola Outbreak, North Kivu and Ituri - MOH-By-Health-Zone.csv')
df_clean = df.drop(columns=['publication_date', 'report_date','country', 'province','health_zone', 'confirmed_cases_change',
'probable_cases_change', 'total_cases_change','confirmed_deaths_change', 'total_deaths_change','total_suspected_cases_change', 'source'])
def generate_table(dataframe):
dataframe = df[df.report_date.str.contains("2020-02-18")]
dataframe = dataframe.astype({"confirmed_cases": int,"probable_cases": int})
return html.Table(
# Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +
# Body
[html.Tr([
html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), len(dataframe)))]
)
def gen(selected_datte):
dataframe = df[df.report_date.str.contains(selected_datte)]
return dataframe['report_date'][dataframe.index[0]]
#load df ordered by month
def load_by_mounth():
df_m = []
for m in df['report_date'].unique():
df_m.append(m[:7])
output = []
for x in df_m:
if x not in output:
output.append(x)
return output
def result_over_time():
return (
dcc.Graph(
id='rot-graph',
figure={
'data': [
go.Scatter(
x = [ report_date for report_date in df["report_date"].unique() ],
y = [cc for cc in df["confirmed_deaths"]],
line = {"color": "rgb(53, 83, 255)"},
mode = "lines",
name = "confirmed_deaths"
),
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
)
def result_all_in_one():
filtered_df = df[df.report_date == "2020-02-18"]
return (
dcc.Graph(
id='life-exp-vs-gdp',
figure={
'data': [
go.Scatter(
x=filtered_df[filtered_df['province'] == i]['total_cases'],
y=filtered_df[filtered_df['province'] == i]['confirmed_deaths'],
text=filtered_df[filtered_df['province'] == i]['health_zone'],
mode='markers',
opacity=0.7,
marker={
'size': 15,
'line': {'width': 0.5, 'color': 'white'}
},
name=i
) for i in df.province.unique()
],
'layout': go.Layout(
xaxis={'type': 'log', 'title': 'GDP Per Capita'},
yaxis={'title': 'Life Expectancy'},
margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
legend={'x': 0, 'y': 1},
hovermode='closest'
)
}
)
)
def final_stat():
# filter df by province
#take the last day
filtered_df = df[df.report_date == df['report_date'][df.index[1]]]
filtered_df_nk = filtered_df[filtered_df.province == "North Kivu"]
filtered_df_it = filtered_df[filtered_df.province == "Ituri"]
filtered_df_sk = filtered_df[filtered_df.province == "South Kivu"]
# sum all confirmed case
filtered_df_nk = filtered_df_nk.astype({"confirmed_cases": int,"probable_cases": int
,"confirmed_deaths":int,"total_suspected_cases":int})
filtered_df_it = filtered_df_it.astype({"confirmed_cases": int,"probable_cases": int
,"confirmed_deaths":int,"total_suspected_cases":int})
filtered_df_sk = filtered_df_sk.astype({"confirmed_cases": int,"probable_cases": int
,"confirmed_deaths":int,"total_suspected_cases":int})
# sum all suspected cases
get_sum_nk = filtered_df_nk.sum(axis = 0, skipna = True)
get_sum_it = filtered_df_it.sum(axis = 0, skipna = True)
get_sum_sk = filtered_df_sk.sum(axis = 0, skipna = True)
# the same to sc
data_nk= [
{
'values': [get_sum_nk["confirmed_cases"], get_sum_nk["confirmed_deaths"]],
'type': 'pie',
'labels': ['N-K Confirmed cases ','N-K Confirmed deaths'],
'textfont': {'size': 20}
},
]
data_it = [
{
'values': [get_sum_it["confirmed_cases"], get_sum_it["confirmed_deaths"]],
'type': 'pie',
'labels': ['Ituri Confirmed cases','Ituri Confirmed deaths'],
'textfont': {'size': 20}
},
]
data_sk = [
{
'values': [get_sum_sk["confirmed_cases"], get_sum_sk["confirmed_deaths"]],
'type': 'pie',
'labels': ['S-K Confirmed cases','S-K Confirmed deaths'],
'textfont': {'size': 20}
},
]
return html.Div([
html.Div([
dcc.Graph(
id='graph1',
figure={
'data': data_nk,
'layout': {
'margin': {
'l': 30,
'r': 0,
'b': 30,
't': 0
},
'legend': {'x': 0, 'y': 1}
}
},
className="fleft mdl-cell--4-col"
),
]),
html.Div([
dcc.Graph(
id='graph2',
figure={
'data': data_it,
'layout': {
'margin': {
'l': 30,
'r': 0,
'b': 30,
't': 0
},
'legend': {'x': 0, 'y': 1}
}
},
className="fleft mdl-cell--4-col"
)
]),
html.Div([
dcc.Graph(
id='graph3',
figure={
'data': data_sk,
'layout': {
'margin': {
'l': 30,
'r': 0,
'b': 30,
't': 0
},
'legend': {'x': 0, 'y': 1}
}
},
className="fleft mdl-cell--4-col"
)
])
])
external_scripts = [
'assets/material.min.js'
]
# external CSS stylesheets
external_stylesheets = [
'assets/material.min.css',
'assets/bWLwgP.css'
]
app = dash.Dash(__name__,
external_scripts=external_scripts,
external_stylesheets=external_stylesheets)
server = app.server
app.layout = html.Div(children=[
# header
html.Div([
html.H3("The outbreak situation of the Ebola Virus (DRC) from 2018-08-04 to 2020-02-18",
className='mdl-layout--large-screen-only mdl-pad-to-bottom-50'),
],
className="m-botm-20 mdl-layout__header mdl-color--pink-800"
),
# generate_table(df),
html.Section([
html.Div([
dcc.Dropdown(
id='datte-id',
options=[{'label': report_date, 'value': report_date} for report_date in df['report_date'].unique()],
value='2020-02-18',
className="mdl-my-input"
),
html.Div(id='datte-div'),
html.P("\
Do you want to see what were the daily situation of health areas\
in terms of confirmed cases and confirmed death?",
className="mdl-my-input qst"
),
html.P("\
The first graph allows you to see the situation at a selected date. \
And to understand which health zone is most affected in terms of confirmed cases \
and death confirms cases.",
className="mdl-my-input"
),
],
className="mdl-card mdl-cell mdl-cell--12-col"
),
],
className="section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp my_section"
),
html.Section([
html.Div([
dcc.Dropdown(
id='province-idd-2',
options=[{'label': prvc, 'value': prvc} for prvc in df['province'].unique()],
value='North Kivu',
className="mdl-my-input"
),
html.Div(id='datte-divv-2'),
html.P("\
Do you want to see the number of people with Ebola per province per month,\
confirmed by the laboratory?",
className="mdl-my-input qst"
),
html.P("\
Here we see the cumulative confirmed cases,\
the monthly cumulative confirmed deaths,and\
the monthly cumulative suspected cases.",
className="mdl-my-input"
),
],
className="mdl-card mdl-cell mdl-cell--12-col"
),
],
className="section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp my_section"
),
html.Section([
html.Div([
final_stat(),
html.P("\
What is the proportion of confirmed deaths compared to confirmed cases?",
className="mdl-my-input qst"
),
html.P("\
On the left I show you the report of confirmed deaths compared to confirmed cases\
of the North Kivu province.\
On the middle I show you the report of confirmed deaths compared to confirmed \
cases of the Ituri province.\
On the right I show you the report of confirmed deaths compared to confirmed \
cases of the South Kivu province.\
Only you can see in which province has there been much more deaths \
compared to the confirmed cases.",
className="mdl-my-input"
),
],
className="mdl-card mdl-cell mdl-cell--12-col"
),
],
className="section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp my_section"
),
html.Section([
html.Div([
html.Div([
html.Div([
html.Label('Select one or more provinces'),
dcc.Dropdown(
id='province-column',
options=[{'label': i, 'value': i} for i in df["province"].unique()[0:]],
value= [i for i in df["province"].unique()[0:]],
multi=True
)
],
style={'width': '28%', 'float': 'left', 'display': 'inline-block','margin':'2%'}),
html.Div([
html.Label('Chose the first case'),
dcc.Dropdown(
id='1axis-column',
options=[{'label': column, 'value': column} for column in df_clean.columns],
value='confirmed_cases'
)
],style={'width': '28%', 'float': 'left', 'display': 'inline-block','margin':'2%'}),
html.Div([
html.Label('Chose the second case'),
dcc.Dropdown(
id='2axis-column',
options=[{'label': column, 'value': column} for column in df_clean.columns],
value='confirmed_deaths'
)
],style={'width': '28%', 'float': 'left', 'display': 'inline-block','margin':'2%'})
]),
html.Div(id='indicator-graphic'),
dcc.Slider(
id='month-slider',
min=0,
max=len(load_by_mounth())-2,
marks=[load_by_mounth_ for load_by_mounth_ in reversed(load_by_mounth())],
value=len(load_by_mounth())-2,
className='mdl-pad-to-bottom-30'
),
],
className="mdl-card mdl-cell mdl-cell--12-col"
),
],
className="section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp my_section"
),
],
className="mdl-color--grey-100")
# second question
@app.callback(
Output(component_id='datte-divv-2', component_property='children'),
[Input(component_id='province-idd-2', component_property='value')]
)
def suspected_over_confirmed(province):
filtered_df = df[df.province.str.match(province)]
#filtered_df = df
tab_sc = [] #suspected
tab_cc = [] # confirmed case
tab_cd = [] # death confirmed
for m in load_by_mounth():
# transform m to the last day of the month form
m_ = gen(m)
# filter result by the last day of the month
df_filtered_b_m = filtered_df[filtered_df.report_date.str.contains(m_)]
df_filtered_b_m = df_filtered_b_m.astype({"confirmed_cases": int,"probable_cases": int
,"confirmed_deaths":int,"total_suspected_cases":int})
# sum all suspected cases
get_sum = df_filtered_b_m.sum(axis = 0, skipna = True)
tab_cc.append(df_filtered_b_m.sum(axis = 0, skipna = True)["confirmed_cases"])
tab_sc.append(df_filtered_b_m.sum(axis = 0, skipna = True)["total_suspected_cases"])
tab_cd.append(df_filtered_b_m.sum(axis = 0, skipna = True)["confirmed_deaths"])
# sum all confirmed cases
return (
dcc.Graph(
id='s-c-by-cd-graph',
figure={
'data': [
{
'x': [load_by_mounth_ for load_by_mounth_ in load_by_mounth()],
'y': [cc for cc in tab_cc],
'type': 'lines', 'name': 'Confirmed cases'
},
{
'x': [load_by_mounth_ for load_by_mounth_ in load_by_mounth()],
'y': [cd for cd in tab_cd],
'type': 'lines', 'name': 'Confirmed deaths'
},
{
'x': [load_by_mounth_ for load_by_mounth_ in load_by_mounth()],
'y': [sc for sc in tab_sc],
'type': 'area', 'name': 'Suspected cases'
}
],
'layout': {
'title': 'DRC Ebola Outbreak, {} province'.format(province)
}
}
)
)
@app.callback(
Output(component_id='datte-div', component_property='children'),
[Input(component_id='datte-id', component_property='value')]
)
def selected_datte_output_div(selected_datte):
filtered_df = df[df.report_date == selected_datte]
return (
dcc.Graph(
id='cc-by-cd-graph',
figure={
'data': [
{
'x': [health_zone for health_zone in filtered_df["health_zone"]],
'y': [cc for cc in filtered_df["confirmed_cases"]],
'type': 'bar', 'name': 'Confirmed cases'
},
{
'x': [health_zone for health_zone in filtered_df["health_zone"]],
'y': [cc for cc in filtered_df["confirmed_deaths"]],
'type': 'bar', 'name': 'Confirmed deaths'
}
],
'layout': {
'title': 'DRC Ebola Outbreak, North Kivu, Ituri and south Kivu - MOH-By-Health-Zone on {}'.format(selected_datte)
}
}
)
)
@app.callback(
Output(component_id='indicator-graphic', component_property='children'),
[
Input(component_id='province-column', component_property='value'),
Input(component_id='1axis-column', component_property='value'),
Input(component_id='2axis-column', component_property='value'),
Input(component_id='month-slider', component_property='value')
]
)
def update_graph(province_clbk,axis_column1,axis_column2,month_slider):
filtered_df = df[df['province'].isin(province_clbk)]
# transform m to the last day of the month form
m_ = gen(load_by_mounth()[len(load_by_mounth()) - month_slider - 1])
# filter result by the last day of the month
filtered_df = filtered_df[filtered_df.report_date.str.contains(m_)]
return (
dcc.Graph(
id='cc-by-cd-graph1',
figure={
'data': [
{
'x': [health_zone for health_zone in filtered_df["health_zone"]],
'y': [cc for cc in filtered_df[""+axis_column1]],
'type': 'bar', 'name': ''+axis_column1
},
{
'x': [health_zone for health_zone in filtered_df["health_zone"]],
'y': [cc for cc in filtered_df[""+axis_column2]],
'type': 'bar', 'name': ''+axis_column2
}
],
'layout': {
'title': 'DRC Ebola Outbreak, North Kivu, Ituri and south Kivu - MOH-By-Health-Zone on {}'.format(province_clbk)
}
}
)
)
if __name__ == '__main__':
app.run_server(debug=True)