Skip to content

Commit 5a0abfa

Browse files
author
Eric Smyth
committed
- Changed display_header in src/penn_chime/presentation.py so mitigation
text for values of `Rt < 1` mention halving (vs doubling) and report a positive unit of time. - Changed `tests/test_app.py` to add `test_mitigation_statement` to test `Rt` values `>= 1` are described as doubling and `< 1` is described as halving. Fixes #155
1 parent 86e170e commit 5a0abfa

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/penn_chime/presentation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def display_header(st, p):
6363
**{r_naught:.2f}**.
6464
6565
**Mitigation**: A **{relative_contact_rate:.0%}** reduction in social contact after the onset of the
66-
outbreak reduces the doubling time to **{doubling_time_t:.1f}** days, implying an effective $R_t$ of **${r_t:.2f}$**.
66+
outbreak **{impact_statement:s} {doubling_time_t:.1f}** days, implying an effective $R_t$ of **${r_t:.2f}$**.
6767
""".format(
6868
total_infections=p.infected,
6969
initial_infections=p.known_infected,
@@ -77,7 +77,8 @@ def display_header(st, p):
7777
doubling_time=p.doubling_time,
7878
relative_contact_rate=p.relative_contact_rate,
7979
r_t=p.r_t,
80-
doubling_time_t=p.doubling_time_t,
80+
doubling_time_t=abs(p.doubling_time_t),
81+
impact_statement=("halves the infections every" if p.r_t < 1 else "reduces the doubling time to")
8182
)
8283
)
8384

tests/test_app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ def test_the_rest_of_header_shows_up():
7171
), "The whole header should render"
7272

7373

74+
def test_mitigation_statement():
75+
st.cleanup()
76+
expected_doubling = "outbreak **reduces the doubling time to 7.8** days"
77+
display_header(st, PARAM)
78+
assert len((list(filter(lambda s: expected_doubling in s, st.render_store))))
79+
st.cleanup()
80+
expected_halving = "outbreak **halves the infections every 51.9** days"
81+
halving_params = Parameters(
82+
current_hospitalized=100,
83+
doubling_time=6.0,
84+
known_infected=5000,
85+
market_share=0.05,
86+
relative_contact_rate=0.7,
87+
susceptible=500000,
88+
hospitalized=RateLos(0.05, 7),
89+
icu=RateLos(0.02, 9),
90+
ventilated=RateLos(0.01, 10),
91+
n_days=60,
92+
)
93+
display_header(st, halving_params)
94+
assert len((list(filter(lambda s: expected_halving in s, st.render_store))))
95+
st.cleanup()
96+
97+
7498
st.cleanup()
7599

76100

0 commit comments

Comments
 (0)