Skip to content

Commit 051d404

Browse files
Merge pull request #204 from nickcanz/expand_max_days_input
Change projection days from a slider to a number input to allow larger max values
2 parents 4177e46 + 0a13587 commit 051d404

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

e2e/cypress/integration/tests/actions.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ context('Actions', () => {
88
it('All + elements are clickable', () => {
99
cy.get('.step-up').click( { multiple: true } )
1010

11+
// This gets the "first" input from the sidebar. From clicking step up,
12+
// the number of days to project should increase from default 60 to 70.
1113
cy.get('input.st-al')
12-
.should('has.value', '7')
14+
.should('has.value', '70')
1315
})
1416
})

src/app.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import streamlit as st # type: ignore
55

66
from penn_chime.presentation import (
7-
# additional_projections_chart,
87
display_header,
98
display_sidebar,
10-
display_n_days_slider,
119
draw_census_table,
1210
draw_projected_admissions_table,
1311
draw_raw_sir_simulation_table,
@@ -38,10 +36,6 @@
3836
notes = "The total size of the susceptible population will be the entire catchment area for Penn Medicine entities (HUP, PAH, PMC, CCH)"
3937
show_more_info_about_this_tool(st=st, parameters=p, inputs=DEFAULTS, notes=notes)
4038

41-
# PRESENTATION
42-
# Two more combination variable initialization / input element creation
43-
as_date = st.checkbox(label="Present result as dates instead of days", value=False)
44-
display_n_days_slider(st, p, DEFAULTS)
4539

4640
# begin format data
4741
admissions_df = build_admissions_df(p=p) # p.n_days, *p.dispositions)
@@ -50,34 +44,34 @@
5044

5145
st.subheader("New Admissions")
5246
st.markdown("Projected number of **daily** COVID-19 admissions at Penn hospitals")
53-
new_admit_chart = new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date)
47+
new_admit_chart = new_admissions_chart(alt, admissions_df, parameters=p)
5448
st.altair_chart(
5549
new_admit_chart, use_container_width=True
5650
)
5751

5852
st.markdown(chart_descriptions(new_admit_chart))
5953

6054
if st.checkbox("Show Projected Admissions in tabular form"):
61-
draw_projected_admissions_table(st, admissions_df, as_date=as_date)
55+
draw_projected_admissions_table(st, admissions_df, as_date=p.as_date)
6256
st.subheader("Admitted Patients (Census)")
6357
st.markdown(
6458
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6559
)
66-
census_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
60+
census_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p)
6761
st.altair_chart(
6862
census_chart, use_container_width=True
6963
)
7064
st.markdown(chart_descriptions(census_chart, suffix=" Census"))
7165
if st.checkbox("Show Projected Census in tabular form"):
72-
draw_census_table(st, census_df, as_date=as_date)
66+
draw_census_table(st, census_df, as_date=p.as_date)
7367
st.markdown(
7468
"""**Click the checkbox below to view additional data generated by this simulation**"""
7569
)
7670
if st.checkbox("Show Additional Projections"):
7771
show_additional_projections(
78-
st, alt, additional_projections_chart, parameters=p, as_date=as_date
72+
st, alt, additional_projections_chart, parameters=p
7973
)
8074
if st.checkbox("Show Raw SIR Simulation Data"):
81-
draw_raw_sir_simulation_table(st, parameters=p, as_date=as_date)
75+
draw_raw_sir_simulation_table(st, parameters=p)
8276
write_definitions(st)
8377
write_footer(st)

src/penn_chime/charts.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111

1212
def new_admissions_chart(
13-
alt, projection_admits: pd.DataFrame, parameters: Parameters, as_date: bool = False,
13+
alt, projection_admits: pd.DataFrame, parameters: Parameters
1414
) -> Chart:
1515
"""docstring"""
1616
plot_projection_days = parameters.n_days - 10
1717
max_y_axis = parameters.max_y_axis
18+
as_date = parameters.as_date
1819

1920
y_scale = alt.Scale()
2021

@@ -48,12 +49,13 @@ def new_admissions_chart(
4849

4950

5051
def admitted_patients_chart(
51-
alt, census: pd.DataFrame, parameters: Parameters, as_date: bool = False
52+
alt, census: pd.DataFrame, parameters: Parameters
5253
) -> Chart:
5354
"""docstring"""
5455

5556
plot_projection_days = parameters.n_days - 10
5657
max_y_axis = parameters.max_y_axis
58+
as_date = parameters.as_date
5759
if as_date:
5860
census = add_date_column(census)
5961
x_kwargs = {"shorthand": "date:T", "title": "Date"}
@@ -87,10 +89,16 @@ def admitted_patients_chart(
8789

8890

8991
def additional_projections_chart(
90-
alt, i: np.ndarray, r: np.ndarray, as_date: bool = False, max_y_axis: int = None
92+
alt, parameters: Parameters
9193
) -> Chart:
94+
i = parameters.infected_v
95+
r = parameters.recovered_v
9296
dat = pd.DataFrame({"Infected": i, "Recovered": r})
9397
dat["day"] = dat.index
98+
99+
as_date = parameters.as_date
100+
max_y_axis = parameters.max_y_axis
101+
94102
if as_date:
95103
dat = add_date_column(dat)
96104
x_kwargs = {"shorthand": "date:T", "title": "Date"}

src/penn_chime/parameters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def __init__(
2727
icu: RateLos,
2828
ventilated: RateLos,
2929
max_y_axis: int = None,
30-
n_days: int = None
30+
n_days: int = None,
31+
as_date: bool = False
3132
):
3233
self.current_hospitalized = current_hospitalized
3334
self.doubling_time = doubling_time
@@ -42,6 +43,7 @@ def __init__(
4243
self.ventilated = ventilated
4344

4445
self.max_y_axis = max_y_axis
46+
self.as_date = as_date
4547

4648
self.rates = tuple(each.rate for each in (hospitalized, icu, ventilated))
4749
self.lengths_of_stay = tuple(

src/penn_chime/presentation.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def display_sidebar(st, d: Constants) -> Parameters:
9494
if d.known_infected < 1:
9595
raise ValueError("Known cases must be larger than one to enable predictions.")
9696

97+
n_days = st.sidebar.number_input(
98+
"Number of days to project",
99+
min_value=30,
100+
value=d.n_days,
101+
step=10,
102+
format="%i",
103+
)
104+
97105
current_hospitalized = st.sidebar.number_input(
98106
"Currently Hospitalized COVID-19 Patients",
99107
min_value=0,
@@ -205,6 +213,8 @@ def display_sidebar(st, d: Constants) -> Parameters:
205213
format="%i",
206214
)
207215

216+
as_date = st.sidebar.checkbox(label="Present result as dates instead of days", value=False)
217+
208218
max_y_axis_set = st.sidebar.checkbox("Set the Y-axis on graphs to a static value")
209219
max_y_axis = None
210220
if max_y_axis_set:
@@ -213,6 +223,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
213223
)
214224

215225
return Parameters(
226+
n_days=n_days,
216227
current_hospitalized=current_hospitalized,
217228
doubling_time=doubling_time,
218229
known_infected=known_infected,
@@ -223,18 +234,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
223234
icu=RateLos(icu_rate, icu_los),
224235
ventilated=RateLos(ventilated_rate, ventilated_los),
225236
max_y_axis=max_y_axis,
226-
)
227-
228-
229-
def display_n_days_slider(st, p: Parameters, d: Constants):
230-
"""Display n_days_slider."""
231-
p.n_days = st.slider(
232-
"Number of days to project",
233-
min_value=30,
234-
max_value=200,
235-
value=d.n_days,
236-
step=1,
237-
format="%i",
237+
as_date=as_date,
238238
)
239239

240240

@@ -369,7 +369,7 @@ def write_footer(st):
369369

370370

371371
def show_additional_projections(
372-
st, alt, charting_func, parameters, as_date: bool = False,
372+
st, alt, charting_func, parameters
373373
):
374374
st.subheader(
375375
"The number of infected and recovered individuals in the hospital catchment region at any given moment"
@@ -378,10 +378,7 @@ def show_additional_projections(
378378
st.altair_chart(
379379
charting_func(
380380
alt,
381-
parameters.infected_v,
382-
parameters.recovered_v,
383-
as_date=as_date,
384-
max_y_axis=parameters.max_y_axis,
381+
parameters=parameters
385382
),
386383
use_container_width=True,
387384
)
@@ -423,7 +420,8 @@ def draw_census_table(st, census_df: pd.DataFrame, as_date: bool = False):
423420
return None
424421

425422

426-
def draw_raw_sir_simulation_table(st, parameters, as_date: bool = False):
423+
def draw_raw_sir_simulation_table(st, parameters):
424+
as_date = parameters.as_date
427425
days = np.arange(0, parameters.n_days + 1)
428426
data_list = [
429427
days,

tests/test_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def test_chart_descriptions():
288288
# census chart
289289
census_df = pd.read_csv('tests/census_df.csv')
290290
census_df = census_df.rename(columns={'hosp': 'Hospitalized', 'icu': 'ICU', 'vent': 'Ventilated'})
291-
chart = admitted_patients_chart(alt, census_df, PARAM, as_date=True)
291+
PARAM.as_date = True
292+
chart = admitted_patients_chart(alt, census_df, PARAM)
292293
description = chart_descriptions(chart)
293294

294295
assert str(ceil(chart.data['Ventilated'].max())) in description

0 commit comments

Comments
 (0)