Skip to content

Commit 8e7f8e9

Browse files
Merge branch 'quinn_issue_255' of https://github.com/CodeForPhilly/chime into quinn_issue_255
2 parents 490fa2d + ecf51ee commit 8e7f8e9

File tree

1 file changed

+45
-55
lines changed

1 file changed

+45
-55
lines changed

src/penn_chime/presentation.py

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def display_header(st, m, p):
116116
return None
117117

118118

119-
class InputWrapper:
119+
class Input:
120120
"""Helper to separate Streamlit input definition from creation/rendering"""
121121
def __init__(self, st_obj, label, value, kwargs):
122122
self.st_obj = st_obj
@@ -128,17 +128,25 @@ def __call__(self):
128128
return self.st_obj(self.label, value=self.value, **self.kwargs)
129129

130130

131-
class NumberInputWrapper(InputWrapper):
131+
class NumberInput(Input):
132132
def __init__(self, st_obj, label, min_value=None, max_value=None, value=None, step=None, format=None, key=None):
133133
kwargs = dict(min_value=min_value, max_value=max_value, step=step, format=format, key=key)
134134
super().__init__(st_obj.number_input, label, value, kwargs)
135135

136-
class DateInputWrapper(InputWrapper):
136+
class DateInput(Input):
137137
def __init__(self, st_obj, label, value=None, key=None):
138138
kwargs = dict(key=key)
139139
super().__init__(st_obj.date_input, label, value, kwargs)
140140

141-
class CheckboxWrapper(InputWrapper):
141+
class PercentInput(NumberInput):
142+
def __init__(self, st_obj, label, min_value=0.0, max_value=100.0, value=None, step=FLOAT_INPUT_STEP, format="%f", key=None):
143+
super().__init__(st_obj, label, min_value, max_value, value * 100.0, step, format, key)
144+
145+
def __call__(self):
146+
return super().__call__() / 100.0
147+
148+
149+
class CheckboxInput(Input):
142150
def __init__(self, st_obj, label, value=None, key=None):
143151
kwargs = dict(key=key)
144152
super().__init__(st_obj.checkbox, label, value, kwargs)
@@ -153,145 +161,127 @@ def display_sidebar(st, d: Constants) -> Parameters:
153161
if d.known_infected < 1:
154162
raise ValueError("Known cases must be larger than one to enable predictions.")
155163
st_obj = st.sidebar
156-
current_hospitalized_input = NumberInputWrapper(
164+
current_hospitalized_input = NumberInput(
157165
st_obj,
158166
"Currently Hospitalized COVID-19 Patients",
159167
min_value=0,
160168
value=d.current_hospitalized,
161169
step=1,
162170
format="%i",
163171
)
164-
n_days_input = NumberInputWrapper(
172+
n_days_input = NumberInput(
165173
st_obj,
166174
"Number of days to project",
167175
min_value=30,
168176
value=d.n_days,
169177
step=1,
170178
format="%i",
171179
)
172-
doubling_time_input = NumberInputWrapper(
180+
doubling_time_input = NumberInput(
173181
st_obj,
174182
"Doubling time before social distancing (days)",
175183
min_value=FLOAT_INPUT_MIN,
176184
value=d.doubling_time,
177185
step=FLOAT_INPUT_STEP,
178186
format="%f",
179187
)
180-
date_first_hospitalized_input = DateInputWrapper(
188+
date_first_hospitalized_input = DateInput(
181189
st_obj,
182190
"Date of first hospitalized case",
183191
value=d.date_first_hospitalized,
184192
)
185-
relative_contact_rate_input = NumberInputWrapper(
193+
relative_contact_pct_input = PercentInput(
186194
st_obj,
187195
"Social distancing (% reduction in social contact)",
188-
min_value=0.0,
189-
max_value=100.0,
190-
value=d.relative_contact_rate * 100.0,
191-
step=FLOAT_INPUT_STEP,
192-
format="%f",
196+
value=d.relative_contact_rate,
193197
)
194-
hospitalized_rate_input = NumberInputWrapper(
198+
hospitalized_pct_input = PercentInput(
195199
st_obj,
196200
"Hospitalization %(total infections)",
197-
min_value=0.0,
198-
max_value=100.0,
199-
value=d.hospitalized.rate * 100,
200-
step=FLOAT_INPUT_STEP,
201-
format="%f",
201+
value=d.hospitalized.rate,
202202
)
203-
icu_rate_input = NumberInputWrapper(
203+
icu_pct_input = PercentInput(
204204
st_obj,
205205
"ICU %(total infections)",
206-
min_value=0.0,
207-
max_value=100.0,
208-
value=d.icu.rate * 100,
209-
step=FLOAT_INPUT_STEP,
210-
format="%f",
206+
value=d.icu.rate,
211207
)
212-
ventilated_rate_input = NumberInputWrapper(
208+
ventilated_pct_input = PercentInput(
213209
st_obj,
214210
"Ventilated %(total infections)",
215-
min_value=0.0,
216-
max_value=100.0,
217-
value=d.ventilated.rate * 100,
218-
step=FLOAT_INPUT_STEP,
219-
format="%f",
211+
value=d.ventilated.rate,
220212
)
221-
hospitalized_los_input = NumberInputWrapper(
213+
hospitalized_los_input = NumberInput(
222214
st_obj,
223215
"Hospital Length of Stay",
224216
min_value=0,
225217
value=d.hospitalized.length_of_stay,
226218
step=1,
227219
format="%i",
228220
)
229-
icu_los_input = NumberInputWrapper(
221+
icu_los_input = NumberInput(
230222
st_obj,
231223
"ICU Length of Stay",
232224
min_value=0,
233225
value=d.icu.length_of_stay,
234226
step=1,
235227
format="%i",
236228
)
237-
ventilated_los_input = NumberInputWrapper(
229+
ventilated_los_input = NumberInput(
238230
st_obj,
239231
"Vent Length of Stay",
240232
min_value=0,
241233
value=d.ventilated.length_of_stay,
242234
step=1,
243235
format="%i",
244236
)
245-
market_share_input = NumberInputWrapper(
237+
market_share_pct_input = PercentInput(
246238
st_obj,
247239
"Hospital Market Share (%)",
248240
min_value=FLOAT_INPUT_MIN,
249-
max_value=100.0,
250-
value=d.market_share * 100,
251-
step=FLOAT_INPUT_STEP,
252-
format="%f",
241+
value=d.market_share,
253242
)
254-
population_input = NumberInputWrapper(
243+
population_input = NumberInput(
255244
st_obj,
256245
"Regional Population",
257246
min_value=1,
258247
value=d.region.population,
259248
step=1,
260249
format="%i",
261250
)
262-
known_infected_input = NumberInputWrapper(
251+
known_infected_input = NumberInput(
263252
st_obj,
264253
"Currently Known Regional Infections (only used to compute detection rate - does not change projections)",
265254
min_value=0,
266255
value=d.known_infected,
267256
step=1,
268257
format="%i",
269258
)
270-
as_date_input = CheckboxWrapper(st_obj, "Present result as dates instead of days", value=False)
271-
max_y_axis_set_input = CheckboxWrapper(st_obj, "Set the Y-axis on graphs to a static value")
272-
max_y_axis_input = NumberInputWrapper(st_obj, "Y-axis static value", value=500, format="%i", step=25)
259+
as_date_input = CheckboxInput(st_obj, "Present result as dates instead of days", value=False)
260+
max_y_axis_set_input = CheckboxInput(st_obj, "Set the Y-axis on graphs to a static value")
261+
max_y_axis_input = NumberInput(st_obj, "Y-axis static value", value=500, format="%i", step=25)
273262

274263
# Build in desired order
275264
st.sidebar.markdown("### Regional Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
276265
population = population_input()
277-
market_share = market_share_input()
266+
market_share = market_share_pct_input()
278267
known_infected = known_infected_input()
279268
current_hospitalized = current_hospitalized_input()
280269

281270
st.sidebar.markdown("### Spread and Contact Parameters [ℹ]({docs_url}/what-is-chime/parameters)"
282271
.format(docs_url=DOCS_URL))
272+
283273
if st.sidebar.checkbox("I know the date of the first hospitalized case in the region."):
284274
date_first_hospitalized = date_first_hospitalized_input()
285275
doubling_time = None
286276
else:
287277
date_first_hospitalized = None
288278
doubling_time = doubling_time_input()
289-
relative_contact_rate = relative_contact_rate_input()
279+
relative_contact_rate = relative_contact_pct_input()
290280

291281
st.sidebar.markdown("### Severity Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
292-
hospitalized_rate = hospitalized_rate_input()
293-
icu_rate = icu_rate_input()
294-
ventilated_rate = ventilated_rate_input()
282+
hospitalized_rate = hospitalized_pct_input()
283+
icu_rate = icu_pct_input()
284+
ventilated_rate = ventilated_pct_input()
295285
hospitalized_los = hospitalized_los_input()
296286
icu_los = icu_los_input()
297287
ventilated_los = ventilated_los_input()
@@ -308,19 +298,19 @@ def display_sidebar(st, d: Constants) -> Parameters:
308298
return Parameters(
309299
as_date=as_date,
310300
current_hospitalized=current_hospitalized,
311-
market_share=market_share / 100.0,
301+
market_share=market_share,
312302
known_infected=known_infected,
313303
doubling_time=doubling_time,
314304
date_first_hospitalized=date_first_hospitalized,
315305

316306
max_y_axis=max_y_axis,
317307
n_days=n_days,
318-
relative_contact_rate=relative_contact_rate / 100.0,
308+
relative_contact_rate=relative_contact_rate,
319309
population=population,
320310

321-
hospitalized=RateLos(hospitalized_rate / 100.0, hospitalized_los),
322-
icu=RateLos(icu_rate / 100.0, icu_los),
323-
ventilated=RateLos(ventilated_rate / 100.0, ventilated_los),
311+
hospitalized=RateLos(hospitalized_rate, hospitalized_los),
312+
icu=RateLos(icu_rate, icu_los),
313+
ventilated=RateLos(ventilated_rate, ventilated_los),
324314
)
325315

326316

0 commit comments

Comments
 (0)