Skip to content

Commit 1ae4dd3

Browse files
author
PJ Hoberman
committed
Adding chart language
1 parent 7f7e33e commit 1ae4dd3

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/app.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
)
2020
from penn_chime.settings import DEFAULTS
2121
from penn_chime.models import sim_sir_df, build_admissions_df, build_census_df
22-
from penn_chime.charts import additional_projections_chart, admitted_patients_chart, new_admissions_chart
22+
from penn_chime.charts import (additional_projections_chart, admitted_patients_chart,
23+
new_admissions_chart, chart_descriptions)
2324
# This is somewhat dangerous:
2425
# Hide the main menu with "Rerun", "run on Save", "clear cache", and "record a screencast"
2526
# This should not be hidden in prod, but removed
@@ -51,18 +52,25 @@
5152

5253
st.subheader("New Admissions")
5354
st.markdown("Projected number of **daily** COVID-19 admissions at Penn hospitals")
55+
new_admit_chart = new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date)
5456
st.altair_chart(
55-
new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date), use_container_width=True
57+
new_admit_chart, use_container_width=True
5658
)
59+
60+
61+
st.markdown(chart_descriptions(new_admit_chart))
62+
5763
if st.checkbox("Show Projected Admissions in tabular form"):
5864
draw_projected_admissions_table(st, admissions_df, as_date=as_date)
5965
st.subheader("Admitted Patients (Census)")
6066
st.markdown(
6167
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6268
)
69+
admit_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
6370
st.altair_chart(
64-
admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date), use_container_width=True
71+
admit_chart, use_container_width=True
6572
)
73+
st.markdown(chart_descriptions(admit_chart, True))
6674
if st.checkbox("Show Projected Census in tabular form"):
6775
draw_census_table(st, census_df, as_date=as_date)
6876
st.markdown(

src/penn_chime/charts.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
from math import ceil
22
from altair import Chart # type: ignore
33
import pandas as pd # type: ignore
44
import numpy as np # type: ignore
@@ -123,3 +123,26 @@ def additional_projections_chart(
123123
)
124124
.interactive()
125125
)
126+
127+
128+
def chart_descriptions(chart, census=False):
129+
messages = []
130+
cols = ["Hospitalized", "ICU", "Ventilated"]
131+
if census:
132+
cols = [col + " Census" for col in cols]
133+
asterisk = False
134+
for col in cols:
135+
if chart.data[col].idxmax() + 1 == len(chart.data):
136+
asterisk = True
137+
messages.append(
138+
"{} peaks at {:,} on day {}{}".format(
139+
col,
140+
ceil(chart.data[col].max()),
141+
chart.data[col].idxmax() + 1,
142+
"*" if asterisk else "",
143+
)
144+
)
145+
146+
if asterisk:
147+
messages.append("_* The max is at the upper bound of the data, and therefore may not be the actual max_")
148+
return "\n\n".join(messages)

src/penn_chime/presentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ def draw_projected_admissions_table(
408408
drop_day_column=True,
409409
date_format=DATE_FORMAT
410410
)
411-
412411
st.table(admits_table)
413412
return None
414413

414+
415415
def draw_census_table(st, census_df: pd.DataFrame, as_date: bool = False):
416416
census_table = census_df[np.mod(census_df.index, 7) == 0].copy()
417417
census_table.index = range(census_table.shape[0])

0 commit comments

Comments
 (0)