Skip to content

Commit 0a708f8

Browse files
author
Eric Smyth
committed
Fixes for issue 269
* Updated min value and step for most number inputs. * Updated format for float inputs to display as float instead of as int. Cleanup * Removed unused imports
1 parent ef0854a commit 0a708f8

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/penn_chime/presentation.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""effectful functions for streamlit io"""
22

3-
from typing import Optional
4-
5-
import altair as alt # type: ignore
63
import numpy as np # type: ignore
74
import pandas as pd # type: ignore
85

@@ -13,6 +10,9 @@
1310
DATE_FORMAT = "%b, %d" # see https://strftime.org
1411
DOCS_URL = "https://code-for-philly.gitbook.io/chime"
1512

13+
FLOAT_INPUT_MIN = 0.001
14+
FLOAT_INPUT_STEP = FLOAT_INPUT_MIN
15+
1616
hide_menu_style = """
1717
<style>
1818
#MainMenu {visibility: hidden;}
@@ -158,33 +158,33 @@ def display_sidebar(st, d: Constants) -> Parameters:
158158
"Number of days to project",
159159
min_value=30,
160160
value=d.n_days,
161-
step=10,
161+
step=1,
162162
format="%i",
163163
)
164164
doubling_time_input = NumberInputWrapper(
165165
st_obj,
166166
"Doubling time before social distancing (days)",
167-
min_value=0,
167+
min_value=FLOAT_INPUT_MIN,
168168
value=d.doubling_time,
169-
step=1,
170-
format="%i",
169+
step=FLOAT_INPUT_STEP,
170+
format="%f",
171171
)
172172
relative_contact_rate_input = NumberInputWrapper(
173173
st_obj,
174174
"Social distancing (% reduction in social contact)",
175-
min_value=0,
176-
max_value=100,
177-
value=int(d.relative_contact_rate * 100),
178-
step=5,
179-
format="%i",
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",
180180
)
181181
hospitalized_rate_input = NumberInputWrapper(
182182
st_obj,
183183
"Hospitalization %(total infections)",
184-
min_value=0.001,
184+
min_value=0.0,
185185
max_value=100.0,
186186
value=d.hospitalized.rate * 100,
187-
step=1.0,
187+
step=FLOAT_INPUT_STEP,
188188
format="%f",
189189
)
190190
icu_rate_input = NumberInputWrapper(
@@ -193,7 +193,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
193193
min_value=0.0,
194194
max_value=100.0,
195195
value=d.icu.rate * 100,
196-
step=1.0,
196+
step=FLOAT_INPUT_STEP,
197197
format="%f",
198198
)
199199
ventilated_rate_input = NumberInputWrapper(
@@ -202,7 +202,7 @@ def display_sidebar(st, d: Constants) -> Parameters:
202202
min_value=0.0,
203203
max_value=100.0,
204204
value=d.ventilated.rate * 100,
205-
step=1.0,
205+
step=FLOAT_INPUT_STEP,
206206
format="%f",
207207
)
208208
hospitalized_los_input = NumberInputWrapper(
@@ -232,33 +232,32 @@ def display_sidebar(st, d: Constants) -> Parameters:
232232
market_share_input = NumberInputWrapper(
233233
st_obj,
234234
"Hospital Market Share (%)",
235-
min_value=0.001,
235+
min_value=FLOAT_INPUT_MIN,
236236
max_value=100.0,
237237
value=d.market_share * 100,
238-
step=1.0,
238+
step=FLOAT_INPUT_STEP,
239239
format="%f",
240240
)
241241
population_input = NumberInputWrapper(
242242
st_obj,
243243
"Regional Population",
244244
min_value=1,
245245
value=d.region.population,
246-
step=100000,
246+
step=1,
247247
format="%i",
248248
)
249249
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,
254-
step=10,
254+
step=1,
255255
format="%i",
256256
)
257257
as_date_input = CheckboxWrapper(st_obj, "Present result as dates instead of days", value=False)
258258
max_y_axis_set_input = CheckboxWrapper(st_obj, "Set the Y-axis on graphs to a static value")
259259
max_y_axis_input = NumberInputWrapper(st_obj, "Y-axis static value", value=500, format="%i", step=25)
260260

261-
262261
# Build in desired order
263262
st.sidebar.markdown("### Regional Parameters [ℹ]({docs_url}/what-is-chime/parameters)".format(docs_url=DOCS_URL))
264263
population = population_input()
@@ -300,9 +299,9 @@ def display_sidebar(st, d: Constants) -> Parameters:
300299
relative_contact_rate=relative_contact_rate / 100.0,
301300
population=population,
302301

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),
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),
306305
)
307306

308307

0 commit comments

Comments
 (0)