Skip to content

Commit

Permalink
Merge pull request #33 from DTS-STN/cerb_scenario_refactor
Browse files Browse the repository at this point in the history
Updated the CERB class based on comments from the Rocket Code Review
  • Loading branch information
MikeBungay authored Aug 18, 2020
2 parents 8e89674 + 6018c84 commit 681dab5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 55 deletions.
48 changes: 23 additions & 25 deletions openfisca_canada/tests/benefitfinder/cerb/cerb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 1

cerb__is_eligible_lost_all_income_lost_job_or_employer_closed:
- true

- name: "individual employer closed - Scenario 1"
period: 2020-08
Expand All @@ -26,8 +25,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 1
cerb__is_eligible_lost_all_income_lost_job_or_employer_closed:
- true


- name: "individual self eployed no income test"
Expand All @@ -41,8 +40,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 4
cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim:
- true


- name: "individual unpaid leave care of child or sick"
Expand All @@ -56,8 +55,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 4
cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim:
- true

- name: "individual recent parental leave cant return to work"
period: 2020-08
Expand All @@ -70,8 +69,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 4
cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim:
- true


- name: "individual has recent ei claim"
Expand All @@ -85,8 +84,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 4
cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim:
- true

- name: "individual is sick or quarantined or unpaid leave"
period: 2020-08
Expand All @@ -99,8 +98,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 4
cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim:
- true

#has lost some income Tests

Expand All @@ -118,8 +117,7 @@
output:
cerb__is_eligible:
- false
cerb__eligible_scenario:
- 0



- name: "Lost Some Income - is quarantined"
Expand All @@ -136,8 +134,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 3
cerb__is_eligible_lost_some_income_quarantine:
- true

- name: "Lost Some Income - has hours reduced or lost a job"
period: 2018-08
Expand All @@ -153,8 +151,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 2
cerb__is_eligible_lost_some_income_reduced_hours_1000_or_less:
- true

- name: "Lost Some Income - is self employed some income"
period: 2018-08
Expand All @@ -170,8 +168,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 5
cerb__is_eligible_lost_some_income_self_employed_1000_hours_or_less:
- true
# Person has gross income of greater than 5K
- name: "Person Gross income over 5k"
period: 2018-08
Expand All @@ -183,8 +181,8 @@
output:
cerb__is_eligible:
- true
cerb__eligible_scenario:
- 6
cerb__is_eligible_gross_income_over_5k:
- true

- name: "Some Income tests"
period: 2018-08
Expand Down
103 changes: 73 additions & 30 deletions openfisca_canada/variables/benefitfinder/cerb/cerb__is_eligible.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from openfisca_core.model_api import *
from openfisca_canada.entities import Person, Family
import numpy as np


class cerb__is_eligible(Variable):
value_type = bool
Expand All @@ -14,38 +12,83 @@ class cerb__is_eligible(Variable):
reference = "tbd"

def formula(persons, period, parameters):
return (persons('income_status__has_lost_all_income', period) * (persons('income_status_reason__has_lost_job', period) + persons('income_status_reason__has_employer_closed', period) + \
persons('income_status_reason__is_self_employed', period) + persons('income_status_reason__has_unpaid_leave_to_care_for_child_or_sick', period) + \
persons('income_status_reason__has_parental_recently_cant_return_to_work', period) + persons('income_status_reason__has_ei_recent_claim_ended', period))) + \
(persons('income_status__has_lost_some_income', period) * ((persons("income_status_reason__has_hours_reduced",period) + persons("income_status_reason__employed_lost_a_job",period)) * persons("income_status_reason__has_1000_or_less",period))) + \
(persons('income_status__has_lost_some_income', period) * persons("income_status_reason__is_quarantined",period)) + \
(persons('income_status__has_lost_some_income', period) * persons("income_status_reason__is_self_employed",period) * persons("income_status_reason__has_1000_or_less",period)) + \
persons('income_status_reason__is_gross_income_over_5k', period)

class cerb__eligible_scenario(Variable):
value_type = float
return persons('cerb__is_eligible_lost_all_income_lost_job_or_employer_closed', period) +\
persons('cerb__is_eligible_lost_some_income_reduced_hours_1000_or_less', period) +\
persons('cerb__is_eligible_lost_some_income_quarantine', period) +\
persons('cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim', period) +\
persons('cerb__is_eligible_lost_some_income_self_employed_1000_hours_or_less', period) +\
persons('cerb__is_eligible_gross_income_over_5k', period)


class cerb__is_eligible_lost_all_income_lost_job_or_employer_closed(Variable):
value_type = bool
entity = Person
definition_period = MONTH
label = u"which scenario of cerb is person eligible?"
reference = "tbd"

def formula(persons, period, parameters):
return persons('income_status__has_lost_all_income', period) * (persons('income_status_reason__has_lost_job', period) +\
persons('income_status_reason__has_employer_closed', period))

class cerb__is_eligible_lost_some_income_reduced_hours_1000_or_less(Variable):
value_type = bool
entity = Person
definition_period = MONTH
default_value = False
label = u"which scenario of cerb is person eligible?"
reference = "tbd"

def formula(persons, period, parameters):
return persons('income_status__has_lost_some_income', period) * ((persons('income_status_reason__has_hours_reduced', period) + \
persons('income_status_reason__employed_lost_a_job', period)) * persons('income_status_reason__has_1000_or_less', period))

class cerb__is_eligible_lost_some_income_quarantine(Variable):
value_type = bool
entity = Person
definition_period = MONTH
default_value = False
label = u"which scenario of cerb is person eligible?"
reference = "tbd"

def formula(persons, period, parameters):
return persons('income_status__has_lost_some_income', period) * persons('income_status_reason__is_quarantined', period)



class cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim(Variable):
value_type = bool
entity = Person
definition_period = MONTH
default_value = False
label = u"is person eligible for cerb__is_eligible_lost_all_income_self_employed_closed_unpaid_leave_parental_leave_recent_ei_claim?"
reference = "tbd"

def formula(persons, period, parameters):
return persons('income_status__has_lost_all_income', period) * (persons('income_status_reason__is_self_employed', period) + \
persons('income_status_reason__has_unpaid_leave_to_care_for_child_or_sick', period) + \
persons('income_status_reason__has_parental_recently_cant_return_to_work', period) + \
persons('income_status_reason__has_ei_recent_claim_ended', period))

class cerb__is_eligible_lost_some_income_self_employed_1000_hours_or_less(Variable):
value_type = bool
entity = Person
definition_period = MONTH
default_value = False
label = u"is person eligible for cerb__is_eligible_lost_some_income_self_employed_1000_hours_or_less?"
reference = "tbd"

def formula(persons, period, parameters):
return persons('income_status__has_lost_some_income', period) * persons('income_status_reason__is_self_employed', period) * \
persons('income_status_reason__has_1000_or_less', period)

class cerb__is_eligible_gross_income_over_5k(Variable):
value_type = bool
entity = Person
definition_period = MONTH
default_value = False
label = u"is person eligible fo cerb__is_eligible_gross_income_over_5k?"
reference = "tbd"

def formula(persons, period, parameters):
result = np.arange(1)
if (persons('income_status__has_lost_all_income', period) * (persons('income_status_reason__has_lost_job', period) + persons('income_status_reason__has_employer_closed', period))):
result[0]=1
elif (persons('income_status__has_lost_all_income', period) * persons('income_status_reason__is_self_employed', period) + persons('income_status_reason__has_unpaid_leave_to_care_for_child_or_sick', period) + \
persons('income_status_reason__has_parental_recently_cant_return_to_work', period) + persons('income_status_reason__has_ei_recent_claim_ended', period)):
result[0]= 4
elif (persons('income_status__has_lost_some_income', period) * ((persons("income_status_reason__has_hours_reduced",period) + persons("income_status_reason__employed_lost_a_job",period)) * persons("income_status_reason__has_1000_or_less",period))):
result[0]= 2
elif (persons('income_status__has_lost_some_income', period) * persons("income_status_reason__is_quarantined",period)):
result[0]= 3
elif (persons('income_status__has_lost_some_income', period) * persons("income_status_reason__is_self_employed",period) * persons("income_status_reason__has_1000_or_less",period)):
result[0]= 5
elif persons('income_status_reason__is_gross_income_over_5k', period):
result[0]= 6
else:
result[0]= 0
return result

return persons('income_status_reason__is_gross_income_over_5k', period)

0 comments on commit 681dab5

Please sign in to comment.