コード例 #1
0
def test_erfs_fpr_survey_simulation(year = 2012):
    survey_scenario = ErfsFprSurveyScenario.create(year = year, rebuild_input_data = True)
    data_frame_by_entity_key_plural = survey_scenario.create_data_frame_by_entity_key_plural(
        variables = [
            'aspa',
            'aide_logement_montant_brut',
            'idmen',
            'quimen',
            'idfoy',
            'quifoy',
            'idfam',
            'quifam',
            'age',
            'activite',
            'champm_individus',
            'pensions_alimentaires_percues',
            'salaire_imposable',
            'salaire_net',
            'autonomie_financiere',
            'af_nbenf',
            'af',
            'rsa_base_ressources',
            'rsa',
            'weight_familles',
            'revdisp',
            ]
        )

    return data_frame_by_entity_key_plural
コード例 #2
0
def get_survey_scenario(year = 2012, rebuild_input_data = False, tax_benefit_system = None,
        baseline_tax_benefit_system = None, data = None, reform_key = None):
    assert not(
        (tax_benefit_system is not None)
        & (reform_key is not None)
        )
    if tax_benefit_system is None:
        if reform_key is not None:
            tax_benefit_system = base_survey.get_cached_reform(
                reform_key = reform_key,
                tax_benefit_system = base_survey.france_data_tax_benefit_system,
                )
        else:
            tax_benefit_system = base_survey.france_data_tax_benefit_system

    if baseline_tax_benefit_system is None:
        baseline_tax_benefit_system = tax_benefit_system

    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        )
    if data is None:
        data = dict(
            input_data_table = dict(),
            input_data_survey_prefix = 'openfisca_erfs_fpr_data',
            )
    survey_scenario.init_from_data(
        data = data,
        rebuild_input_data = rebuild_input_data,
        )
    return survey_scenario
コード例 #3
0
def get_survey_scenario(year=2012, rebuild_input_data=False):
    tax_benefit_system = base_survey.france_data_tax_benefit_system

    class rsa_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class aah_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class paje_clca_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class hors_match(Variable):
        value_type = bool
        entity = Individu
        label = u"hors match"
        definition_period = MONTH

    class activite_famille_max(Variable):
        value_type = int
        entity = Famille
        label = u"activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite', period)
            return period, famille.max(activite, role=Famille.PARENT)

    class activite_famille_min(Variable):
        value_type = int
        entity = Famille
        label = u"activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite')
            return period, famille.min(activite, role=Famille.PARENT)

    tax_benefit_system.add_variable(activite_famille_max)
    tax_benefit_system.add_variable(activite_famille_min)

    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system=tax_benefit_system,
        year=year,
    )
    survey_scenario.init_from_survey_tables(
        rebuild_input_data=rebuild_input_data)
    return survey_scenario
コード例 #4
0
def test_erfs_fpr_aggregates_reform():
    survey_scenario = ErfsFprSurveyScenario.create(
        data_year=2012,
        year=2015,
        reform_key='plf2015',
    )

    aggregates = Aggregates(survey_scenario=survey_scenario)
    base_data_frame = aggregates.compute_aggregates()
    return aggregates, base_data_frame
コード例 #5
0
def test_erfs_fpr_survey_simulation_aggregates(year = 2012, rebuild_input_data = False):
    np.seterr(all='raise')
    tax_benefit_system = base_survey.france_data_tax_benefit_system
    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        )
    survey_scenario.init_from_survey_tables(rebuild_input_data = rebuild_input_data)
    return survey_scenario
コード例 #6
0
def test_erfs_aggregates_reform():
    '''
    test aggregates value with data
    :param year: year of data and simulation to test agregates
    :param reform: optional argument, put an openfisca_france.refoms object, default None
    '''
    survey_scenario = ErfsFprSurveyScenario.create(data_year = 2012, year = 2015, reform_key = 'plf2015')
    aggregates = Aggregates(survey_scenario = survey_scenario)
    base_data_frame = aggregates.compute_aggregates()

    return aggregates, base_data_frame
コード例 #7
0
def test_erfs_fpr_aggregates_reform():
    '''
    test aggregates value with data
    :param year: year of data and simulation to test agregates
    :param reform: optional argument, put an openfisca_france.refoms object, default None
    '''
    survey_scenario = ErfsFprSurveyScenario.create(data_year = 2012, year = 2015, reform_key = 'plf2015')
    aggregates = Aggregates(survey_scenario = survey_scenario)
    base_data_frame = aggregates.compute_aggregates()

    return aggregates, base_data_frame
コード例 #8
0
def get_survey_scenario(year=2012, rebuild_input_data=False):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key='inversion_directe_salaires',
        tax_benefit_system=base_survey.france_data_tax_benefit_system,
    )
    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system=tax_benefit_system,
        baseline_tax_benefit_system=tax_benefit_system,
        year=year,
        rebuild_input_data=rebuild_input_data,
    )
    return survey_scenario
コード例 #9
0
def test_erfs_fpr_survey_simulation(year = 2012, rebuild = False):
    tax_benefit_system = base_survey.get_cached_reform(
        reform_key = 'inversion_directe_salaires',
        tax_benefit_system = base_survey.france_data_tax_benefit_system,
        )
    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system = tax_benefit_system,
        baseline_tax_benefit_system = tax_benefit_system,
        year = year,
        # rebuild_input_data = True,
        )
    data_frame_by_entity = None
    #    data_frame_by_entity = survey_scenario.create_data_frame_by_entity(
#        variables = variables,
#        )
#    loose_check(data_frame_by_entity)
    return survey_scenario, data_frame_by_entity
コード例 #10
0
 def _survey_scenario(year: int) -> ErfsFprSurveyScenario:
     return ErfsFprSurveyScenario.create(
         tax_benefit_system = tax_benefit_system,
         year = year,
         )
コード例 #11
0
def get_survey_scenario(
        year: int = 2014,
        rebuild_input_data: bool = False,
        tax_benefit_system: Optional[TaxBenefitSystem] = None,
        baseline_tax_benefit_system: Optional[TaxBenefitSystem] = None,
        data: Any = None,  # Plusiers formats possibles.
        reform: Optional[Reform] = None,
        use_marginal_tax_rate: bool = False,
        variation_factor: float = 0.03,
        varying_variable: str = None,
        ) -> ErfsFprSurveyScenario:
    """Helper pour créer un `ErfsFprSurveyScenario`.

    :param year:                        L'année des données de l'enquête.
    :param rebuild_input_data:          Si l'on doit formatter les données (raw) ou pas.
    :param tax_benefit_system:          Le `TaxBenefitSystem` déjà réformé.
    :param baseline_tax_benefit_system: Le `TaxBenefitSystem` au droit courant.
    :param data:                        Les données de l'enquête.
    :param reform:                      Une réforme à appliquer à *france_data_tax_benefit_system*.
    """
    tax_benefit_system = get_tax_benefit_system(
        tax_benefit_system,
        reform,
        )

    baseline_tax_benefit_system = get_baseline_tax_benefit_system(
        baseline_tax_benefit_system,
        )

    if not use_marginal_tax_rate:
        survey_scenario = ErfsFprSurveyScenario.create(
            tax_benefit_system = tax_benefit_system,
            baseline_tax_benefit_system = baseline_tax_benefit_system,
            year = year,
            )
    else:
        assert varying_variable is not None, "You need to specify the varying variable."
        survey_scenario = ErfsFprSurveyScenario.create(
            tax_benefit_system = tax_benefit_system,
            baseline_tax_benefit_system = baseline_tax_benefit_system,
            year = year,
            )
        survey_scenario.variation_factor = variation_factor
        survey_scenario.varying_variable = varying_variable

    # S'il n'y a pas de données, on sait où les trouver.
    if data is None:
        input_data_table_by_entity = dict(
            individu = f"individu_{year}",
            menage = f"menage_{year}",
            )

        input_data_table_by_entity_by_period = dict()
        input_data_table_by_entity_by_period[year] = input_data_table_by_entity

        data = dict(
            input_data_table_by_entity_by_period = input_data_table_by_entity_by_period,
            input_data_survey_prefix = "openfisca_erfs_fpr_data",
            )

    # Les données peuvent venir en différents formats :
    #
    #  * Pandas' DataFrame
    #  * CSV
    #  * HDF5
    #  * Etc.
    #
    #  .. seealso:: :func:`ErfsFprSurveyScenario.init_from_data`
    survey_scenario.init_from_data(
        data = data,
        rebuild_input_data = rebuild_input_data,
        use_marginal_tax_rate = use_marginal_tax_rate,
        )

    return survey_scenario
コード例 #12
0
def test_weights_building():
    year = 2012
    survey_scenario = ErfsFprSurveyScenario.create(year = year)
    survey_scenario.new_simulation()
    return survey_scenario.simulation
コード例 #13
0
def get_custom_survey_scenario(year=2012, rebuild_input_data=False):
    tax_benefit_system = france_data_tax_benefit_system

    class rsa_origin(Variable):
        value_type = float
        entity = Famille
        label = "RSA de l'ENA"
        definition_period = MONTH

    class aah_origin(Variable):
        value_type = float
        entity = Famille
        label = "RSA de l'ENA"
        definition_period = MONTH

    class paje_clca_origin(Variable):
        value_type = float
        entity = Famille
        label = "RSA de l'ENA"
        definition_period = MONTH

    class hors_match(Variable):
        value_type = bool
        entity = Individu
        label = "hors match"
        definition_period = MONTH

    class activite_famille_max(Variable):
        value_type = int
        entity = Famille
        label = "activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite', period)
            return famille.max(activite, role=Famille.PARENT)

    class activite_famille_min(Variable):
        value_type = int
        entity = Famille
        label = "activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite', period)
            return famille.min(activite, role=Famille.PARENT)

    tax_benefit_system.add_variable(activite_famille_max)
    tax_benefit_system.add_variable(activite_famille_min)

    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system=tax_benefit_system,
        year=year,
    )
    data = dict(
        input_data_table=dict(),
        input_data_survey_prefix='openfisca_erfs_fpr_data',
    )
    survey_scenario.init_from_data(
        data=data,
        rebuild_input_data=rebuild_input_data,
    )
    return survey_scenario
コード例 #14
0
def get_survey_scenario(year = 2012, rebuild_input_data = False):
    tax_benefit_system = base_survey.france_data_tax_benefit_system

    class rsa_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class aah_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class paje_clca_origin(Variable):
        value_type = float
        entity = Famille
        label = u"RSA de l'ENA"
        definition_period = MONTH

    class hors_match(Variable):
        value_type = bool
        entity = Individu
        label = u"hors match"
        definition_period = MONTH

    class activite_famille_max(Variable):
        value_type = int
        entity = Famille
        label = u"activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite', period)
            return famille.max(activite, role = Famille.PARENT)

    class activite_famille_min(Variable):
        value_type = int
        entity = Famille
        label = u"activite_famille"
        definition_period = MONTH

        def formula(famille, period):
            activite = famille.members('activite', period)
            return famille.min(activite, role = Famille.PARENT)

    tax_benefit_system.add_variable(activite_famille_max)
    tax_benefit_system.add_variable(activite_famille_min)

    survey_scenario = ErfsFprSurveyScenario.create(
        tax_benefit_system = tax_benefit_system,
        year = year,
        )
    data = dict(
        input_data_table = dict(),
        input_data_survey_prefix = 'openfisca_erfs_fpr_data',
        )
    survey_scenario.init_from_data(
        data = data,
        rebuild_input_data = rebuild_input_data,
        )
    return survey_scenario
コード例 #15
0
def test_weights_building():
    year = 2012
    survey_scenario = ErfsFprSurveyScenario.create(year = year)
    survey_scenario.new_simulation()
    return survey_scenario.simulation
コード例 #16
0
def test_create_scenario(year):
    assert ErfsFprSurveyScenario(year)