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

Add variables to the new API #126

Closed fpagnoux closed 7 years ago

fpagnoux commented 7 years ago

Connected to #125 Depends on https://github.com/openfisca/openfisca-dummy-country/pull/6 Depends on https://github.com/openfisca/openfisca-core/pull/494

fpagnoux commented 7 years ago

A few exemples :

Input variable

{
    "defaultValue": "1970-01-01",
    "definitionPeriod": "eternity",
    "description": "Date de naissance",
    "entity": "individu",
    "id": "birth",
    "references": ["https://fr.wikipedia.org/wiki/Date_de_naissance"],
    "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L27-L32",
    "valueType": "Date"
}

Basic variable with a formula

{
    "defaultValue": 0,
    "definitionPeriod": "month",
    "description": "Salaire net",
    "entity": "individu",
    "formulas": {
        "0001-01-01": {
            "content": "def function(individu, period):\n    salaire_brut = individu('salaire_brut', period)\n\n    return salaire_brut * 0.8\n",
            "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L172-L175"
        }
    },
    "id": "salaire_net",
    "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L164-L175",
    "valueType": "Float"
}
fpagnoux commented 7 years ago

Interrupted dated variable

{
    "defaultValue": 0,
    "definitionPeriod": "month",
    "description": "Allocationd pour Parent Isolé",
    "entity": "famille",
    "formulas": {
        "2000-01-01": {
            "content": "def function_2000(famille, period):\n    nb_parents = famille.nb_persons(role = famille.PARENT)\n    nb_enfants = famille.nb_persons(role = famille.ENFANT)\n    condition = (nb_parents == 1) * (nb_enfants > 0)\n\n    return condition * 100\n",
            "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L229-L234"
        },
        "2005-01-01": {
            "content": "def function_2005(famille, period):\n    nb_parents = famille.nb_persons(role = famille.PARENT)\n    nb_enfants = famille.nb_persons(role = famille.ENFANT)\n    condition = (nb_parents == 1) * (nb_enfants > 0)\n\n    return condition * 200\n",
            "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L221-L226"
        },
        "2010-01-01": null
    },
    "id": "api",
    "source": "https://github.com/openfisca/openfisca-dummy-country/blob/0.1.5/openfisca_dummy_country/model/model.py#L212-L234",
    "valueType": "Float"
}
fpagnoux commented 7 years ago

Les liens github marcheront quand https://github.com/openfisca/openfisca-dummy-country/pull/6 sera mergée et publiée. Pour avoir un aperçu en attendant, remplacer 0.1.5 par add-variables-route-to-new-api/ dans l'URL.

fpagnoux commented 7 years ago