8
8
import pandas as pd
9
9
import numpy as np
10
10
import streamlit as st
11
+ from datetime import timedelta
11
12
import plotly .graph_objects as go
12
13
from forecast import download_button
13
14
from get_data import get_curve
@@ -64,7 +65,8 @@ def plot_cases_canton(full_name_canton, canton):
64
65
65
66
last_date = df .index [- 1 ]
66
67
df = df ['2021-11-01' :]
67
- df = df .iloc [:- 3 ]
68
+
69
+ #df = df.iloc[:-3]
68
70
69
71
# computing the rolling average
70
72
m_movel = df .rolling (7 ).mean ().dropna ()
@@ -107,9 +109,9 @@ def get_hospCapacity(canton):
107
109
df = get_curve ('hospcapacity' , canton )
108
110
df = df .resample ('D' ).mean ()
109
111
df = df .sort_index ()
110
- df = df .iloc [:- 3 ]
112
+ # df = df.iloc[:-3]
111
113
df = df .fillna (0 )
112
- return df .Total_Covid19Patients [- 2 :].astype ('int' ), df .TotalPercent_Covid19Patients [- 2 :]
114
+ return df .total_covid19patients [- 2 :].astype ('int' ), df .totalpercent_covid19patients [- 2 :]
113
115
114
116
115
117
def plot_hosp_canton (full_name_canton , canton ):
@@ -126,7 +128,7 @@ def plot_hosp_canton(full_name_canton, canton):
126
128
df .sort_index (inplace = True )
127
129
df = df ['2021-11-01' :]
128
130
129
- df = df .iloc [:- 3 ]
131
+ # df = df.iloc[:-3]
130
132
131
133
# computing the rolling average
132
134
m_movel = df .rolling (7 ).mean ().dropna ()
@@ -188,15 +190,15 @@ def plot_predictions_canton(table_name, curve, canton, full_name_canton, title=N
188
190
y95 = df_val ['upper' ]
189
191
190
192
point = target .index [train_size ]
191
- min_val = min ([min (target ), np .nanmin (y50 )])
192
- max_val = max ([max (target ), np .nanmax (y50 )])
193
+ min_val = min ([min (target ), np .nanmin (y95 )])
194
+ max_val = max ([max (target ), np .nanmax (y95 )])
193
195
194
196
point_date = np .where (target .index == '2021-01-01' )
195
197
196
198
fig = go .Figure ()
197
199
198
200
# Dict with names for the curves
199
- names = {'hosp' : 'New Hospitalizations' , 'ICU_patients ' : 'Total ICU patients' ,
201
+ names = {'hosp' : 'New Hospitalizations' , 'icu_patients ' : 'Total ICU patients' ,
200
202
'total_hosp' : 'Total hospitalizations' }
201
203
202
204
if title == None :
@@ -267,11 +269,11 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
267
269
268
270
df_for .index = pd .to_datetime (df_for .date )
269
271
270
- curves = {'hosp' : 'hosp' , 'ICU_patients ' : 'hospcapacity' ,
272
+ curves = {'hosp' : 'hosp' , 'icu_patients ' : 'hospcapacity' ,
271
273
'total_hosp' : 'hospcapacity' }
272
274
ydata = get_curve (curves [curve ], canton )
273
275
ydata = ydata .resample ('D' ).mean ()
274
- ydata = ydata .iloc [:- 3 ]
276
+ # ydata = ydata.iloc[:-3]
275
277
ydata = ydata .rolling (7 ).mean ().dropna ()
276
278
277
279
dates_forecast = df_for .index
@@ -283,7 +285,7 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
283
285
284
286
# Dict with names for the curves
285
287
names = {'hosp' : 'Forecast New Hospitalizations' ,
286
- 'ICU_patients ' : 'Forecast Total ICU patients' ,
288
+ 'icu_patients ' : 'Forecast Total ICU patients' ,
287
289
'total_hosp' : 'Total hospitalizations' }
288
290
289
291
if title == None :
@@ -303,11 +305,14 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
303
305
# adding the traces
304
306
# Data
305
307
306
- column_curves = {'hosp' : 'entries' , 'ICU_patients' : 'ICU_Covid19Patients' ,
307
- 'total_hosp' : 'Total_Covid19Patients' }
308
+ column_curves = {'hosp' : 'entries' , 'icu_patients' : 'icu_covid19patients' ,
309
+ 'total_hosp' : 'total_covid19patients' }
310
+
311
+ min_data = min (ydata .index [- 1 ], df_for .index [0 ] - timedelta (days = 1 ))
312
+
308
313
309
314
fig .add_trace (go .Scatter (
310
- x = ydata .index [- 150 :], y = ydata [column_curves [curve ]][- 150 :], name = 'Data' , line = dict (color = 'black' )))
315
+ x = ydata .loc [: min_data ]. index [- 150 :], y = ydata . loc [: min_data ] [column_curves [curve ]][- 150 :], name = 'Data' , line = dict (color = 'black' )))
311
316
312
317
# Separation between data and forecast
313
318
fig .add_trace (go .Scatter (x = [df_for .index [0 ], df_for .index [0 ]], y = [min (min (ydata [column_curves [curve ]][- 150 :]), min (forecast95 )), max (
@@ -335,7 +340,7 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
335
340
336
341
# fig.write_image(path)
337
342
338
- del df_for ['index' ]
343
+ # del df_for['index']
339
344
df_for .index = pd .to_datetime (df_for .index )
340
345
df_for .index = df_for .index .date
341
346
df_for .reset_index (inplace = True )
@@ -427,7 +432,7 @@ def app():
427
432
''' )
428
433
429
434
fig_for , df_hosp = plot_forecast_canton (
430
- 'ml_for_hosp_all_cantons ' , canton = canton , curve = 'hosp' , full_name_canton = full_name_canton )
435
+ 'ngboost_forecast_hosp_d_results ' , canton = canton , curve = 'hosp' , full_name_canton = full_name_canton )
431
436
st .plotly_chart (fig_for , use_container_width = True )
432
437
filename = 'forecast_hosp.csv'
433
438
download_button_str = download_button (
@@ -436,7 +441,7 @@ def app():
436
441
st .markdown (download_button_str , unsafe_allow_html = True )
437
442
438
443
fig_total , df_total = plot_forecast_canton (
439
- 'ml_for_total_all_cantons ' , canton = canton , curve = 'total_hosp' , full_name_canton = full_name_canton )
444
+ 'ngboost_forecast_total_hosp_d_results ' , canton = canton , curve = 'total_hosp' , full_name_canton = full_name_canton )
440
445
st .plotly_chart (fig_total , use_container_width = True )
441
446
filename = 'forecast_total.csv'
442
447
download_button_str = download_button (
@@ -445,7 +450,7 @@ def app():
445
450
st .markdown (download_button_str , unsafe_allow_html = True )
446
451
447
452
fig_for_icu , df_icu = plot_forecast_canton (
448
- 'ml_for_icu_all_cantons ' , canton = canton , curve = 'ICU_patients ' , full_name_canton = full_name_canton )
453
+ 'ngboost_forecast_icu_patients_d_results ' , canton = canton , curve = 'icu_patients ' , full_name_canton = full_name_canton )
449
454
st .plotly_chart (fig_for_icu , use_container_width = True )
450
455
filename = 'forecast_icu.csv'
451
456
download_button_str = download_button (
@@ -460,7 +465,7 @@ def app():
460
465
461
466
''' )
462
467
fig_val = plot_predictions_canton (
463
- 'ml_val_hosp_all_cantons ' , curve = 'hosp' , canton = canton , full_name_canton = full_name_canton )
468
+ 'ngboost_validation_hosp_d_results ' , curve = 'hosp' , canton = canton , full_name_canton = full_name_canton )
464
469
465
470
st .plotly_chart (fig_val , use_container_width = True )
466
471
@@ -470,7 +475,7 @@ def app():
470
475
''' )
471
476
472
477
fig_val_total = plot_predictions_canton (
473
- 'ml_val_total_all_cantons ' , curve = 'total_hosp' , canton = canton , full_name_canton = full_name_canton )
478
+ 'ngboost_validation_total_hosp_d_results ' , curve = 'total_hosp' , canton = canton , full_name_canton = full_name_canton )
474
479
475
480
st .plotly_chart (fig_val_total , use_container_width = True )
476
481
@@ -480,6 +485,6 @@ def app():
480
485
''' )
481
486
482
487
fig_val_icu = plot_predictions_canton (
483
- 'ml_val_icu_all_cantons ' , curve = 'ICU_patients ' , canton = canton , full_name_canton = full_name_canton )
488
+ 'ngboost_validation_icu_patients_d_results ' , curve = 'icu_patients ' , canton = canton , full_name_canton = full_name_canton )
484
489
485
490
st .plotly_chart (fig_val_icu , use_container_width = True )
0 commit comments