Spaces:
Running
Running
| from openfisca_core.taxbenefitsystems import TaxBenefitSystem | |
| from openfisca_core.simulations import SimulationBuilder | |
| from .entities import entities | |
| from . import variables as vars_module | |
| import inspect | |
| def build_tax_system(): | |
| system = TaxBenefitSystem(entities) | |
| # Auto-register all Variable subclasses | |
| for name, obj in inspect.getmembers(vars_module, inspect.isclass): | |
| if hasattr(obj, 'value_type'): | |
| system.add_variable(obj) | |
| return system | |
| TAX_SYSTEM = build_tax_system() | |
| ELIGIBILITY_VARIABLES = [ | |
| # National Schemes | |
| "eligible_pm_kisan", | |
| "eligible_pmjay", | |
| "eligible_pmay_gramin", | |
| "eligible_ujjwala", | |
| "eligible_scholarship_sc_st", | |
| # Rajasthan State Schemes | |
| "eligible_chiranjeevi", | |
| "eligible_palanhar", | |
| "eligible_ekal_nari", | |
| "eligible_devnarayan_scholarship", | |
| "eligible_incentive_to_girls", | |
| "eligible_widow_bed_scheme", | |
| "eligible_nirman_shramik_auzaar", | |
| "eligible_indira_mahila_shakti", | |
| "eligible_ayushman_arogya" | |
| ] | |
| def check_eligibility(profile: dict) -> dict: | |
| """ | |
| Takes a citizen profile dict, returns dict of scheme eligibility. | |
| Pure deterministic logic — no LLM involved. | |
| Sprint 40: Temporal dynamism — period key is now derived from | |
| the current calendar year instead of hardcoded "2024". | |
| """ | |
| import datetime as _dt | |
| current_year = str(_dt.datetime.now().year) | |
| situation = { | |
| "persons": { | |
| "citizen": { | |
| "annual_income": {current_year: profile.get("annual_income", 0)}, | |
| "age": {current_year: profile.get("age", 0)}, | |
| "is_farmer": {current_year: profile.get("is_farmer", False)}, | |
| "state": {current_year: profile.get("state", "Unknown")}, | |
| "caste_category": {current_year: profile.get("caste_category", "General")}, | |
| "gender": {current_year: profile.get("gender", "Unknown")}, | |
| "is_bpl": {current_year: profile.get("is_bpl", False)}, | |
| "land_size_hectares": {current_year: profile.get("land_size_hectares", 0.0)}, | |
| "is_disabled": {current_year: profile.get("is_disabled", False)}, | |
| "occupation": {current_year: profile.get("occupation", "Unknown")}, | |
| } | |
| }, | |
| "households": {"household": {"members": ["citizen"]}} | |
| } | |
| # CRITICAL FIX: Use the SimulationBuilder to properly inject the dictionary! | |
| builder = SimulationBuilder() | |
| simulation = builder.build_from_dict(TAX_SYSTEM, situation) | |
| results = {} | |
| for var in ELIGIBILITY_VARIABLES: | |
| results[var] = bool(simulation.calculate(var, current_year)[0]) | |
| return results |