-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcovid_streamlit_view.py
56 lines (43 loc) · 2.05 KB
/
covid_streamlit_view.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
from itertools import product
# Web
import streamlit as st
# Custom
from utils import date_filter, build_bar_data
from covid_fig import covid_analyze_lines, covid_analyze_bars
def covid_lines_stats(df, min_date, max_date, country_list, d_type_list):
st.subheader('COVID-19 Line Chart by Country')
col1, col2 = st.columns([1, 3])
with col1:
countries = st.multiselect(
"Select countries to analyze", country_list, key='Country Name')
d_types = st.multiselect(
"Select data types", d_type_list, key='Data Type')
date_range = st.slider("Select a date range", min_value=min_date,
max_value=max_date, value=(min_date, max_date), key='Line Date')
with col2:
indexes = list(product(d_types, countries))
temp_df = df.loc[indexes, :]
st_index = (date_range[0]-min_date).days+2
lt_index = (date_range[1] - date_range[0]).days + st_index
temp_df = date_filter(temp_df, st_index, lt_index)
fig = covid_analyze_lines(temp_df)
st.plotly_chart(fig, use_container_width=True)
def covid_bars_stats(df, min_date, max_date, d_type_list):
st.subheader('Top Countries Affected by COVID-19')
col1, col2 = st.columns([1, 3])
with col1:
top_k = st.selectbox(
"Select number of countries", [10, 15, 20, 25, 30], key='Top K')
d_types = st.selectbox(
"Select data type", d_type_list, key='Data Type Single')
date_range = st.slider("Select a date range", min_value=min_date,
max_value=max_date, value=(min_date, max_date), key='Bar Date')
with col2:
temp_df = df.loc[d_types]
st_index = (date_range[0]-min_date).days+2
lt_index = (date_range[1] - date_range[0]).days + st_index
temp_df = date_filter(temp_df, st_index, lt_index)
temp_df = build_bar_data(temp_df, d_types)
fig = covid_analyze_bars(
temp_df, d_types, date_range[0], date_range[1], top_k)
st.plotly_chart(fig, use_container_width=True)