-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/Gary-Community-Ventures/bene…
…fits-api into dev
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Empty file.
44 changes: 44 additions & 0 deletions
44
programs/programs/emergency_rental_assistance/calculator.py
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,44 @@ | ||
from programs.programs.calc import Eligibility, ProgramCalculator | ||
import programs.programs.messages as messages | ||
from integrations.util.cache import Cache | ||
from programs.sheets import sheets_get_data | ||
from programs.co_county_zips import counties_from_zip | ||
|
||
|
||
class EmergencyRentalAssistanceIncomeLimitsCache(Cache): | ||
expire_time = 60 * 60 * 24 | ||
default = {} | ||
|
||
def update(self): | ||
spreadsheet_id = '1QHb-ZT0Y2oWjFMoeP_wy8ClveslINWdehb-CXhB8WSE' | ||
range_name = "'2022 80% AMI'!A2:I" | ||
sheet_values = sheets_get_data(spreadsheet_id, range_name) | ||
|
||
if not sheet_values: | ||
raise Exception('Sheet unavailable') | ||
|
||
data = {d[0].strip() + ' County': [int(v.replace(',', '')) for v in d[1:]] for d in sheet_values} | ||
|
||
return data | ||
|
||
|
||
class EmergencyRentalAssistance(ProgramCalculator): | ||
amount = 13_848 | ||
dependencies = ['income_amount', 'income_frequency', 'household_size', 'zipcode'] | ||
income_cache = EmergencyRentalAssistanceIncomeLimitsCache() | ||
income_limit_percent = .8 | ||
|
||
def eligible(self) -> Eligibility: | ||
e = Eligibility() | ||
|
||
# Income test | ||
counties = counties_from_zip(self.screen.zipcode) | ||
county_name = self.screen.county if self.screen.county is not None else counties[0] | ||
|
||
income = self.screen.calc_gross_income('yearly', ['all']) | ||
income_limits = EmergencyRentalAssistance.income_cache.fetch() | ||
income_limit = income_limits[county_name][self.screen.household_size - 1] * EmergencyRentalAssistance.income_limit_percent | ||
e.condition(income < income_limit, messages.income(income, income_limit)) | ||
|
||
return e | ||
|