Skip to content
Merged
4 changes: 3 additions & 1 deletion e2e/cypress/integration/tests/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ context('Actions', () => {
it('All + elements are clickable', () => {
cy.get('.step-up').click( { multiple: true } )

// This gets the "first" input from the sidebar. From clicking step up,
// the number of days to project should increase from default 60 to 70.
cy.get('input.st-al')
.should('has.value', '7')
.should('has.value', '70')
})
})
13 changes: 4 additions & 9 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# additional_projections_chart,
display_header,
display_sidebar,
display_n_days_slider,
draw_census_table,
draw_projected_admissions_table,
draw_raw_sir_simulation_table,
Expand Down Expand Up @@ -38,10 +37,6 @@
notes = "The total size of the susceptible population will be the entire catchment area for Penn Medicine entities (HUP, PAH, PMC, CCH)"
show_more_info_about_this_tool(st=st, parameters=p, inputs=DEFAULTS, notes=notes)

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

# begin format data
admissions_df = build_admissions_df(p=p) # p.n_days, *p.dispositions)
Expand All @@ -58,7 +53,7 @@
st.markdown(chart_descriptions(new_admit_chart))

if st.checkbox("Show Projected Admissions in tabular form"):
draw_projected_admissions_table(st, admissions_df, as_date=as_date)
draw_projected_admissions_table(st, admissions_df, as_date=p.as_date)
st.subheader("Admitted Patients (Census)")
st.markdown(
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
Expand All @@ -69,15 +64,15 @@
)
st.markdown(chart_descriptions(census_chart, suffix=" Census"))
if st.checkbox("Show Projected Census in tabular form"):
draw_census_table(st, census_df, as_date=as_date)
draw_census_table(st, census_df, as_date=p.as_date)
st.markdown(
"""**Click the checkbox below to view additional data generated by this simulation**"""
)
if st.checkbox("Show Additional Projections"):
show_additional_projections(
st, alt, additional_projections_chart, parameters=p, as_date=as_date
st, alt, additional_projections_chart, parameters=p
)
if st.checkbox("Show Raw SIR Simulation Data"):
draw_raw_sir_simulation_table(st, parameters=p, as_date=as_date)
draw_raw_sir_simulation_table(st, parameters=p)
write_definitions(st)
write_footer(st)
14 changes: 11 additions & 3 deletions src/penn_chime/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@


def new_admissions_chart(
alt, projection_admits: pd.DataFrame, parameters: Parameters, as_date: bool = False,
alt, projection_admits: pd.DataFrame, parameters: Parameters
) -> Chart:
"""docstring"""
plot_projection_days = parameters.n_days - 10
max_y_axis = parameters.max_y_axis
as_date = parameters.as_date

y_scale = alt.Scale()

Expand Down Expand Up @@ -48,12 +49,13 @@ def new_admissions_chart(


def admitted_patients_chart(
alt, census: pd.DataFrame, parameters: Parameters, as_date: bool = False
alt, census: pd.DataFrame, parameters: Parameters
) -> Chart:
"""docstring"""

plot_projection_days = parameters.n_days - 10
max_y_axis = parameters.max_y_axis
as_date = parameters.as_date
if as_date:
census = add_date_column(census)
x_kwargs = {"shorthand": "date:T", "title": "Date"}
Expand Down Expand Up @@ -87,10 +89,16 @@ def admitted_patients_chart(


def additional_projections_chart(
alt, i: np.ndarray, r: np.ndarray, as_date: bool = False, max_y_axis: int = None
alt, parameters: Parameters
) -> Chart:
i = parameters.infected_v
r = parameters.recovered_v
dat = pd.DataFrame({"Infected": i, "Recovered": r})
dat["day"] = dat.index

as_date = parameters.as_date
max_y_axis = parameters.max_y_axis

if as_date:
dat = add_date_column(dat)
x_kwargs = {"shorthand": "date:T", "title": "Date"}
Expand Down
4 changes: 3 additions & 1 deletion src/penn_chime/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(
icu: RateLos,
ventilated: RateLos,
max_y_axis: int = None,
n_days: int = None
n_days: int = None,
as_date: bool = False
):
self.current_hospitalized = current_hospitalized
self.doubling_time = doubling_time
Expand All @@ -42,6 +43,7 @@ def __init__(
self.ventilated = ventilated

self.max_y_axis = max_y_axis
self.as_date = as_date

self.rates = tuple(each.rate for each in (hospitalized, icu, ventilated))
self.lengths_of_stay = tuple(
Expand Down
34 changes: 16 additions & 18 deletions src/penn_chime/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def display_sidebar(st, d: Constants) -> Parameters:
if d.known_infected < 1:
raise ValueError("Known cases must be larger than one to enable predictions.")

n_days = st.sidebar.number_input(
"Number of days to project",
min_value=30,
value=d.n_days,
step=10,
format="%i",
)

current_hospitalized = st.sidebar.number_input(
"Currently Hospitalized COVID-19 Patients",
min_value=0,
Expand Down Expand Up @@ -205,6 +213,8 @@ def display_sidebar(st, d: Constants) -> Parameters:
format="%i",
)

as_date = st.sidebar.checkbox(label="Present result as dates instead of days", value=False)

max_y_axis_set = st.sidebar.checkbox("Set the Y-axis on graphs to a static value")
max_y_axis = None
if max_y_axis_set:
Expand All @@ -213,6 +223,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
)

return Parameters(
n_days=n_days,
current_hospitalized=current_hospitalized,
doubling_time=doubling_time,
known_infected=known_infected,
Expand All @@ -223,18 +234,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
icu=RateLos(icu_rate, icu_los),
ventilated=RateLos(ventilated_rate, ventilated_los),
max_y_axis=max_y_axis,
)


def display_n_days_slider(st, p: Parameters, d: Constants):
"""Display n_days_slider."""
p.n_days = st.slider(
"Number of days to project",
min_value=30,
max_value=200,
value=d.n_days,
step=1,
format="%i",
as_date=as_date,
)


Expand Down Expand Up @@ -369,7 +369,7 @@ def write_footer(st):


def show_additional_projections(
st, alt, charting_func, parameters, as_date: bool = False,
st, alt, charting_func, parameters
):
st.subheader(
"The number of infected and recovered individuals in the hospital catchment region at any given moment"
Expand All @@ -378,10 +378,7 @@ def show_additional_projections(
st.altair_chart(
charting_func(
alt,
parameters.infected_v,
parameters.recovered_v,
as_date=as_date,
max_y_axis=parameters.max_y_axis,
parameters=parameters
),
use_container_width=True,
)
Expand Down Expand Up @@ -423,7 +420,8 @@ def draw_census_table(st, census_df: pd.DataFrame, as_date: bool = False):
return None


def draw_raw_sir_simulation_table(st, parameters, as_date: bool = False):
def draw_raw_sir_simulation_table(st, parameters):
as_date = parameters.as_date
days = np.arange(0, parameters.n_days + 1)
data_list = [
days,
Expand Down