Created
May 31, 2021 09:33
-
-
Save ObjectBoxPC/326874142de12b5f0fb970ae176f1053 to your computer and use it in GitHub Desktop.
Functions implementing California's COVID-19 reopening tiers introduced in August 2020 (not including 2021 updates) https://www.cdph.ca.gov/Programs/CID/DCDC/Pages/COVID-19/COVID19CountyMonitoringOverview.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data RiskTier = Widespread | Substantial | Moderate | Minimal | |
deriving (Show, Eq) | |
instance Ord RiskTier where | |
compare x y = compare (tierNumber x) (tierNumber y) | |
where | |
tierNumber t = case t of | |
Widespread -> 1 | |
Substantial -> 2 | |
Moderate -> 3 | |
Minimal -> 4 | |
caseRateAdjustmentFactor :: Double -> Double | |
caseRateAdjustmentFactor testingFactor = min 1.4 (max 0.6 rawAdjustmentFactor) | |
where | |
rawAdjustmentFactor = 1.4 - testingFactor * 0.4 | |
tierByCaseRate :: Double -> Double -> Bool -> Bool -> RiskTier | |
tierByCaseRate caseRate testingFactor canAdjustUpward canAdjustDownward | |
| adjustedRate > 7 = Widespread | |
| 4 <= adjustedRate && adjustedRate <= 7 = Substantial | |
| 1 <= adjustedRate && adjustedRate < 4 = Moderate | |
| otherwise = Minimal | |
where | |
adjustedRate | |
| (not canAdjustUpward && adjustmentFactor > 1) | |
|| (canAdjustDownward && adjustmentFactor < 1) = caseRate | |
| otherwise = caseRate * adjustmentFactor | |
adjustmentFactor = caseRateAdjustmentFactor testingFactor | |
tierByTestPositivity :: Double -> RiskTier | |
tierByTestPositivity p | |
| p > 8 = Widespread | |
| 5 <= p && p <= 8 = Substantial | |
| 2 <= p && p < 5 = Moderate | |
| otherwise = Minimal | |
tier :: Double -> Double -> Double -> Bool -> RiskTier | |
tier caseRate testPositivity testingFactor isSmallCounty = | |
min tcr ttp | |
where | |
tcr = tierByCaseRate caseRate testingFactor cau cad | |
ttp = tierByTestPositivity testPositivity | |
cau = not isSmallCounty && testPositivity > 3.5 | |
cad = not isSmallCounty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment