Skip to content

Commit ca5c65d

Browse files
author
PJ Hoberman
committed
Added option for as date. Cleaned up variable names
1 parent 9758623 commit ca5c65d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
st.markdown(
6363
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6464
)
65-
admit_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
65+
census_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
6666
st.altair_chart(
67-
admit_chart, use_container_width=True
67+
census_chart, use_container_width=True
6868
)
69-
st.markdown(chart_descriptions(admit_chart, True))
69+
st.markdown(chart_descriptions(census_chart, census=True))
7070
if st.checkbox("Show Projected Census in tabular form"):
7171
draw_census_table(st, census_df, as_date=as_date)
7272
st.markdown(

src/penn_chime/charts.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
from math import ceil
3+
import datetime
34
from altair import Chart # type: ignore
45
import pandas as pd # type: ignore
56
import numpy as np # type: ignore
@@ -118,18 +119,30 @@ def additional_projections_chart(
118119

119120
def chart_descriptions(chart, census=False):
120121
messages = []
122+
121123
cols = ["Hospitalized", "ICU", "Ventilated"]
122124
if census:
123125
cols = [col + " Census" for col in cols]
126+
124127
asterisk = False
128+
129+
day = "date" if "date" in chart.data.columns else "day"
130+
125131
for col in cols:
126132
if chart.data[col].idxmax() + 1 == len(chart.data):
127133
asterisk = True
134+
135+
on = chart.data[day][chart.data[col].idxmax()]
136+
if day == "date":
137+
on = datetime.datetime.strftime(on, "%b %d") # todo: bring this to an optional arg / i18n
138+
else:
139+
on += 1 # 0 index issue
140+
128141
messages.append(
129142
"{} peaks at {:,} on day {}{}".format(
130143
col,
131144
ceil(chart.data[col].max()),
132-
chart.data[col].idxmax() + 1,
145+
on,
133146
"*" if asterisk else "",
134147
)
135148
)

0 commit comments

Comments
 (0)