Skip to content

Commit 337aa8f

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents d5bfb79 + 5a60be8 commit 337aa8f

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed

docs/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ As of March 21, help is especially wanted from contributors with experience in K
2626

2727
- [Fork](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) the [CodeforPhilly/chime](https://github.com/CodeForPhilly/chime) repo.
2828
- Base your work on the `develop` branch.
29+
- Take a few minutes to review this [resource](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Reviewer_Checklist) for contributors and reviewers, to accelerate the adoption of your contribution (thanks to the good folks at Mozilla for this).
2930
- Submit pull requests from your fork, also against the `develop` branch of the `CodeforPhilly/chime` repo.
3031
- Request review from the relevant maintainer(s).
3132
- Check your pull request periodically to see if any changes have been requested or any merge conflicts have arisen.
3233
- If a merge conflict arises, rebase against the latest `develop` branch and force-push the new branch as early as you can. You may need to do this more than once before your changes get merged. Do your best to keep your branch in a mergeable state until it is finished being reviewed and accepted.
33-
- If your change affects the results calculated or presented, update `change_date` in `src/penn_chime/parameters.py` when the pull request is ready for merge, so users can see when results have last changed
34+
- If your change affects the results calculated or presented, update `change_date` in `src/penn_chime/constants.py` when the pull request is ready for merge, so users can see when results have last changed
3435
- Note: Frequent contributors with write access can submit pull requests from a new branch in the `CodeforPhilly/chime` repository.
3536

3637
## Review & Release

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
__version__ = "1.1.3" # update VERSION in constants.py
44
__author__ = "Predictive Healthcare @ Penn Medicine"
55

6-
from os import path
7-
from setuptools import setup, find_packages, find_namespace_packages
6+
from setuptools import setup, find_namespace_packages
87

98

109
setup(
@@ -24,6 +23,7 @@
2423
install_requires=[
2524
"altair",
2625
"black",
26+
"gspread",
2727
"gunicorn",
2828
"dash",
2929
"dash_bootstrap_components",
@@ -42,10 +42,9 @@
4242
"Operating System :: OS Independent",
4343
],
4444
python_requires='>=3.7',
45-
entry_points = {
45+
entry_points={
4646
'console_scripts': ['penn_chime=penn_chime.cli:main'],
4747
},
4848
keywords=[],
4949
include_package_data=True,
5050
)
51-

src/penn_chime/models.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,40 @@ def __init__(self, p: Parameters):
6464
logger.info('Using doubling_time: %s', p.doubling_time)
6565

6666
intrinsic_growth_rate = get_growth_rate(p.doubling_time)
67-
6867
self.beta = get_beta(intrinsic_growth_rate, gamma, self.susceptible, 0.0)
6968
self.beta_t = get_beta(intrinsic_growth_rate, self.gamma, self.susceptible, p.relative_contact_rate)
7069

71-
self.i_day = 0 # seed to the full length
72-
raw = self.run_projection(p, [(self.beta, p.n_days)])
73-
self.i_day = i_day = int(get_argmin_ds(raw["census_hospitalized"], p.current_hospitalized))
70+
if p.mitigation_date is None:
71+
self.i_day = 0 # seed to the full length
72+
raw = self.run_projection(p, [(self.beta, p.n_days)])
73+
self.i_day = i_day = int(get_argmin_ds(raw["census_hospitalized"], p.current_hospitalized))
7474

75-
self.raw = self.run_projection(p, self.gen_policy(p))
75+
self.raw = self.run_projection(p, self.gen_policy(p))
76+
77+
logger.info('Set i_day = %s', i_day)
78+
else:
79+
projections = {}
80+
best_i_day = -1
81+
best_i_day_loss = float('inf')
82+
for i_day in range(p.n_days):
83+
self.i_day = i_day
84+
raw = self.run_projection(p, self.gen_policy(p))
85+
86+
# Don't fit against results that put the peak before the present day
87+
if raw["census_hospitalized"].argmax() < i_day:
88+
continue
89+
90+
loss = get_loss(raw["census_hospitalized"][i_day], p.current_hospitalized)
91+
if loss < best_i_day_loss:
92+
best_i_day_loss = loss
93+
best_i_day = i_day
94+
self.raw = raw
95+
96+
self.i_day = best_i_day
7697

77-
logger.info('Set i_day = %s', i_day)
78-
p.date_first_hospitalized = p.current_date - timedelta(days=i_day)
7998
logger.info(
8099
'Estimated date_first_hospitalized: %s; current_date: %s; i_day: %s',
81-
p.date_first_hospitalized,
100+
p.current_date - timedelta(days=self.i_day),
82101
p.current_date,
83102
self.i_day)
84103

src/penn_chime/parameters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from .validators import (
2121
Date,
22+
GteOne,
2223
OptionalDate,
2324
OptionalValue,
2425
OptionalStrictlyPositive,
@@ -64,7 +65,7 @@ class Disposition(_Disposition):
6465
@classmethod
6566
def create(cls, *, days: int, rate: float):
6667
"""Mandate key word arguments."""
67-
Positive(key="days", value=days)
68+
GteOne(key="days", value=days)
6869
Rate(key="rate", value=rate)
6970
return cls(days, rate)
7071

@@ -201,7 +202,7 @@ def validate(string):
201202
(
202203
"hospitalized_days",
203204
int,
204-
0,
205+
1,
205206
None,
206207
True,
207208
),
@@ -215,7 +216,7 @@ def validate(string):
215216
(
216217
"icu_days",
217218
int,
218-
0,
219+
1,
219220
None,
220221
True,
221222
),
@@ -285,7 +286,7 @@ def validate(string):
285286
(
286287
"ventilated_days",
287288
int,
288-
0,
289+
1,
289290
None,
290291
True,
291292
),

src/penn_chime/presentation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ def display_sidebar(st, d: Parameters) -> Parameters:
220220
step=1.0,
221221
)
222222
hospitalized_pct_input = PercentInput(
223-
st_obj, "Hospitalization %(total infections)", value=d.hospitalized.rate,
223+
st_obj,
224+
"Hospitalization %(total infections)",
225+
value=d.hospitalized.rate,
226+
min_value=FLOAT_INPUT_MIN,
227+
max_value=100.0
224228
)
225229
icu_pct_input = PercentInput(st_obj,
226230
"ICU %(total infections)",
@@ -234,23 +238,23 @@ def display_sidebar(st, d: Parameters) -> Parameters:
234238
hospitalized_days_input = NumberInput(
235239
st_obj,
236240
"Average hospital length of stay (in days)",
237-
min_value=0,
241+
min_value=1,
238242
value=d.hospitalized.days,
239243
step=1,
240244
format="%i",
241245
)
242246
icu_days_input = NumberInput(
243247
st_obj,
244248
"Average days in ICU",
245-
min_value=0,
249+
min_value=1,
246250
value=d.icu.days,
247251
step=1,
248252
format="%i",
249253
)
250254
ventilated_days_input = NumberInput(
251255
st_obj,
252256
"Average days on ventilator",
253-
min_value=0,
257+
min_value=1,
254258
value=d.ventilated.days,
255259
step=1,
256260
format="%i",
@@ -272,7 +276,7 @@ def display_sidebar(st, d: Parameters) -> Parameters:
272276
infectious_days_input = NumberInput(
273277
st_obj,
274278
"Infectious days",
275-
min_value=0,
279+
min_value=1,
276280
value=d.infectious_days,
277281
step=1,
278282
format="%i",

src/penn_chime/validators/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
OptionalStrictlyPositive = ValOptionalBounded(lower_bound=EPSILON)
1616
StrictlyPositive = ValBounded(lower_bound=EPSILON)
1717
Positive = ValBounded(lower_bound=-EPSILON)
18+
GteOne = ValBounded(lower_bound=1)
1819
Rate = ValRate()
1920
Date = ValDate()
2021
OptionalDate = ValOptionalDate()

0 commit comments

Comments
 (0)