Skip to content

Commit

Permalink
Change tous les poids après calmar
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainipp committed Sep 17, 2024
1 parent d5fa4b2 commit 9a78970
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
61 changes: 39 additions & 22 deletions openfisca_france_data/reforms/variables_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,46 @@

from openfisca_france.model.base import * # noqa analysis:ignore
from openfisca_core.reforms import Reform
from openfisca_france_data import france_data_tax_benefit_system

import logging

log = logging.getLogger(__name__)
def create_calibration_tax_benefit_system(survey_scenario = None):
class variables_pour_calibration(Reform):
name = 'variables_pour_calibration'

def apply(self):

class age_calage(Variable):
value_type = str
entity = Individu
label = "Age censuré pour calage"
definition_period = YEAR
unit = 'years'
is_period_size_independent = True
set_input = set_input_dispatch_by_period

def formula(individu, period):
age = individu('age', period.first_month)
return min_(age, 100)

self.add_variable(age_calage)
scenario_for_calibration = variables_pour_calibration(survey_scenario)
return scenario_for_calibration

class variables_pour_calibration(Reform):
name = 'variables_pour_calibration'

def apply(self):

class age_calage(Variable):
value_type = str
entity = Individu
label = "Age censuré pour calage"
definition_period = YEAR
unit = 'years'
is_period_size_independent = True
set_input = set_input_dispatch_by_period

def formula(individu, period):
age = individu('age', period.first_month)
return min_(age, 100)


class weight_individus(Variable):
is_period_size_independent = True
value_type = float
entity = Individu
label = "Poids de l'individu"
definition_period = YEAR

def formula(individu, period):
if france_data_tax_benefit_system.variables["weight_familles"].is_input_variable():
return(individu.famille('weight_familles', period))
elif france_data_tax_benefit_system.variables["weight_foyers"].is_input_variable():
return(individu.foyer_fiscal('weight_foyers', period))
elif france_data_tax_benefit_system.variables["weight_menages"].is_input_variable():
return(individu.menage('weight_menages', period))
return individu.menage('wprm', period)

self.add_variable(age_calage)
scenario_for_calibration = variables_pour_calibration(france_data_tax_benefit_system)
4 changes: 2 additions & 2 deletions tests/test_calage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openfisca_survey_manager.calibration import Calibration # type: ignore
from openfisca_france_data import openfisca_france_data_location
from openfisca_france_data.model.calage import create_dic_calage
from openfisca_france_data.reforms.variables_calibration import create_calibration_tax_benefit_system
from openfisca_france_data.reforms.variables_calibration import scenario_for_calibration
from openfisca_france_data.erfs_fpr.scenario import ( # type: ignore
ErfsFprSurveyScenario,
)
Expand All @@ -19,7 +19,7 @@ def location() -> str:
def test_calage(survey_scenario, fake_input_data, location, year: int = 2015):
# On ititialise le survey scenario
survey_scenario2 = ErfsFprSurveyScenario.create(
tax_benefit_system = create_calibration_tax_benefit_system(france_data_tax_benefit_system),
tax_benefit_system = scenario_for_calibration,
period = year,
)
survey_scenario = survey_scenario2
Expand Down

0 comments on commit 9a78970

Please sign in to comment.