|
8 | 8 | import altair as alt # type: ignore
|
9 | 9 |
|
10 | 10 | 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 |
12 | 12 | from src.penn_chime.parameters import Parameters
|
13 | 13 | from src.penn_chime.presentation import display_header
|
14 | 14 | from src.penn_chime.settings import DEFAULTS
|
|
27 | 27 | n_days=60,
|
28 | 28 | )
|
29 | 29 |
|
| 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 | + |
30 | 43 | MODEL = SimSirModel(PARAM)
|
| 44 | +HALVING_MODEL = SimSirModel(HALVING_PARAM) |
31 | 45 |
|
32 | 46 |
|
33 | 47 | # set up
|
@@ -58,46 +72,38 @@ def cleanup(self):
|
58 | 72 | # test presentation
|
59 | 73 |
|
60 | 74 |
|
| 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 | + |
61 | 83 | def test_penn_logo_in_header():
|
62 | 84 | 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) |
67 | 86 |
|
68 | 87 |
|
69 | 88 | def test_the_rest_of_header_shows_up():
|
70 | 89 | 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) |
74 | 91 |
|
75 | 92 |
|
76 | 93 | def test_mitigation_statement():
|
77 |
| - st.cleanup() |
78 | 94 | 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() |
83 | 95 | 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) |
101 | 107 |
|
102 | 108 |
|
103 | 109 | st.cleanup()
|
@@ -262,6 +268,12 @@ def test_model(model=MODEL, param=PARAM):
|
262 | 268 | assert (diff.abs() < 0.1).all()
|
263 | 269 |
|
264 | 270 |
|
| 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 | + |
265 | 277 | def test_chart_descriptions(p=PARAM):
|
266 | 278 | # new admissions chart
|
267 | 279 | projection_admits = pd.read_csv('tests/projection_admits.csv')
|
|
0 commit comments