-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support per-county low income thresholds (#485)
## Description This has been hanging over our heads since Vermont, but now NY's HEAR program has them, so it's time to actually do it. I added a `type` field to each threshold definition, which can have the values `hhsize` or `county-hhsize`, indicating the sequence of keys to be used with the `thresholds` structure. Counties are identified by FIPS code, same as in the authorities files. To demonstrate this working, I updated the county-specific Vermont incentives (it's a lot less data than the NY ones, which I'll do separately). I've also switched the low-income-thresholds JSON-Schema-to-TS logic away from ajv and to `json-schema-to-ts`. The latter is what I prefer to use for this because it's what Fastify uses to turn endpoint schemas into types, and I think it's worthwhile to have everything use the same solution for that (because every schema-to-TS thing has subtle differences). I've been converting things gradually. Anyway, this resulted most notably in having to remove the `required: [1,2,...]` constraint on the household-size-thresholds struct, so I added a unit test for that. ## Test Plan New test for county-specific Vermont thresholds (same income is LI in one county but not in another). Other tests pass.
- Loading branch information
Showing
14 changed files
with
582 additions
and
123 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
HHSizeThresholds, | ||
LowIncomeThresholdsAuthority, | ||
} from '../data/low_income_thresholds'; | ||
import { CalculateParams } from './incentives-calculation'; | ||
import { ResolvedLocation } from './location'; | ||
|
||
/** | ||
* Chooses the right income threshold and determines whether the given income | ||
* is below it. Which threshold is chosen is conditioned on household size, and, | ||
* in some cases, location. | ||
*/ | ||
export function isLowIncome( | ||
{ household_size, household_income }: CalculateParams, | ||
thresholds: LowIncomeThresholdsAuthority, | ||
location: ResolvedLocation, | ||
): boolean { | ||
const bySize: HHSizeThresholds = | ||
thresholds.type === 'hhsize' | ||
? thresholds.thresholds | ||
: thresholds.thresholds[location.countyFips] ?? | ||
thresholds.thresholds['other']; | ||
const threshold = bySize?.[household_size]; | ||
|
||
// The only way the threshold should be missing is if they are defined by | ||
// county, the user's county doesn't have thresholds defined, and there's no | ||
// "other" fallback. (All possible input HH sizes should be present in the | ||
// data; this is enforced by a unit test.) If the threshold is missing, be | ||
// conservative and return false (i.e. "not low income"). | ||
return typeof threshold === 'number' && household_income <= threshold; | ||
} |
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
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
Oops, something went wrong.