Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…fits-api into dev
  • Loading branch information
CalebPena committed Apr 18, 2024
2 parents 1da55a8 + c2586c3 commit c248844
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions programs/programs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -59,4 +60,5 @@
'trua': Trua,
'ubp': UtilityBillPay,
'rag': RentalAssistanceGrant,
'erap': EmergencyRentalAssistance,
}
Empty file.
44 changes: 44 additions & 0 deletions programs/programs/emergency_rental_assistance/calculator.py
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

0 comments on commit c248844

Please sign in to comment.