-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcovid_states_app.py
More file actions
144 lines (122 loc) · 4.17 KB
/
covid_states_app.py
File metadata and controls
144 lines (122 loc) · 4.17 KB
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
import streamlit as st
import numpy as np
from draw_plots import tests_plot, load_data, process_state_tracker, create_plot
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import json
from datetime import timedelta
#@st.cache(allow_output_mutation=True)
hosp_col_dict = {
"Hospital Census":"hospitalizedCurrently",
"New Hospitalizations":"hospitalizedIncrease"
}
other_col_dict = {
"New COVID Cases": "positiveIncrease",
"COVID-related Deaths": "deathIncrease"
}
# get state info
with open('state_data.json') as json_file:
state_data = json.load(json_file)
## SIDEBAR
state = st.sidebar.selectbox(
"Which State Would You Like to view?",
[k for k,v in state_data.items()]
)
site_title = st.title(state+' COVID Trends Data')
hosp_col = st.sidebar.selectbox(
'Do you want New Hospitalizations or Census?',
[k for k,v in hosp_col_dict.items()])
st.sidebar.markdown("---")
# load and process the data
data = load_data(state=state_data[state]["abbr"])
process_state_tracker(data)
# deaths count
total_deaths = int(data["death"].iloc[-1])
rel_deaths = np.round(data["death"].iloc[-1] / (state_data[state]["Population"] / 100000), 1)
st.sidebar.markdown(
'<p style="font-size:120%;font-weigth;bold;color:#444444; text-align: center;">Total COVID-related Deaths<br /><span style="font-size:300%;font-family: Impact, Charcoal, sans-serif;">'+str(total_deaths)+'</span><br /><span style="font-size:90%;">'+str(rel_deaths)+' per 100,000</span></p>',
unsafe_allow_html=True
)
# percent positive: 7-day average
pct_pos = np.round(data["pct_pos"].iloc[-7:].mean()*100, 1)
if pct_pos > 10:
color = 'red'
elif pct_pos > 5 and pct_pos <=10:
color = 'orange'
else:
color = '#444444'
st.sidebar.markdown("---")
if pct_pos > 100:
st.sidebar.markdown(
'<p style="font-size:120%;font-weigth;bold;color:#444444; text-align: center;">'
+'Percent Positve (Past Week)<br />'
+ '<span style="font-size:300%;font-family: Impact, Charcoal, sans-serif;">'
+ 'No Data</span></p>',
unsafe_allow_html=True
)
else:
st.sidebar.markdown(
'<p style="font-size:120%;font-weigth;bold;color:#444444; text-align: center;">'
+ 'Percent Positve (Past Week)<br />'
+ '<span style="font-size:300%;font-family: Impact, Charcoal, sans-serif;color:'+color+';">'
+ str(pct_pos)+'%</span></p>',
unsafe_allow_html=True
)
# case fatality rate
st.sidebar.markdown("---")
cfr = np.round((data.death / data.positive).values[-1]*100, 2)
st.sidebar.markdown(
'<p style="font-size:120%;font-weigth;bold;color:#444444; text-align: center;">Case Fatality Rate<br /><span style="font-size:300%;font-family: Impact, Charcoal, sans-serif;">'+str(cfr)+'</span><br /><span style="font-size:90%;">deaths per 100 cases</span></p>',
unsafe_allow_html=True
)
# Contribute
st.sidebar.markdown("---")
st.sidebar.info(
"This is an open source project and you are welcome to **contribute** "
"[issues](https://github.com/TheeChris/USofCOVID/issues) or "
"[pull requests](https://github.com/TheeChris/USofCOVID/pulls) "
"to [source code](https://github.com/TheeChris/USofCOVID). "
)
## MAIN SECTION
st.subheader(
"State Population: {:,}".format(state_data[state]['Population'])
)
phases = st.checkbox("Show reopening dates and measures")
if phases:
with open(state_data[state]["Policy"], 'r') as reader:
st.markdown(reader.read())
# COVID+ hospitalizations
st.header(hosp_col)
create_plot(
data,
state_data,
col=hosp_col,
col_dict=hosp_col_dict,
state=state
)
# New COVID Cases
st.header("New COVID Cases")
create_plot(
data,
state_data,
col="New COVID Cases",
col_dict=other_col_dict,
state=state
)
# COVID testing plot
st.header("Testing Data")
tests_plot(data=data)
# COVID-related deaths plot
st.header("COVID-related Deaths")
create_plot(
data,
state_data,
col="COVID-related Deaths",
col_dict=other_col_dict,
state=state
)
# Federal Phase Definitions
guidelines = st.checkbox("Show Federal Guideline Definitions")
if guidelines:
with open('guidelines.md', 'r') as reader:
st.markdown(reader.read())