Skip to content

Commit ec420cd

Browse files
authored
Merge pull request #57 from CodeForPhilly/graph-granularity
makes census chart granular at daily level
2 parents 0d47757 + 0d8ba87 commit ec420cd

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

app.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
)
6060

6161
initial_infections = st.sidebar.number_input(
62-
"Currently Known Regional Infections (only used to compute detection rate - does not change projections)", value=known_infections, step=10, format="%i"
62+
"Currently Known Regional Infections", value=known_infections, step=10, format="%i"
6363
)
6464

6565
total_infections = current_hosp / Penn_market_share / hosp_rate
@@ -286,6 +286,7 @@ def sim_sir(S, I, R, beta, gamma, n_days, beta_decay=None):
286286
projection_admits = projection.iloc[:-1, :] - projection.shift(1)
287287
projection_admits[projection_admits < 0] = 0
288288

289+
289290
plot_projection_days = n_days - 10
290291
projection_admits["day"] = range(projection_admits.shape[0])
291292

@@ -324,7 +325,7 @@ def new_admissions_chart(projection_admits: pd.DataFrame, plot_projection_days:
324325
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
325326
)
326327

327-
def _census_table(projection_admits, hosp_los, icu_los, vent_los) -> pd.DataFrame:
328+
def _census_df(projection_admits, hosp_los, icu_los, vent_los) -> pd.DataFrame:
328329
"""ALOS for each category of COVID-19 case (total guesses)"""
329330

330331
los_dict = {
@@ -345,23 +346,16 @@ def _census_table(projection_admits, hosp_los, icu_los, vent_los) -> pd.DataFram
345346
census_df = pd.DataFrame(census_dict)
346347
census_df["day"] = census_df.index
347348
census_df = census_df[["day", "hosp", "icu", "vent"]]
349+
return census_df
348350

349-
census_table = census_df[np.mod(census_df.index, 7) == 0].copy()
350-
census_table.index = range(census_table.shape[0])
351-
census_table.loc[0, :] = 0
352-
census_table = census_table.dropna().astype(int)
353-
354-
return census_table
355-
356-
census_table = _census_table(projection_admits, hosp_los, icu_los, vent_los)
351+
census_df = _census_df(projection_admits, hosp_los, icu_los, vent_los)
357352

358353
def admitted_patients_chart(census: pd.DataFrame) -> alt.Chart:
359354
"""docstring"""
360355
census = census.rename(columns={"hosp": "Hospital Census", "icu": "ICU Census", "vent": "Ventilated Census"})
361-
362356
return (
363357
alt
364-
.Chart(census)
358+
.Chart(census.head(plot_projection_days))
365359
.transform_fold(fold=["Hospital Census", "ICU Census", "Ventilated Census"])
366360
.mark_line(point=True)
367361
.encode(
@@ -373,9 +367,14 @@ def admitted_patients_chart(census: pd.DataFrame) -> alt.Chart:
373367
.interactive()
374368
)
375369

376-
st.altair_chart(admitted_patients_chart(census_table), use_container_width=True)
370+
st.altair_chart(admitted_patients_chart(census_df), use_container_width=True)
377371

378372
if st.checkbox("Show Projected Census in tabular form"):
373+
census_table = census_df[np.mod(census_df.index, 7) == 0].copy()
374+
census_table.index = range(census_table.shape[0])
375+
census_table.loc[0, :] = 0
376+
census_table = census_table.dropna().astype(int)
377+
379378
st.dataframe(census_table)
380379

381380
def additional_projections_chart(i: np.ndarray, r: np.ndarray) -> alt.Chart:

0 commit comments

Comments
 (0)