Skip to content

Commit abaa30a

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

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
st.altair_chart(
5757
new_admit_chart, use_container_width=True
5858
)
59-
60-
6159
st.markdown(chart_descriptions(new_admit_chart))
6260

6361
if st.checkbox("Show Projected Admissions in tabular form"):
@@ -66,11 +64,11 @@
6664
st.markdown(
6765
"Projected **census** of COVID-19 patients, accounting for arrivals and discharges at Penn hospitals"
6866
)
69-
admit_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
67+
census_chart = admitted_patients_chart(alt=alt, census=census_df, parameters=p, as_date=as_date)
7068
st.altair_chart(
71-
admit_chart, use_container_width=True
69+
census_chart, use_container_width=True
7270
)
73-
st.markdown(chart_descriptions(admit_chart, True))
71+
st.markdown(chart_descriptions(census_chart, census=True))
7472
if st.checkbox("Show Projected Census in tabular form"):
7573
draw_census_table(st, census_df, as_date=as_date)
7674
st.markdown(

src/penn_chime/charts.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from math import ceil
2+
import datetime
23
from altair import Chart # type: ignore
34
import pandas as pd # type: ignore
45
import numpy as np # type: ignore
@@ -127,18 +128,30 @@ def additional_projections_chart(
127128

128129
def chart_descriptions(chart, census=False):
129130
messages = []
131+
130132
cols = ["Hospitalized", "ICU", "Ventilated"]
131133
if census:
132134
cols = [col + " Census" for col in cols]
135+
133136
asterisk = False
137+
138+
day = "date" if "date" in chart.data.columns else "day"
139+
134140
for col in cols:
135141
if chart.data[col].idxmax() + 1 == len(chart.data):
136142
asterisk = True
143+
144+
on = chart.data[day][chart.data[col].idxmax()]
145+
if day == "date":
146+
on = datetime.datetime.strftime(on, "%b %d") # todo: bring this to an optional arg / i18n
147+
else:
148+
on += 1 # 0 index issue
149+
137150
messages.append(
138151
"{} peaks at {:,} on day {}{}".format(
139152
col,
140153
ceil(chart.data[col].max()),
141-
chart.data[col].idxmax() + 1,
154+
on,
142155
"*" if asterisk else "",
143156
)
144157
)

0 commit comments

Comments
 (0)