Skip to content

Commit c939c48

Browse files
author
Nick Canzoneri
committed
Merge remote-tracking branch 'upstream/develop' into pip_installation_scripts
2 parents 42826cc + 0bc279d commit c939c48

File tree

3 files changed

+58
-33
lines changed

3 files changed

+58
-33
lines changed

src/penn_chime/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def __init__(self, p: Parameters) -> SimSirModel:
9393
self.dispositions_df = dispositions_df
9494
self.admits_df = admits_df
9595
self.census_df = census_df
96+
self.daily_growth = daily_growth_helper(p.doubling_time)
97+
self.daily_growth_t = daily_growth_helper(doubling_time_t)
9698

9799

98100
def sir(
@@ -171,3 +173,11 @@ def build_census_df(
171173
for key, los in lengths_of_stay.items()
172174
}
173175
})
176+
177+
178+
def daily_growth_helper(doubling_time):
179+
"""Calculates average daily growth rate from doubling time"""
180+
result = 0
181+
if doubling_time != 0:
182+
result = (np.power(2, 1.0 / doubling_time) - 1) * 100
183+
return result

src/penn_chime/presentation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ def display_header(st, m, p):
8181
{infected_population_warning_str}
8282
8383
An initial doubling time of **{doubling_time}** days and a recovery time of **{recovery_days}** days imply an $R_0$ of
84-
**{r_naught:.2f}**.
85-
84+
**{r_naught:.2f}** and daily growth rate of **{daily_growth:.2f}%**.
85+
8686
**Mitigation**: A **{relative_contact_rate:.0%}** reduction in social contact after the onset of the
87-
outbreak **{impact_statement:s} {doubling_time_t:.1f}** days, implying an effective $R_t$ of **${r_t:.2f}$**.
87+
outbreak **{impact_statement:s} {doubling_time_t:.1f}** days, implying an effective $R_t$ of **${r_t:.2f}$**
88+
and daily growth rate of **{daily_growth_t:.2f}%**.
8889
""".format(
8990
total_infections=m.infected,
9091
initial_infections=p.known_infected,
@@ -100,6 +101,8 @@ def display_header(st, m, p):
100101
r_t=m.r_t,
101102
doubling_time_t=abs(m.doubling_time_t),
102103
impact_statement=("halves the infections every" if m.r_t < 1 else "reduces the doubling time to"),
104+
daily_growth=m.daily_growth,
105+
daily_growth_t=m.daily_growth_t,
103106
docs_url=DOCS_URL,
104107
infection_warning_str=infection_warning_str,
105108
infected_population_warning_str=infected_population_warning_str

tests/test_app.py

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import altair as alt # type: ignore
99

1010
from src.penn_chime.charts import new_admissions_chart, admitted_patients_chart, chart_descriptions
11-
from src.penn_chime.models import SimSirModel, sir, sim_sir_df, build_admits_df
11+
from src.penn_chime.models import SimSirModel, sir, sim_sir_df, build_admits_df, daily_growth_helper
1212
from src.penn_chime.parameters import Parameters
1313
from src.penn_chime.presentation import display_header
1414
from src.penn_chime.settings import DEFAULTS
@@ -27,7 +27,21 @@
2727
n_days=60,
2828
)
2929

30+
HALVING_PARAM = Parameters(
31+
current_hospitalized=100,
32+
doubling_time=6.0,
33+
known_infected=5000,
34+
market_share=0.05,
35+
relative_contact_rate=0.7,
36+
susceptible=500000,
37+
hospitalized=RateLos(0.05, 7),
38+
icu=RateLos(0.02, 9),
39+
ventilated=RateLos(0.01, 10),
40+
n_days=60,
41+
)
42+
3043
MODEL = SimSirModel(PARAM)
44+
HALVING_MODEL = SimSirModel(HALVING_PARAM)
3145

3246

3347
# set up
@@ -58,46 +72,38 @@ def cleanup(self):
5872
# test presentation
5973

6074

75+
def header_test_helper(expected_str, model, param):
76+
st.cleanup()
77+
display_header(st, model, param)
78+
assert [s for s in st.render_store if expected_str in s],\
79+
"Expected the string '{expected}' in the display header".format(expected=expected_str)
80+
st.cleanup()
81+
82+
6183
def test_penn_logo_in_header():
6284
penn_css = '<link rel="stylesheet" href="https://www1.pennmedicine.org/styles/shared/penn-medicine-header.css">'
63-
display_header(st, MODEL, PARAM)
64-
assert len(
65-
list(filter(lambda s: penn_css in s, st.render_store))
66-
), "The Penn Medicine header should be printed"
85+
header_test_helper(penn_css, MODEL, PARAM)
6786

6887

6988
def test_the_rest_of_header_shows_up():
7089
random_part_of_header = "implying an effective $R_t$ of"
71-
assert len(
72-
list(filter(lambda s: random_part_of_header in s, st.render_store))
73-
), "The whole header should render"
90+
header_test_helper(random_part_of_header, MODEL, PARAM)
7491

7592

7693
def test_mitigation_statement():
77-
st.cleanup()
7894
expected_doubling = "outbreak **reduces the doubling time to 7.8** days"
79-
display_header(st, MODEL, PARAM)
80-
assert [s for s in st.render_store if expected_doubling in s]
81-
# assert len((list(filter(lambda s: expected_doubling in s, st.render_store))))
82-
st.cleanup()
8395
expected_halving = "outbreak **halves the infections every 51.9** days"
84-
halving_params = Parameters(
85-
current_hospitalized=100,
86-
doubling_time=6.0,
87-
known_infected=5000,
88-
market_share=0.05,
89-
relative_contact_rate=0.7,
90-
susceptible=500000,
91-
hospitalized=RateLos(0.05, 7),
92-
icu=RateLos(0.02, 9),
93-
ventilated=RateLos(0.01, 10),
94-
n_days=60,
95-
)
96-
halving_model = SimSirModel(halving_params)
97-
display_header(st, halving_model, halving_params)
98-
assert [s for s in st.render_store if expected_halving in s]
99-
#assert len((list(filter(lambda s: expected_halving in s, st.render_store))))
100-
st.cleanup()
96+
header_test_helper(expected_doubling, MODEL, PARAM)
97+
header_test_helper(expected_halving, HALVING_MODEL, HALVING_PARAM)
98+
99+
100+
def test_daily_growth_presentation():
101+
initial_growth = "and daily growth rate of **12.25%**."
102+
mitigated_growth = "and daily growth rate of **9.34%**."
103+
mitigated_halving = "and daily growth rate of **-1.33%**."
104+
header_test_helper(initial_growth, MODEL, PARAM)
105+
header_test_helper(mitigated_growth, MODEL, PARAM)
106+
header_test_helper(mitigated_halving, HALVING_MODEL, HALVING_PARAM)
101107

102108

103109
st.cleanup()
@@ -262,6 +268,12 @@ def test_model(model=MODEL, param=PARAM):
262268
assert (diff.abs() < 0.1).all()
263269

264270

271+
def test_daily_growth_helper():
272+
assert np.round(daily_growth_helper(5), decimals=4) == 14.8698
273+
assert np.round(daily_growth_helper(0), decimals=4) == 0.0
274+
assert np.round(daily_growth_helper(-4), decimals=4) == -15.9104
275+
276+
265277
def test_chart_descriptions(p=PARAM):
266278
# new admissions chart
267279
projection_admits = pd.read_csv('tests/projection_admits.csv')

0 commit comments

Comments
 (0)