Skip to content

Commit 555870c

Browse files
committed
Restructure validators so that Disposition objects have their own distinct validator
1 parent 4a29aab commit 555870c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/penn_chime/parameters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Optional
1010

1111
from .validators import (
12-
Positive, OptionalStrictlyPositive, StrictlyPositive, Rate, Date, OptionalDate
12+
Positive, OptionalStrictlyPositive, StrictlyPositive, Rate, Date, OptionalDate, ValDisposition
1313
)
1414

1515
# Parameters for each disposition (hospitalized, icu, ventilated)
@@ -69,9 +69,9 @@ def __init__(
6969
region: Optional[Regions] = None,
7070
):
7171
self.current_hospitalized = Positive(value=current_hospitalized)
72-
Rate(value=hospitalized.rate), Rate(value=icu.rate), Rate(value=ventilated.rate)
73-
StrictlyPositive(value=hospitalized.days), StrictlyPositive(value=icu.days),
74-
StrictlyPositive(value=ventilated.days)
72+
ValDisposition(value=hospitalized)
73+
ValDisposition(value=icu)
74+
ValDisposition(value=ventilated)
7575

7676
self.hospitalized = hospitalized
7777
self.icu = icu

src/penn_chime/validators/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"""the callable validator design pattern"""
22

3-
from .validators import Bounded, OptionalBounded, Rate, Date, OptionalDate
4-
5-
EPSILON = 1.e-7
3+
from .validators import EPSILON, Bounded, OptionalBounded, Rate, Date, OptionalDate, ValDisposition
64

75
OptionalStrictlyPositive = OptionalBounded(lower_bound=EPSILON)
86
StrictlyPositive = Bounded(lower_bound=EPSILON)
97
Positive = Bounded(lower_bound=-EPSILON)
108
Rate = Rate() # type: ignore
119
Date = Date() # type: ignore
1210
OptionalDate = OptionalDate() # type: ignore
11+
ValDisposition = ValDisposition()
1312
# # rolling a custom validator for doubling time in case DS wants to add upper bound
1413
# DoublingTime = OptionalBounded(lower_bound=0-EPSILON, upper_bound=None)

src/penn_chime/validators/validators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .base import Validator
77

8+
EPSILON = 1.e-7
89

910
class Bounded(Validator):
1011
"""A bounded number."""
@@ -67,3 +68,11 @@ def validate(self, value):
6768
if value is None:
6869
return None
6970
super().validate(value)
71+
72+
class ValDisposition(Validator):
73+
def __init__(self) -> None:
74+
pass
75+
76+
def validate(self, value):
77+
Bounded(lower_bound=EPSILON)(value=value.days)
78+
Rate()(value=value.rate)

0 commit comments

Comments
 (0)