-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
210 lines (200 loc) · 7.16 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
import dash
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_html_components as html
import reading
import drawing
import components
import loading
import RTCalculator
stats = reading.read_all()
region_stats = reading.read_regions()
loading.load()
try:
stats_slope = reading.read_slope()
except FileNotFoundError:
open("AppData/slope.json", 'w').close()
globalRT = RTCalculator.rki(loading.load_eigth_positive_cases(stats))
chart_1 = drawing.draw_chart_1(stats)
chart_2 = drawing.draw_chart_2(stats)
chart_3 = drawing.draw_chart_3(stats)
chart_4 = drawing.draw_chart_4(stats_slope)
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
app.title = 'Covid19 data analysis'
app.layout = html.Div(
children=[
html.H1(
children='Covid19 data analysis',
style={
'textAlign': 'center',
'margin-top': '2rem'
}
),
html.H6(
children='Stefano leggio',
style={
'textAlign': 'center',
}
),
dbc.Row(
dbc.Col(
[
html.H6(
children = "Dati del " + str(stats['time_ita'][len(stats['time_ita'])-1]),
style = {
'margin-top' : '3rem',
'margin-bottom' : '1.5rem'
}
),
dbc.Row(
[
dbc.Col(dbc.Card(components.card("Positivi su tamponi", str(stats["percetage_screening"]) + "%"), color="dark", inverse=True)),
dbc.Col(dbc.Card(components.card("Nuovi positivi", stats["last_positive_cases"]), color="dark", inverse=True)),
dbc.Col(dbc.Card(components.card("Nuovi pazienti ricoverati", stats["last_h_var"]), color="dark", inverse=True)),
dbc.Col(dbc.Card(components.card("Nuovi pazienti in terapia intensiva", stats["last_ic_var"]), color="dark", inverse=True)),
dbc.Col(dbc.Card(components.card("Indice RT", str(globalRT)), color="danger", inverse=True)),
],
className="mb-4",
),
]
),
style = {
'margin-top' : '5rem',
'margin-left' : '10rem',
'margin-right' : '10rem',
}
),
dbc.Row(
dbc.Col(
[
html.H6(
children = "Terapie intensive occupate (solo pazienti Covid)",
style = {
'margin-top' : '3rem',
'margin-bottom' : '1.5rem'
}
),
components.progress_bar_ic(stats)
]
),
style = {
'margin-left' : '10rem',
'margin-right' : '10rem',
}
),
html.Div(
children = [
dcc.Dropdown(
id= 'chart-dropdown',
options=[
{'label': 'Da inizio epidemia', 'value': 'GEN'},
{'label': 'Ultimi 30 giorni', 'value': 'LM'},
{'label': 'Ultimi 7 giorni', 'value': 'LW'},
{'label': 'Andamento derivate', 'value': 'DD'},
],
searchable=False,
value='GEN',
style = {
'width' : '20rem'
}
),
],
style = {
'padding-top' : '7rem',
'padding-left' : '15rem',
}
),
html.Div(
id = 'main-chart'
),
dbc.Row(
dbc.Col(
[
html.H6(
children = "Previsioni",
style = {
'margin-top' : '3rem',
'margin-bottom' : '1.5rem'
}
),
components.table()
]
),
style = {
'margin-top' : '5rem',
'margin-left' : '10rem',
'margin-right' : '10rem',
}
),
dbc.Row(
dbc.Col(
[
dcc.Dropdown(
id= 'datawrapper-dropdown',
options=[
{'label': 'Saturazione', 'value': 'STI'},
{'label': 'Capacità', 'value': 'CTI'},
{'label': 'Capacità su 100mila abitanti', 'value': 'GTI'},
],
searchable=False,
value='STI',
style = {
'width' : '20rem',
'margin-bottom': '2rem'
}
),
dbc.Button("Aggiorna", color="primary", id="update_dw", className="mr-1", style={"margin-bottom" : '2rem'}),
html.Div(
id = 'main-datawrapper'
),
html.Div(
id = "output_btn"
)
]
),
style = {
'margin-top' : '5rem',
'margin-left' : '10rem',
'margin-right' : '10rem',
}
)
]
)
@app.callback(
dash.dependencies.Output('main-chart', 'children'),
[dash.dependencies.Input('chart-dropdown', 'value')])
def update_output(value):
chart = chart_1
if value == "LM":
chart = chart_2
elif value == "LW":
chart = chart_3
elif value == "DD":
chart = chart_4
return dcc.Graph(
figure=chart,
style={
'margin-left' : '10rem',
'margin-right' : '10rem',
'height' : '50rem'
}
),
@app.callback(
dash.dependencies.Output('main-datawrapper', 'children'),
[dash.dependencies.Input('datawrapper-dropdown', 'value')])
def update_output(value):
if value == "CTI":
return html.Iframe(title="Capacità terapie intensive", style = {'height': '802px','min-width': '100%','border': 'none'}, src=f'https://datawrapper.dwcdn.net/2lDyq/')
if value == "STI":
return html.Iframe(title="Saturazione terapie intensive", style = {'height': '802px','min-width': '100%','border': 'none'}, src=f'https://datawrapper.dwcdn.net/n02gP/')
if value == "GTI":
return html.Iframe(title="Posti di terapia intensiva ogni 100mila abitanti", style = {'height': '802px','min-width': '100%','border': 'none'}, src=f'https://datawrapper.dwcdn.net/7qNQd/1/')
@app.callback(
dash.dependencies.Output("output_btn", "children"),
[dash.dependencies.Input("update_dw", 'n_clicks')]
)
def update_dw(n_clicks):
loading.load_capacity()
loading.load_saturation(region_stats)
if __name__ == '__main__':
app.run_server(debug=False)