Skip to content

Commit cdf05b0

Browse files
author
Eric Smyth
committed
- Adds daily_growth and daily_growth_t instance attributes on Parameters class.
- Adds `daily_growth_helper` function to `src/penn_chime/parameters.py` to calculate daily growth rate as a function of doubling time. - Updates `display_header` function in `src/penn_chime/presentation.py` to display initial and mitigated daily growth rates. - Adds `test_daily_growth` test to `tests/test_app.py` to test above changes Fixes #90
1 parent 1ecdff6 commit cdf05b0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/penn_chime/parameters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
`change_date`, so users can see when results have last changed
55
"""
66

7-
from numpy import log2 # type: ignore
7+
from numpy import log2, power # type: ignore
88

99
from .utils import RateLos
1010
from .models import (
@@ -13,6 +13,10 @@
1313
)
1414

1515

16+
def daily_growth_helper(doubling_time):
17+
return (power(2, 1.0 / doubling_time) - 1) * 100
18+
19+
1620
class Parameters:
1721
def __init__(
1822
self,
@@ -98,6 +102,9 @@ def __init__(
98102
if n_days is not None:
99103
self.n_days = n_days
100104

105+
self.daily_growth = daily_growth_helper(self.doubling_time)
106+
self.daily_growth_t = power(2, 1.9 / self.doubling_time_t)
107+
101108
@property
102109
def n_days(self):
103110
return self._n_days

src/penn_chime/presentation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ def display_header(st, p):
6060
and Hospital market share (**{market_share:.0%}**).
6161
6262
An initial doubling time of **{doubling_time}** days and a recovery time of **{recovery_days}** days imply an $R_0$ of
63-
**{r_naught:.2f}**.
63+
**{r_naught:.2f}** and daily growth rate of **{daily_growth:.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 reduces the doubling time to **{doubling_time_t:.1f}** days, implying an effective $R_t$ of **${r_t:.2f}$**
67+
and daily growth rate of **{daily_growth_t:.2f}%**.
6768
""".format(
6869
total_infections=p.infected,
6970
initial_infections=p.known_infected,
@@ -78,6 +79,8 @@ def display_header(st, p):
7879
relative_contact_rate=p.relative_contact_rate,
7980
r_t=p.r_t,
8081
doubling_time_t=p.doubling_time_t,
82+
daily_growth=p.daily_growth,
83+
daily_growth_t=p.daily_growth_t,
8184
)
8285
)
8386

tests/test_app.py

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

7373

74+
def test_daily_growth():
75+
st.cleanup()
76+
initial_growth = "and daily growth rate of **12.25%**."
77+
mitigated_growth = "and daily growth rate of **1.18%**."
78+
display_header(st, PARAM)
79+
assert len((list(filter(lambda s: initial_growth in s, st.render_store))))
80+
assert len((list(filter(lambda s: mitigated_growth in s, st.render_store))))
81+
st.cleanup()
82+
83+
7484
st.cleanup()
7585

7686

0 commit comments

Comments
 (0)