Skip to content

Commit f8dcb03

Browse files
Correct the name of the tables used in the dashboard (#16)
* 'Minor changes in the layout of the plots and in the texts' * Minor change to correct the end of the data lines in the forecast plots * Removed the line of the code that dropoed the last 3 days of data in the plots. * Correct the name of the tables used in the dashboard * Removed the SEIR predictions and made a minor updated in the plots of validation figures * Solved conflicts
1 parent 9d3d528 commit f8dcb03

File tree

3 files changed

+89
-224
lines changed

3 files changed

+89
-224
lines changed

for_other_cantons.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas as pd
99
import numpy as np
1010
import streamlit as st
11+
from datetime import timedelta
1112
import plotly.graph_objects as go
1213
from forecast import download_button
1314
from get_data import get_curve
@@ -64,7 +65,8 @@ def plot_cases_canton(full_name_canton, canton):
6465

6566
last_date = df.index[-1]
6667
df = df['2021-11-01':]
67-
df = df.iloc[:-3]
68+
69+
#df = df.iloc[:-3]
6870

6971
# computing the rolling average
7072
m_movel = df.rolling(7).mean().dropna()
@@ -107,9 +109,9 @@ def get_hospCapacity(canton):
107109
df = get_curve('hospcapacity', canton)
108110
df = df.resample('D').mean()
109111
df = df.sort_index()
110-
df = df.iloc[:-3]
112+
#df = df.iloc[:-3]
111113
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:]
113115

114116

115117
def plot_hosp_canton(full_name_canton, canton):
@@ -126,7 +128,7 @@ def plot_hosp_canton(full_name_canton, canton):
126128
df.sort_index(inplace=True)
127129
df = df['2021-11-01':]
128130

129-
df = df.iloc[:-3]
131+
#df = df.iloc[:-3]
130132

131133
# computing the rolling average
132134
m_movel = df.rolling(7).mean().dropna()
@@ -188,15 +190,15 @@ def plot_predictions_canton(table_name, curve, canton, full_name_canton, title=N
188190
y95 = df_val['upper']
189191

190192
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)])
193195

194196
point_date = np.where(target.index == '2021-01-01')
195197

196198
fig = go.Figure()
197199

198200
# 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',
200202
'total_hosp': 'Total hospitalizations'}
201203

202204
if title == None:
@@ -267,11 +269,11 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
267269

268270
df_for.index = pd.to_datetime(df_for.date)
269271

270-
curves = {'hosp': 'hosp', 'ICU_patients': 'hospcapacity',
272+
curves = {'hosp': 'hosp', 'icu_patients': 'hospcapacity',
271273
'total_hosp': 'hospcapacity'}
272274
ydata = get_curve(curves[curve], canton)
273275
ydata = ydata.resample('D').mean()
274-
ydata = ydata.iloc[:-3]
276+
#ydata = ydata.iloc[:-3]
275277
ydata = ydata.rolling(7).mean().dropna()
276278

277279
dates_forecast = df_for.index
@@ -283,7 +285,7 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
283285

284286
# Dict with names for the curves
285287
names = {'hosp': 'Forecast New Hospitalizations',
286-
'ICU_patients': 'Forecast Total ICU patients',
288+
'icu_patients': 'Forecast Total ICU patients',
287289
'total_hosp': 'Total hospitalizations'}
288290

289291
if title == None:
@@ -303,11 +305,14 @@ def plot_forecast_canton(table_name, canton, curve, full_name_canton, title=None
303305
# adding the traces
304306
# Data
305307

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+
308313

309314
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')))
311316

312317
# Separation between data and forecast
313318
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
335340

336341
# fig.write_image(path)
337342

338-
del df_for['index']
343+
#del df_for['index']
339344
df_for.index = pd.to_datetime(df_for.index)
340345
df_for.index = df_for.index.date
341346
df_for.reset_index(inplace=True)
@@ -427,7 +432,7 @@ def app():
427432
''')
428433

429434
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)
431436
st.plotly_chart(fig_for, use_container_width=True)
432437
filename = 'forecast_hosp.csv'
433438
download_button_str = download_button(
@@ -436,7 +441,7 @@ def app():
436441
st.markdown(download_button_str, unsafe_allow_html=True)
437442

438443
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)
440445
st.plotly_chart(fig_total, use_container_width=True)
441446
filename = 'forecast_total.csv'
442447
download_button_str = download_button(
@@ -445,7 +450,7 @@ def app():
445450
st.markdown(download_button_str, unsafe_allow_html=True)
446451

447452
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)
449454
st.plotly_chart(fig_for_icu, use_container_width=True)
450455
filename = 'forecast_icu.csv'
451456
download_button_str = download_button(
@@ -460,7 +465,7 @@ def app():
460465
461466
''')
462467
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)
464469

465470
st.plotly_chart(fig_val, use_container_width=True)
466471

@@ -470,7 +475,7 @@ def app():
470475
''')
471476

472477
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)
474479

475480
st.plotly_chart(fig_val_total, use_container_width=True)
476481

@@ -480,6 +485,6 @@ def app():
480485
''')
481486

482487
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)
484489

485490
st.plotly_chart(fig_val_icu, use_container_width=True)

0 commit comments

Comments
 (0)