@@ -116,7 +116,7 @@ def display_header(st, m, p):
116
116
return None
117
117
118
118
119
- class InputWrapper :
119
+ class Input :
120
120
"""Helper to separate Streamlit input definition from creation/rendering"""
121
121
def __init__ (self , st_obj , label , value , kwargs ):
122
122
self .st_obj = st_obj
@@ -128,17 +128,25 @@ def __call__(self):
128
128
return self .st_obj (self .label , value = self .value , ** self .kwargs )
129
129
130
130
131
- class NumberInputWrapper ( InputWrapper ):
131
+ class NumberInput ( Input ):
132
132
def __init__ (self , st_obj , label , min_value = None , max_value = None , value = None , step = None , format = None , key = None ):
133
133
kwargs = dict (min_value = min_value , max_value = max_value , step = step , format = format , key = key )
134
134
super ().__init__ (st_obj .number_input , label , value , kwargs )
135
135
136
- class DateInputWrapper ( InputWrapper ):
136
+ class DateInput ( Input ):
137
137
def __init__ (self , st_obj , label , value = None , key = None ):
138
138
kwargs = dict (key = key )
139
139
super ().__init__ (st_obj .date_input , label , value , kwargs )
140
140
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 ):
142
150
def __init__ (self , st_obj , label , value = None , key = None ):
143
151
kwargs = dict (key = key )
144
152
super ().__init__ (st_obj .checkbox , label , value , kwargs )
@@ -153,145 +161,127 @@ def display_sidebar(st, d: Constants) -> Parameters:
153
161
if d .known_infected < 1 :
154
162
raise ValueError ("Known cases must be larger than one to enable predictions." )
155
163
st_obj = st .sidebar
156
- current_hospitalized_input = NumberInputWrapper (
164
+ current_hospitalized_input = NumberInput (
157
165
st_obj ,
158
166
"Currently Hospitalized COVID-19 Patients" ,
159
167
min_value = 0 ,
160
168
value = d .current_hospitalized ,
161
169
step = 1 ,
162
170
format = "%i" ,
163
171
)
164
- n_days_input = NumberInputWrapper (
172
+ n_days_input = NumberInput (
165
173
st_obj ,
166
174
"Number of days to project" ,
167
175
min_value = 30 ,
168
176
value = d .n_days ,
169
177
step = 1 ,
170
178
format = "%i" ,
171
179
)
172
- doubling_time_input = NumberInputWrapper (
180
+ doubling_time_input = NumberInput (
173
181
st_obj ,
174
182
"Doubling time before social distancing (days)" ,
175
183
min_value = FLOAT_INPUT_MIN ,
176
184
value = d .doubling_time ,
177
185
step = FLOAT_INPUT_STEP ,
178
186
format = "%f" ,
179
187
)
180
- date_first_hospitalized_input = DateInputWrapper (
188
+ date_first_hospitalized_input = DateInput (
181
189
st_obj ,
182
190
"Date of first hospitalized case" ,
183
191
value = d .date_first_hospitalized ,
184
192
)
185
- relative_contact_rate_input = NumberInputWrapper (
193
+ relative_contact_pct_input = PercentInput (
186
194
st_obj ,
187
195
"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 ,
193
197
)
194
- hospitalized_rate_input = NumberInputWrapper (
198
+ hospitalized_pct_input = PercentInput (
195
199
st_obj ,
196
200
"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 ,
202
202
)
203
- icu_rate_input = NumberInputWrapper (
203
+ icu_pct_input = PercentInput (
204
204
st_obj ,
205
205
"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 ,
211
207
)
212
- ventilated_rate_input = NumberInputWrapper (
208
+ ventilated_pct_input = PercentInput (
213
209
st_obj ,
214
210
"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 ,
220
212
)
221
- hospitalized_los_input = NumberInputWrapper (
213
+ hospitalized_los_input = NumberInput (
222
214
st_obj ,
223
215
"Hospital Length of Stay" ,
224
216
min_value = 0 ,
225
217
value = d .hospitalized .length_of_stay ,
226
218
step = 1 ,
227
219
format = "%i" ,
228
220
)
229
- icu_los_input = NumberInputWrapper (
221
+ icu_los_input = NumberInput (
230
222
st_obj ,
231
223
"ICU Length of Stay" ,
232
224
min_value = 0 ,
233
225
value = d .icu .length_of_stay ,
234
226
step = 1 ,
235
227
format = "%i" ,
236
228
)
237
- ventilated_los_input = NumberInputWrapper (
229
+ ventilated_los_input = NumberInput (
238
230
st_obj ,
239
231
"Vent Length of Stay" ,
240
232
min_value = 0 ,
241
233
value = d .ventilated .length_of_stay ,
242
234
step = 1 ,
243
235
format = "%i" ,
244
236
)
245
- market_share_input = NumberInputWrapper (
237
+ market_share_pct_input = PercentInput (
246
238
st_obj ,
247
239
"Hospital Market Share (%)" ,
248
240
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 ,
253
242
)
254
- population_input = NumberInputWrapper (
243
+ population_input = NumberInput (
255
244
st_obj ,
256
245
"Regional Population" ,
257
246
min_value = 1 ,
258
247
value = d .region .population ,
259
248
step = 1 ,
260
249
format = "%i" ,
261
250
)
262
- known_infected_input = NumberInputWrapper (
251
+ known_infected_input = NumberInput (
263
252
st_obj ,
264
253
"Currently Known Regional Infections (only used to compute detection rate - does not change projections)" ,
265
254
min_value = 0 ,
266
255
value = d .known_infected ,
267
256
step = 1 ,
268
257
format = "%i" ,
269
258
)
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 )
273
262
274
263
# Build in desired order
275
264
st .sidebar .markdown ("### Regional Parameters [ℹ]({docs_url}/what-is-chime/parameters)" .format (docs_url = DOCS_URL ))
276
265
population = population_input ()
277
- market_share = market_share_input ()
266
+ market_share = market_share_pct_input ()
278
267
known_infected = known_infected_input ()
279
268
current_hospitalized = current_hospitalized_input ()
280
269
281
270
st .sidebar .markdown ("### Spread and Contact Parameters [ℹ]({docs_url}/what-is-chime/parameters)"
282
271
.format (docs_url = DOCS_URL ))
272
+
283
273
if st .sidebar .checkbox ("I know the date of the first hospitalized case in the region." ):
284
274
date_first_hospitalized = date_first_hospitalized_input ()
285
275
doubling_time = None
286
276
else :
287
277
date_first_hospitalized = None
288
278
doubling_time = doubling_time_input ()
289
- relative_contact_rate = relative_contact_rate_input ()
279
+ relative_contact_rate = relative_contact_pct_input ()
290
280
291
281
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 ()
295
285
hospitalized_los = hospitalized_los_input ()
296
286
icu_los = icu_los_input ()
297
287
ventilated_los = ventilated_los_input ()
@@ -308,19 +298,19 @@ def display_sidebar(st, d: Constants) -> Parameters:
308
298
return Parameters (
309
299
as_date = as_date ,
310
300
current_hospitalized = current_hospitalized ,
311
- market_share = market_share / 100.0 ,
301
+ market_share = market_share ,
312
302
known_infected = known_infected ,
313
303
doubling_time = doubling_time ,
314
304
date_first_hospitalized = date_first_hospitalized ,
315
305
316
306
max_y_axis = max_y_axis ,
317
307
n_days = n_days ,
318
- relative_contact_rate = relative_contact_rate / 100.0 ,
308
+ relative_contact_rate = relative_contact_rate ,
319
309
population = population ,
320
310
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 ),
324
314
)
325
315
326
316
0 commit comments