Skip to content

Commit 16d07b8

Browse files
author
Nick Canzoneri
committed
Move all presentation controls to the sidebar and into the Parameters model
1 parent 38f83c9 commit 16d07b8

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

src/app.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# additional_projections_chart,
88
display_header,
99
display_sidebar,
10-
display_n_days_input,
1110
draw_census_table,
1211
draw_projected_admissions_table,
1312
draw_raw_sir_simulation_table,
@@ -39,10 +38,6 @@
3938
notes = "The total size of the susceptible population will be the entire catchment area for Penn Medicine entities (HUP, PAH, PMC, CCH)"
4039
show_more_info_about_this_tool(st=st, parameters=p, inputs=DEFAULTS, notes=notes)
4140

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

4742
# begin format data
4843
admissions_df = build_admissions_df(p=p) # p.n_days, *p.dispositions)
@@ -52,29 +47,29 @@
5247
st.subheader("New Admissions")
5348
st.markdown("Projected number of **daily** COVID-19 admissions at Penn hospitals")
5449
st.altair_chart(
55-
new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date),
50+
new_admissions_chart(alt, admissions_df, parameters=p),
5651
use_container_width=True,
5752
)
5853
if st.checkbox("Show Projected Admissions in tabular form"):
59-
draw_projected_admissions_table(st, admissions_df, as_date=as_date)
54+
draw_projected_admissions_table(st, admissions_df)
6055
st.subheader("Admitted Patients (Census)")
6156
st.markdown(
6257
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6358
)
6459
st.altair_chart(
65-
admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date),
60+
admitted_patients_chart(alt=alt, census=census_df, parameters=p),
6661
use_container_width=True,
6762
)
6863
if st.checkbox("Show Projected Census in tabular form"):
69-
draw_census_table(st, census_df, as_date=as_date)
64+
draw_census_table(st, census_df, parameters=p)
7065
st.markdown(
7166
"""**Click the checkbox below to view additional data generated by this simulation**"""
7267
)
7368
if st.checkbox("Show Additional Projections"):
7469
show_additional_projections(
75-
st, alt, additional_projections_chart, parameters=p, as_date=as_date
70+
st, alt, additional_projections_chart, parameters=p
7671
)
7772
if st.checkbox("Show Raw SIR Simulation Data"):
78-
draw_raw_sir_simulation_table(st, parameters=p, as_date=as_date)
73+
draw_raw_sir_simulation_table(st, parameters=p)
7974
write_definitions(st)
8075
write_footer(st)

src/penn_chime/charts.py

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

88

99
def new_admissions_chart(
10-
alt, projection_admits: pd.DataFrame, parameters: Parameters, as_date: bool = False,
10+
alt, projection_admits: pd.DataFrame, parameters: Parameters
1111
) -> Chart:
1212
"""docstring"""
1313
plot_projection_days = parameters.n_days - 10
1414
max_y_axis = parameters.max_y_axis
15+
as_date = parameters.as_date
1516

1617
y_scale = alt.Scale()
1718

@@ -45,12 +46,13 @@ def new_admissions_chart(
4546

4647

4748
def admitted_patients_chart(
48-
alt, census: pd.DataFrame, parameters: Parameters, as_date: bool = False
49+
alt, census: pd.DataFrame, parameters: Parameters
4950
) -> Chart:
5051
"""docstring"""
5152

5253
plot_projection_days = parameters.n_days - 10
5354
max_y_axis = parameters.max_y_axis
55+
as_date = parameters.as_date
5456
if as_date:
5557
census = add_date_column(census)
5658
x_kwargs = {"shorthand": "date:T", "title": "Date"}
@@ -84,10 +86,16 @@ def admitted_patients_chart(
8486

8587

8688
def additional_projections_chart(
87-
alt, i: np.ndarray, r: np.ndarray, as_date: bool = False, max_y_axis: int = None
89+
alt, parameters: Parameters
8890
) -> Chart:
91+
i = parameters.infected_v
92+
r = parameters.recovered_v
8993
dat = pd.DataFrame({"Infected": i, "Recovered": r})
9094
dat["day"] = dat.index
95+
96+
as_date = parameters.as_date
97+
max_y_axis = parameters.max_y_axis
98+
9199
if as_date:
92100
dat = add_date_column(dat)
93101
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
@@ -23,7 +23,8 @@ def __init__(
2323
icu: RateLos,
2424
ventilated: RateLos,
2525
max_y_axis: int = None,
26-
n_days: int = None
26+
n_days: int = None,
27+
as_date: bool = False
2728
):
2829
self.current_hospitalized = current_hospitalized
2930
self.doubling_time = doubling_time
@@ -38,6 +39,7 @@ def __init__(
3839
self.ventilated = ventilated
3940

4041
self.max_y_axis = max_y_axis
42+
self.as_date = as_date
4143

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

src/penn_chime/presentation.py

Lines changed: 14 additions & 16 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,17 +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_input(st, p: Parameters, d: Constants):
230-
"""Display n_days_input."""
231-
p.n_days = st.number_input(
232-
"Number of days to project",
233-
min_value=30,
234-
value=d.n_days,
235-
step=10,
236-
format="%i",
237+
as_date=as_date,
237238
)
238239

239240

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

369370

370371
def show_additional_projections(
371-
st, alt, charting_func, parameters, as_date: bool = False,
372+
st, alt, charting_func, parameters
372373
):
373374
st.subheader(
374375
"The number of infected and recovered individuals in the hospital catchment region at any given moment"
@@ -377,10 +378,7 @@ def show_additional_projections(
377378
st.altair_chart(
378379
charting_func(
379380
alt,
380-
parameters.infected_v,
381-
parameters.recovered_v,
382-
as_date=as_date,
383-
max_y_axis=parameters.max_y_axis,
381+
parameters=parameters
384382
),
385383
use_container_width=True,
386384
)

0 commit comments

Comments
 (0)