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