Skip to content

Commit 256f19c

Browse files
Merge pull request #271 from CodeForPhilly/fix_inputs
Fix inputs
2 parents 224120f + bffa5c0 commit 256f19c

File tree

2 files changed

+59
-57
lines changed

2 files changed

+59
-57
lines changed

src/penn_chime/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def __init__(self, p: Parameters) -> SimSirModel:
6363
# self.r_naught = r_t / (1.0 - relative_contact_rate)
6464
r_naught = (intrinsic_growth_rate + gamma) / gamma
6565
doubling_time_t = 1.0 / np.log2(
66-
beta * p.susceptible - gamma + 1)
66+
beta * susceptible - gamma + 1)
6767

6868
raw_df = sim_sir_df(
69-
p.susceptible,
69+
susceptible,
7070
infected,
7171
recovered,
7272
beta,
@@ -174,7 +174,7 @@ def build_census_df(
174174
}
175175
})
176176

177-
177+
178178
def daily_growth_helper(doubling_time):
179179
"""Calculates average daily growth rate from doubling time"""
180180
result = 0

src/penn_chime/presentation.py

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def display_header(st, m, p):
6464
)
6565
st.markdown(
6666
"""*This tool was developed by the [Predictive Healthcare team](http://predictivehealthcare.pennmedicine.org/) at
67-
Penn Medicine to assist hospitals and public health officials with hospital capacity planning,
68-
but can be used anywhere in the world.
67+
Penn Medicine to assist hospitals and public health officials with hospital capacity planning,
68+
but can be used anywhere in the world.
6969
Customize it for your region by modifying data inputs in the left panel.
7070
For questions on how to use this tool see the [User docs]({docs_url}). Code can be found on [Github](https://github.com/CodeForPhilly/chime)*.
7171
""".format(docs_url=DOCS_URL)
@@ -76,15 +76,15 @@ def display_header(st, m, p):
7676
confirmed cases in the region imply a **{detection_prob_str}** rate of detection. This is based on current inputs for
7777
Hospitalizations (**{current_hosp}**), Hospitalization rate (**{hosp_rate:.0%}**), Region size (**{S}**),
7878
and Hospital market share (**{market_share:.0%}**).
79-
80-
{infection_warning_str}
79+
80+
{infection_warning_str}
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}** and daily growth rate of **{daily_growth:.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}$**
8888
and daily growth rate of **{daily_growth_t:.2f}%**.
8989
""".format(
9090
total_infections=m.infected,
@@ -120,7 +120,7 @@ def __init__(self, st_obj, label, value, kwargs):
120120
self.value = value
121121
self.kwargs = kwargs
122122

123-
def build(self):
123+
def __call__(self):
124124
return self.st_obj(self.label, value=self.value, **self.kwargs)
125125

126126

@@ -145,31 +145,31 @@ def display_sidebar(st, d: Constants) -> Parameters:
145145
if d.known_infected < 1:
146146
raise ValueError("Known cases must be larger than one to enable predictions.")
147147
st_obj = st.sidebar
148-
current_hospitalized = NumberInputWrapper(
148+
current_hospitalized_input = NumberInputWrapper(
149149
st_obj,
150150
"Currently Hospitalized COVID-19 Patients",
151151
min_value=0,
152152
value=d.current_hospitalized,
153153
step=1,
154154
format="%i",
155155
)
156-
n_days = NumberInputWrapper(
156+
n_days_input = NumberInputWrapper(
157157
st_obj,
158158
"Number of days to project",
159159
min_value=30,
160160
value=d.n_days,
161161
step=10,
162162
format="%i",
163163
)
164-
doubling_time = NumberInputWrapper(
164+
doubling_time_input = NumberInputWrapper(
165165
st_obj,
166166
"Doubling time before social distancing (days)",
167167
min_value=0,
168168
value=d.doubling_time,
169169
step=1,
170170
format="%i",
171171
)
172-
relative_contact_rate = NumberInputWrapper(
172+
relative_contact_rate_input = NumberInputWrapper(
173173
st_obj,
174174
"Social distancing (% reduction in social contact)",
175175
min_value=0,
@@ -178,7 +178,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
178178
step=5,
179179
format="%i",
180180
)
181-
hospitalized_rate = NumberInputWrapper(
181+
hospitalized_rate_input = NumberInputWrapper(
182182
st_obj,
183183
"Hospitalization %(total infections)",
184184
min_value=0.001,
@@ -187,7 +187,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
187187
step=1.0,
188188
format="%f",
189189
)
190-
icu_rate = NumberInputWrapper(
190+
icu_rate_input = NumberInputWrapper(
191191
st_obj,
192192
"ICU %(total infections)",
193193
min_value=0.0,
@@ -196,7 +196,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
196196
step=1.0,
197197
format="%f",
198198
)
199-
ventilated_rate = NumberInputWrapper(
199+
ventilated_rate_input = NumberInputWrapper(
200200
st_obj,
201201
"Ventilated %(total infections)",
202202
min_value=0.0,
@@ -205,31 +205,31 @@ def display_sidebar(st, d: Constants) -> Parameters:
205205
step=1.0,
206206
format="%f",
207207
)
208-
hospitalized_los = NumberInputWrapper(
208+
hospitalized_los_input = NumberInputWrapper(
209209
st_obj,
210210
"Hospital Length of Stay",
211211
min_value=0,
212212
value=d.hospitalized.length_of_stay,
213213
step=1,
214214
format="%i",
215215
)
216-
icu_los = NumberInputWrapper(
216+
icu_los_input = NumberInputWrapper(
217217
st_obj,
218218
"ICU Length of Stay",
219219
min_value=0,
220220
value=d.icu.length_of_stay,
221221
step=1,
222222
format="%i",
223223
)
224-
ventilated_los = NumberInputWrapper(
224+
ventilated_los_input = NumberInputWrapper(
225225
st_obj,
226226
"Vent Length of Stay",
227227
min_value=0,
228228
value=d.ventilated.length_of_stay,
229229
step=1,
230230
format="%i",
231231
)
232-
market_share = NumberInputWrapper(
232+
market_share_input = NumberInputWrapper(
233233
st_obj,
234234
"Hospital Market Share (%)",
235235
min_value=0.001,
@@ -238,69 +238,71 @@ def display_sidebar(st, d: Constants) -> Parameters:
238238
step=1.0,
239239
format="%f",
240240
)
241-
susceptible = NumberInputWrapper(
241+
susceptible_input = NumberInputWrapper(
242242
st_obj,
243243
"Regional Population",
244244
min_value=1,
245245
value=d.region.susceptible,
246246
step=100000,
247247
format="%i",
248248
)
249-
known_infected = NumberInputWrapper(
249+
known_infected_input = NumberInputWrapper(
250250
st_obj,
251251
"Currently Known Regional Infections (only used to compute detection rate - does not change projections)",
252252
min_value=0,
253253
value=d.known_infected,
254254
step=10,
255255
format="%i",
256256
)
257-
as_date = CheckboxWrapper(st_obj, "Present result as dates instead of days", value=False)
258-
max_y_axis_set = CheckboxWrapper(st_obj, "Set the Y-axis on graphs to a static value")
257+
as_date_input = CheckboxWrapper(st_obj, "Present result as dates instead of days", value=False)
258+
max_y_axis_set_input = CheckboxWrapper(st_obj, "Set the Y-axis on graphs to a static value")
259+
max_y_axis_input = NumberInputWrapper(st_obj, "Y-axis static value", value=500, format="%i", step=25)
259260

260-
max_y_axis = None
261-
if max_y_axis_set:
262-
max_y_axis = NumberInputWrapper(st_obj, "Y-axis static value", value=500, format="%i", step=25)
263261

264262
# Build in desired order
265263
st.sidebar.markdown("### Regional Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
266-
susceptible.build()
267-
market_share.build()
268-
known_infected.build()
269-
current_hospitalized.build()
264+
susceptible = susceptible_input()
265+
market_share = market_share_input()
266+
known_infected = known_infected_input()
267+
current_hospitalized = current_hospitalized_input()
270268

271269
st.sidebar.markdown("### Spread and Contact Parameters [ℹ]({docs_url}/what-is-chime/parameters)"
272270
.format(docs_url=DOCS_URL))
273-
doubling_time.build()
274-
relative_contact_rate.build()
271+
doubling_time = doubling_time_input()
272+
relative_contact_rate = relative_contact_rate_input()
275273

276274
st.sidebar.markdown("### Severity Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
277-
hospitalized_rate.build()
278-
icu_rate.build()
279-
ventilated_rate.build()
280-
hospitalized_los.build()
281-
icu_los.build()
282-
ventilated_los.build()
275+
hospitalized_rate = hospitalized_rate_input()
276+
icu_rate = icu_rate_input()
277+
ventilated_rate = ventilated_rate_input()
278+
hospitalized_los = hospitalized_los_input()
279+
icu_los = icu_los_input()
280+
ventilated_los = ventilated_los_input()
283281

284282
st.sidebar.markdown("### Display Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
285-
n_days.build()
286-
max_y_axis.build()
287-
as_date.build()
283+
n_days = n_days_input()
284+
max_y_axis_set = max_y_axis_set_input()
285+
as_date = as_date_input()
286+
287+
max_y_axis = None
288+
if max_y_axis_set:
289+
max_y_axis = max_y_axis_input()
288290

289291
return Parameters(
290-
as_date=as_date.value,
291-
current_hospitalized=current_hospitalized.value,
292-
market_share=market_share.value,
293-
known_infected=known_infected.value,
294-
doubling_time=doubling_time.value,
292+
as_date=as_date,
293+
current_hospitalized=current_hospitalized,
294+
market_share=market_share,
295+
known_infected=known_infected,
296+
doubling_time=doubling_time,
295297

296-
max_y_axis=max_y_axis.value,
297-
n_days=n_days.value,
298-
relative_contact_rate=relative_contact_rate.value / 100.0,
299-
susceptible=susceptible.value,
298+
max_y_axis=max_y_axis,
299+
n_days=n_days,
300+
relative_contact_rate=relative_contact_rate / 100.0,
301+
susceptible=susceptible,
300302

301-
hospitalized=RateLos(hospitalized_rate.value / 100.0, hospitalized_los.value),
302-
icu=RateLos(icu_rate.value / 100.0, icu_los.value),
303-
ventilated=RateLos(ventilated_rate.value / 100.0, ventilated_los.value),
303+
hospitalized=RateLos(hospitalized_rate/ 100.0, hospitalized_los),
304+
icu=RateLos(icu_rate/ 100.0, icu_los),
305+
ventilated=RateLos(ventilated_rate/ 100.0, ventilated_los),
304306
)
305307

306308

@@ -408,7 +410,7 @@ def show_more_info_about_this_tool(st, model, parameters, defaults, notes: str =
408410
def write_definitions(st):
409411
st.subheader("Guidance on Selecting Inputs")
410412
st.markdown(
411-
"""**This information has been moved to the
413+
"""**This information has been moved to the
412414
[User Documentation]({docs_url}/what-is-chime/parameters#guidance-on-selecting-inputs)**""".format(docs_url=DOCS_URL)
413415
)
414416

0 commit comments

Comments
 (0)