openfisca / openfisca-web-api

[DEPRECATED] Web API for OpenFisca
https://www.openfisca.fr/
GNU Affero General Public License v3.0
13 stars 11 forks source link

Create a new version of the variables endpoint #125

Closed MattiSG closed 7 years ago

MattiSG commented 7 years ago

Proposition 1

/variables endpoint

List of all variables as an object mapping their variable name to objects containing a description property whose value is their label, matching the /parameters endpoint.

Each variable is then exposed under the /variable/{{name}} URL as an object whose values are documented below.

InputVariable

Before

{
    "@type": "Float",
    "default": 0,
    "entity": "individu",
    "label": "Salaire de base, en général appelé salaire brut, la 1ère ligne sur la fiche de paie",
    "start_line_number": 479,
    "source_code": "class salaire_de_base(Variable):\n    column = FloatCol\n    entity = Individu\n    label = u\"Salaire de base, en général appelé salaire brut, la 1ère ligne sur la fiche de paie\"\n    set_input = set_input_divide_by_period\n    url = u'http://www.insee.fr/fr/methodes/default.asp?page=definitions/salaire-mensuel-base-smb.htm'\n    definition_period = MONTH\n",
    "source_file_path": "model/revenus/activite/salarie.py",
    "name": "salaire_de_base",
    "url": "http://www.insee.fr/fr/methodes/default.asp?page=definitions/salaire-mensuel-base-smb.htm"
},

After

"salaire_de_base": {
    "description": "Salaire de base, en général appelé salaire brut, la 1ère ligne sur la fiche de paie",
    "valueType": "Float",
    "defaultValue": 0,
    "definitionPeriod": "month",
    "entity": "individu",
    "reference": "http://www.insee.fr/fr/methodes/default.asp?page=definitions/salaire-mensuel-base-smb.htm",
    "source": "https://github.com/openfisca/openfisca-france/master/model/revenus/activite/salarie.py#L479-489"
},

Variable

Before

{
    "@type": "Float",
    "default": 0,
    "entity": "famille",
    "label": "Allocations logements",
    "start_line_number": 354,
    "source_code": "class aides_logement(Variable):\n    column = FloatCol\n    entity = Famille\n    label = u\"Allocations logements\"\n    url = \"http://vosdroits.service-public.fr/particuliers/N20360.xhtml\"\n    definition_period = YEAR\n\n    def function(famille, period):\n        '''\n        Prestations logement\n        '''\n        apl = famille('apl', period, options = [ADD])\n        als = famille('als', period, options = [ADD])\n        alf = famille('alf', period, options = [ADD])\n        crds_logement = famille('crds_logement', period, options = [ADD])\n\n        return apl + als + alf + crds_logement\n",
    "source_file_path": "model/mesures.py",
    "name": "aides_logement",
    "url": "http://vosdroits.service-public.fr/particuliers/N20360.xhtml",
    "formula": {
        "@type": "SimpleFormula",
        "comments": null,
        "doc": "Prestations logement"
    }
},

After

"aides_logement": {
    "description": "Allocations logements",
    "valueType": "Float",
    "defaultValue": 0,
    "definitionPeriod": "month",
    "entity": "famille",
    "reference": "http://vosdroits.service-public.fr/particuliers/N20360.xhtml",
    "source": "https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L354-L367",
    "formulas": {
        "0001-01-01": {
            "source": "https://github.com/openfisca/openfisca-france/master/model/mesures.py#L360-L367",
            "content": "def function(famille, period):\n        '''\n        Prestations logement\n        '''\n        apl = famille('apl', period, options = [ADD])\n        als = famille('als', period, options = [ADD])\n        alf = famille('alf', period, options = [ADD])\n        crds_logement = famille('crds_logement', period, options = [ADD])\n\n        return apl + als + alf + crds_logement\n"
        }
    }
},

DatedVariable

Before

{
    "@type": "Float",
    "default": 0,
    "entity": "famille",
    "label": "Revenu de référence, basé sur la situation familiale, pris en compte dans le calcul des AL.",
    "start_line_number": 419,
    "source_code": "class aide_logement_R0(DatedVariable):\n    column = FloatCol\n    entity = Famille\n    label = u\"Revenu de référence, basé sur la situation familiale, pris en compte dans le calcul des AL.\"\n    definition_period = MONTH\n\n    @dated_function(stop = date(2014, 12, 31))\n    def function_2014(famille, period, legislation):\n        al = legislation(period).prestations.aides_logement\n        pfam_n_2 = legislation(period.start.offset(-2, 'year')).prestations.prestations_familiales\n        minim_n_2 = legislation(period.start.offset(-2, 'year')).prestations.minima_sociaux\n        couple = famille('al_couple', period)\n        al_nb_pac = famille('al_nb_personnes_a_charge', period)\n        residence_dom = famille.demandeur.menage('residence_dom', period)\n\n        n_2 = period.start.offset(-2, 'year')\n        if n_2.date >= date(2009, 6, 01):\n            montant_de_base = minim_n_2.rsa.montant_de_base_du_rsa\n        else:\n            montant_de_base = minim_n_2.rmi.montant_de_base_du_rmi\n\n        R1 = montant_de_base * (\n            al.r1.personne_isolee * not_(couple) * (al_nb_pac == 0) +\n            al.r1.couple_sans_enf * couple * (al_nb_pac == 0) +\n            al.r1.personne_isolee_ou_couple_avec_1_enf * (al_nb_pac == 1) +\n            al.r1.personne_isolee_ou_couple_avec_2_enf * (al_nb_pac >= 2) +\n            al.r1.majoration_enfant_a_charge_supp * (al_nb_pac > 2) * (al_nb_pac - 2)\n            )\n\n        R2 = pfam_n_2.af.bmaf * (\n            al.r2.taux3_dom * residence_dom * (al_nb_pac == 1) +\n            al.r2.personnes_isolees_ou_couples_avec_2_enf * (al_nb_pac >= 2) +\n            al.r2.majoration_par_enf_supp_a_charge * (al_nb_pac > 2) * (al_nb_pac - 2)\n            )\n\n        R0 = round_(12 * (R1 - R2) * (1 - al.autres.abat_sal))\n\n        return R0\n\n    # cf Décret n° 2014-1739 du 29 décembre 2014 relatif au calcul des aides personnelles au logement\n    @dated_function(start = date(2015, 1, 1))\n    def function_2015(famille, period, legislation):\n        al = legislation(period).prestations.aides_logement\n        couple = famille('al_couple', period)\n        al_nb_pac = famille('al_nb_personnes_a_charge', period)\n\n        R0 = (\n            al.R0.taux_seul * not_(couple) * (al_nb_pac == 0) +\n            al.R0.taux_couple * couple * (al_nb_pac == 0) +\n            al.R0.taux1pac * (al_nb_pac == 1) +\n            al.R0.taux2pac * (al_nb_pac == 2) +\n            al.R0.taux3pac * (al_nb_pac == 3) +\n            al.R0.taux4pac * (al_nb_pac == 4) +\n            al.R0.taux5pac * (al_nb_pac == 5) +\n            al.R0.taux6pac * (al_nb_pac == 6) +\n            al.R0.taux_pac_supp * (al_nb_pac > 6) * (al_nb_pac - 6)\n            )\n\n        return R0\n",
    "source_file_path": "model/prestations/aides_logement.py",
    "name": "aide_logement_R0",
    "formula": {
        "@type": "DatedFormula",
        "dated_formulas": [
            {
                "formula": {
                    "@type": "SimpleFormula",
                    "comments": null,
                    "doc": null
                },
                "stop_instant": "2014-12-31",
                "start_instant": null
            },
            {
                "formula": {
                    "@type": "SimpleFormula",
                    "comments": "# cf Décret n° 2014-1739 du 29 décembre 2014 relatif au calcul des aides personnelles au logement\n",
                    "doc": null
                },
                "stop_instant": null,
                "start_instant": "2015-01-01"
            }
        ]
    }
},

After

"aide_logement_R0": {
    "description": "Revenu de référence, basé sur la situation familiale, pris en compte dans le calcul des AL.",
    "valueType": "Float",
    "defaultValue": 0,
    "definitionPeriod": "month",
    "entity": "famille",
    "source": "https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L400-L450",
    "formulas": {
        "2015-01-01": {
            "source": "https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L440-L450",
            "content": "def function_2015(famille, period, legislation):\n        al = legislation(period).prestations.aides_logement\n        couple = famille('al_couple', period)\n        al_nb_pac = famille('al_nb_personnes_a_charge', period)\n\n        R0 = (\n            al.R0.taux_seul * not_(couple) * (al_nb_pac == 0) +\n            al.R0.taux_couple * couple * (al_nb_pac == 0) +\n            al.R0.taux1pac * (al_nb_pac == 1) +\n            al.R0.taux2pac * (al_nb_pac == 2) +\n            al.R0.taux3pac * (al_nb_pac == 3) +\n            al.R0.taux4pac * (al_nb_pac == 4) +\n            al.R0.taux5pac * (al_nb_pac == 5) +\n            al.R0.taux6pac * (al_nb_pac == 6) +\n            al.R0.taux_pac_supp * (al_nb_pac > 6) * (al_nb_pac - 6)\n            )\n\n        return R0"
        },
        "0001-01-01": {
            "source": "https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L430-L440",
            "content": "def function_2014(famille, period, legislation):\n        al = legislation(period).prestations.aides_logement\n        pfam_n_2 = legislation(period.start.offset(-2, 'year')).prestations.prestations_familiales\n        minim_n_2 = legislation(period.start.offset(-2, 'year')).prestations.minima_sociaux\n        couple = famille('al_couple', period)\n        al_nb_pac = famille('al_nb_personnes_a_charge', period)\n        residence_dom = famille.demandeur.menage('residence_dom', period)\n\n        n_2 = period.start.offset(-2, 'year')\n        if n_2.date >= date(2009, 6, 01):\n            montant_de_base = minim_n_2.rsa.montant_de_base_du_rsa\n        else:\n            montant_de_base = minim_n_2.rmi.montant_de_base_du_rmi\n\n        R1 = montant_de_base * (\n            al.r1.personne_isolee * not_(couple) * (al_nb_pac == 0) +\n            al.r1.couple_sans_enf * couple * (al_nb_pac == 0) +\n            al.r1.personne_isolee_ou_couple_avec_1_enf * (al_nb_pac == 1) +\n            al.r1.personne_isolee_ou_couple_avec_2_enf * (al_nb_pac >= 2) +\n            al.r1.majoration_enfant_a_charge_supp * (al_nb_pac > 2) * (al_nb_pac - 2)\n            )\n\n        R2 = pfam_n_2.af.bmaf * (\n            al.r2.taux3_dom * residence_dom * (al_nb_pac == 1) +\n            al.r2.personnes_isolees_ou_couples_avec_2_enf * (al_nb_pac >= 2) +\n            al.r2.majoration_par_enf_supp_a_charge * (al_nb_pac > 2) * (al_nb_pac - 2)\n            )\n\n        R0 = round_(12 * (R1 - R2) * (1 - al.autres.abat_sal))\n\n        return R0\n\n    # cf Décret n° 2014-1739 du 29 décembre 2014 relatif au calcul des aides personnelles au logement"
        }
    }
},

Notes