-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateOutcomePlots.py
153 lines (110 loc) · 3.33 KB
/
UpdateOutcomePlots.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
# -*- coding: utf-8 -*-
"""
Work on new plots for monitoring the situation.
Created on Wed Jun 30 10:48:03 2021
@author: 212367548
"""
import datetime
import os
import covid
from tableauscraper import TableauScraper as TS
ts = TS()
#%% Deaths / cases plot
case_df = covid.scrape_widash_cases()
death_df = covid.scrape_widash_deaths()
hosp_df = covid.download_hhs_data_wi()
#%% Put all data into one DF
plotdata = case_df[['Date', 'Confirmed']]
plotdata = plotdata.rename(columns={'Confirmed': 'Cases'})
plotdata = plotdata.set_index('Date')
plotdata['Deaths'] = death_df.set_index('Date')['Confirmed']
plotdata['Admissions'] = hosp_df.set_index('Date')['previous_day_admission_adult_covid_confirmed']
plotdata = plotdata.reset_index()
#%% Function to add shading to preliminary area of plot
def shade_preliminary(fig, x0, x1):
# shading applied to the x range between x0 and x1
fig.add_shape(
type="rect",
xref='x', x0=x0, x1=x1,
yref='paper', y0=0, y1=1,
line_color='rgba(0,0,0,0)',
fillcolor='rgba(0,0,0,0.2)',
)
fig.add_annotation(
xanchor='right', xref='x', x=x0,
yanchor='top', yref='paper', y=1,
text='Preliminary<br>data',
font_color='rgb(0.5,0.5,0.5)',
align='right',
showarrow=False,
)
#%% Plot Deaths / Cases
# parameters for comparison
lag = 12
cfr = 0.012
# Make a plot
plotpath = '.\\docs\\_includes\\plotly'
savefile = plotpath+'\\Deaths-Cases-WI.html'
fig = covid.plotly_twolines(
plotdata,
'Deaths',
'Cases',
plotcolors=['firebrick', 'steelblue', 'rosybrown'],
secondary_scale=1/cfr,
# date_min=datetime.datetime(2021,1,15),
range_max=160,
col1_mode='avg-bar',
col2_mode='avg',
plotlabels = {'title': 'Deaths vs Cases - WI<br>(CFR '+str(cfr*100)+'%)',
'yaxis': 'Deaths',
'yaxis_secondary': 'Cases',
},
savefile=savefile,
showfig=False,
)
fig.update_xaxes(title_text='Date of death / Date of test')
# shade the recent data using custom function
shade_days = 14
end_date = plotdata.Date.max()
start_date = end_date - datetime.timedelta(days=shade_days)
shade_preliminary(fig, start_date, end_date)
fig.write_html(
file=savefile,
default_height=480,
include_plotlyjs='cdn',
)
os.startfile(savefile)
#%% Hospitalization plot
# Make a plot
plotpath = '.\\docs\\_includes\\plotly'
savefile = plotpath+'\\Hosp-Cases-WI.html'
hrate = 0.09
fig = covid.plotly_twolines(
plotdata,
'Admissions',
'Cases',
plotcolors=['darkorange', 'steelblue', 'burlywood'],
secondary_scale=1/hrate,
# date_min=datetime.datetime(2021,1,15),
range_max=1200,
col1_mode='avg-bar',
col2_mode='avg',
plotlabels = {'title': 'Hospital Admissions vs Cases - WI',
'yaxis': 'Admissions',
'yaxis_secondary': 'Cases',
},
savefile=savefile,
showfig=False,
)
fig.update_xaxes(title_text='Date of admission / Date of test')
# shade the recent data using custom function
shade_days = 14
end_date = plotdata.Date.max()
start_date = end_date - datetime.timedelta(days=shade_days)
shade_preliminary(fig, start_date, end_date)
fig.write_html(
file=savefile,
default_height=480,
include_plotlyjs='cdn',
)
os.startfile(savefile)