govbridge-api / eligibility /variables.py
harshrawat18's picture
fix: apply Lead Architect delta patch for concurrent caching and bitwise logic
1c40719
Raw
History Blame Contribute Delete
8.29 kB
from openfisca_core.variables import Variable
from openfisca_core.periods import ETERNITY, YEAR
import numpy as np
from .entities import Person
# Input variables
class annual_income(Variable):
value_type = float
entity = Person
definition_period = YEAR
label = "Annual household income in INR"
default_value = 0
class age(Variable):
value_type = int
entity = Person
definition_period = ETERNITY
label = "Age of person"
default_value = 0
class is_farmer(Variable):
value_type = bool
entity = Person
definition_period = ETERNITY
label = "Is the person a farmer"
default_value = False
class state(Variable):
value_type = str
entity = Person
definition_period = ETERNITY
label = "State of residence"
default_value = ""
class caste_category(Variable):
value_type = str
entity = Person
definition_period = ETERNITY
label = "SC/ST/OBC/General"
default_value = "General"
class gender(Variable):
value_type = str
entity = Person
definition_period = ETERNITY
label = "Gender (Male/Female/Other)"
default_value = "Unknown"
class is_bpl(Variable):
"""Below Poverty Line status — used by PMJAY and other welfare schemes."""
value_type = bool
entity = Person
definition_period = ETERNITY
label = "Is the person below poverty line"
default_value = False
class land_size_hectares(Variable):
"""Agricultural land holding in hectares — used by PM-KISAN."""
value_type = float
entity = Person
definition_period = ETERNITY
label = "Agricultural land size in hectares"
default_value = 0.0
class is_disabled(Variable):
value_type = bool
entity = Person
definition_period = ETERNITY
label = "Person with disability status"
default_value = False
class occupation(Variable):
value_type = str
entity = Person
definition_period = ETERNITY
label = "Primary occupation"
default_value = "Unknown"
# Eligibility output variables
class eligible_pm_kisan(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for PM-KISAN scheme"
def formula(person, period, parameters):
return (
person("is_farmer", period) *
(person("annual_income", period) <= 200000)
)
class eligible_chiranjeevi(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for Chiranjeevi Health Insurance (Rajasthan)"
def formula(person, period, parameters):
income = person("annual_income", period)
state_val = person("state", period)
return (
(state_val == "Rajasthan") *
(income <= 800000)
)
class eligible_palanhar(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for Palanhar Yojana (Rajasthan)"
def formula(person, period, parameters):
return (
(person("state", period) == "Rajasthan") *
(person("caste_category", period) == "SC")
)
# --- SPRINT 8: NEW SCHEMES EXPANSION ---
class eligible_ekal_nari(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Chief Minister Ekal Nari Samman Pension Yojana"
def formula(person, period, parameters):
# Approximated: Adult women in Rajasthan with low income
return (person("state", period) == "Rajasthan") * (person("age", period) >= 18) * (person("annual_income", period) <= 500000)
class eligible_devnarayan_scholarship(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Devnarayan Pre-Matric Scholarship Scheme"
def formula(person, period, parameters):
# Approximated: OBC students under 18
return (person("state", period) == "Rajasthan") * (person("caste_category", period) == "OBC") * (person("age", period) <= 18)
class eligible_incentive_to_girls(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Incentive To Girls"
def formula(person, period, parameters):
# Approximated: Young females (using age as proxy)
return (person("state", period) == "Rajasthan") * (person("age", period) <= 18)
class eligible_widow_bed_scheme(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Widow B.Ed Scheme-Rajasthan"
def formula(person, period, parameters):
# Approximated: Adult women seeking education
return (person("state", period) == "Rajasthan") * (person("age", period) >= 21)
class eligible_nirman_shramik_auzaar(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Nirman Shramik Auzaar Toolkit Sahayata Yojana"
def formula(person, period, parameters):
# Approximated: Working age adults with low income
return (person("state", period) == "Rajasthan") * (person("age", period) >= 18) * (person("annual_income", period) <= 300000)
class eligible_indira_mahila_shakti(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Indira Mahila Shakti Udyam Protsahan Yojana"
def formula(person, period, parameters):
# Approximated: Adult women empowerment
return (person("state", period) == "Rajasthan") * (person("age", period) >= 18)
class eligible_ayushman_arogya(Variable):
value_type = bool
entity = Person
definition_period = YEAR
label = "Mukhyamantree Ayushman Arogya Yojana"
def formula(person, period, parameters):
# Approximated: Healthcare for residents under income threshold
return (person("state", period) == "Rajasthan") * (person("annual_income", period) <= 800000)
# --- SPRINT 19: NATIONAL SCHEME EXPANSION ---
class eligible_pmjay(Variable):
"""
Pradhan Mantri Jan Arogya Yojana (Ayushman Bharat)
National Health Protection Scheme - up to ₹5 lakh/family/year
Eligibility (simplified from SECC deprivation criteria):
- Annual income below ₹5 lakh
- OR BPL status
- Available nationwide
"""
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for Ayushman Bharat PMJAY"
def formula(person, period, parameters):
income = person("annual_income", period)
bpl = person("is_bpl", period)
return (income <= 500000) | bpl # bitwise OR for vectorized logic
class eligible_pmay_gramin(Variable):
"""
Pradhan Mantri Awas Yojana - Gramin (Rural Housing)
Eligibility:
- Annual income below ₹3 lakh
- Must be from rural area (approximated by BPL or low income)
"""
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for PMAY Gramin (Rural Housing)"
def formula(person, period, parameters):
income = person("annual_income", period)
return income <= 300000
class eligible_ujjwala(Variable):
"""
Pradhan Mantri Ujjwala Yojana (Free LPG connection)
Eligibility:
- BPL household
- Adult woman (age >= 18)
"""
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for Ujjwala Yojana (Free LPG)"
def formula(person, period, parameters):
bpl = person("is_bpl", period)
age_val = person("age", period)
gender_val = person("gender", period)
return bpl & (age_val >= 18) & (gender_val == "Female") # bitwise AND for vectorized logic
class eligible_scholarship_sc_st(Variable):
"""
Post-Matric Scholarship for SC/ST Students (National)
Eligibility:
- SC or ST category
- Age 16-35 (post-matric)
- Annual income below ₹2.5 lakh
"""
value_type = bool
entity = Person
definition_period = YEAR
label = "Eligible for SC/ST Post-Matric Scholarship"
def formula(person, period, parameters):
caste = person("caste_category", period)
age_val = person("age", period)
income = person("annual_income", period)
is_sc_st = (caste == "SC") | (caste == "ST") # bitwise OR for vectorized logic
return is_sc_st & (age_val >= 16) & (age_val <= 35) & (income <= 250000) # bitwise AND