From 47b4a03c6293fd957463f65a17f096f9a408ca84 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 18 Apr 2024 15:25:17 -0600 Subject: [PATCH] add emergency rental assistance --- programs/programs/__init__.py | 2 + .../emergency_rental_assistance/__init__.py | 0 .../emergency_rental_assistance/calculator.py | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 programs/programs/emergency_rental_assistance/__init__.py create mode 100644 programs/programs/emergency_rental_assistance/calculator.py diff --git a/programs/programs/__init__.py b/programs/programs/__init__.py index 25d71b5d..a6b5a712 100644 --- a/programs/programs/__init__.py +++ b/programs/programs/__init__.py @@ -28,6 +28,7 @@ from .utility_bill_pay.calculator import UtilityBillPay from .calc import ProgramCalculator from .rental_assistance_grant.calculator import RentalAssistanceGrant +from .emergency_rental_assistance.calculator import EmergencyRentalAssistance calculators: dict[str, type[ProgramCalculator]] = { 'rtdlive': RtdLive, @@ -59,4 +60,5 @@ 'trua': Trua, 'ubp': UtilityBillPay, 'rag': RentalAssistanceGrant, + 'erap': EmergencyRentalAssistance, } diff --git a/programs/programs/emergency_rental_assistance/__init__.py b/programs/programs/emergency_rental_assistance/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/programs/programs/emergency_rental_assistance/calculator.py b/programs/programs/emergency_rental_assistance/calculator.py new file mode 100644 index 00000000..6a3076a0 --- /dev/null +++ b/programs/programs/emergency_rental_assistance/calculator.py @@ -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 +