Skip to content

Commit 9758623

Browse files
author
PJ Hoberman
committed
Adding chart language
1 parent 76a5a76 commit 9758623

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/app.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
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 (
23-
additional_projections_chart,
24-
admitted_patients_chart,
25-
new_admissions_chart,
26-
)
27-
22+
from penn_chime.charts import (additional_projections_chart,
23+
admitted_patients_chart,
24+
new_admissions_chart,
25+
chart_descriptions)
2826
# This is somewhat dangerous:
2927
# Hide the main menu with "Rerun", "run on Save", "clear cache", and "record a screencast"
3028
# This should not be hidden in prod, but removed
@@ -51,20 +49,24 @@
5149

5250
st.subheader("New Admissions")
5351
st.markdown("Projected number of **daily** COVID-19 admissions at Penn hospitals")
52+
new_admit_chart = new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date)
5453
st.altair_chart(
55-
new_admissions_chart(alt, admissions_df, parameters=p, as_date=as_date),
56-
use_container_width=True,
54+
new_admit_chart, use_container_width=True
5755
)
56+
57+
st.markdown(chart_descriptions(new_admit_chart))
58+
5859
if st.checkbox("Show Projected Admissions in tabular form"):
5960
draw_projected_admissions_table(st, admissions_df, as_date=as_date)
6061
st.subheader("Admitted Patients (Census)")
6162
st.markdown(
6263
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6364
)
65+
admit_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
6466
st.altair_chart(
65-
admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date),
66-
use_container_width=True,
67+
admit_chart, use_container_width=True
6768
)
69+
st.markdown(chart_descriptions(admit_chart, True))
6870
if st.checkbox("Show Projected Census in tabular form"):
6971
draw_census_table(st, census_df, as_date=as_date)
7072
st.markdown(

src/penn_chime/charts.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
from math import ceil
13
from altair import Chart # type: ignore
24
import pandas as pd # type: ignore
35
import numpy as np # type: ignore
@@ -112,3 +114,26 @@ def additional_projections_chart(
112114
)
113115
.interactive()
114116
)
117+
118+
119+
def chart_descriptions(chart, census=False):
120+
messages = []
121+
cols = ["Hospitalized", "ICU", "Ventilated"]
122+
if census:
123+
cols = [col + " Census" for col in cols]
124+
asterisk = False
125+
for col in cols:
126+
if chart.data[col].idxmax() + 1 == len(chart.data):
127+
asterisk = True
128+
messages.append(
129+
"{} peaks at {:,} on day {}{}".format(
130+
col,
131+
ceil(chart.data[col].max()),
132+
chart.data[col].idxmax() + 1,
133+
"*" if asterisk else "",
134+
)
135+
)
136+
137+
if asterisk:
138+
messages.append("_* The max is at the upper bound of the data, and therefore may not be the actual max_")
139+
return "\n\n".join(messages)

src/penn_chime/presentation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ def draw_projected_admissions_table(
404404
admits_table = add_date_column(
405405
admits_table, drop_day_column=True, date_format=DATE_FORMAT
406406
)
407-
408407
st.table(admits_table)
409408
return None
410409

0 commit comments

Comments
 (0)