{"action":"opened","issue":{"url":"https://api.github.com/repos/openfisca/openfisca-web-api/issues/125","repository_url":"https://api.github.com/repos/openfisca/openfisca-web-api","labels_url":"https://api.github.com/repos/openfisca/openfisca-web-api/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/openfisca/openfisca-web-api/issues/125/comments","events_url":"https://api.github.com/repos/openfisca/openfisca-web-api/issues/125/events","html_url":"https://github.com/openfisca/openfisca-web-api/issues/125","id":223136815,"number":125,"title":"Create a new version of the variables endpoint","user":{"login":"MattiSG","id":222463,"avatar_url":"https://avatars0.githubusercontent.com/u/222463?v=3","gravatar_id":"","url":"https://api.github.com/users/MattiSG","html_url":"https://github.com/MattiSG","followers_url":"https://api.github.com/users/MattiSG/followers","following_url":"https://api.github.com/users/MattiSG/following{/other_user}","gists_url":"https://api.github.com/users/MattiSG/gists{/gist_id}","starred_url":"https://api.github.com/users/MattiSG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MattiSG/subscriptions","organizations_url":"https://api.github.com/users/MattiSG/orgs","repos_url":"https://api.github.com/users/MattiSG/repos","events_url":"https://api.github.com/users/MattiSG/events{/privacy}","received_events_url":"https://api.github.com/users/MattiSG/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-20T17:10:05Z","updated_at":"2017-04-20T17:10:05Z","closed_at":null,"body":"# Proposition 1\n\n## `/variables` endpoint\n\nList 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.\n\nEach variable is then exposed under the `/variable/{{name}}` URL as an object whose values are documented below.\n\n## InputVariable\n\n### Before\n\n```json\n{\n\t\"@type\": \"Float\",\n\t\"default\": 0,\n\t\"entity\": \"individu\",\n\t\"label\": \"Salaire de base, en général appelé salaire brut, la 1ère ligne sur la fiche de paie\",\n\t\"start_line_number\": 479,\n\t\"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\",\n\t\"source_file_path\": \"model/revenus/activite/salarie.py\",\n\t\"name\": \"salaire_de_base\",\n\t\"url\": \"http://www.insee.fr/fr/methodes/default.asp?page=definitions/salaire-mensuel-base-smb.htm\"\n},\n```\n\n### After\n\n```json\n\"salaire_de_base\": {\n\t\"description\": \"Salaire de base, en général appelé salaire brut, la 1ère ligne sur la fiche de paie\",\n\t\"valueType\": \"Float\",\n\t\"defaultValue\": 0,\n\t\"definitionPeriod\": \"month\",\n\t\"entity\": \"individu\",\n\t\"reference\": \"http://www.insee.fr/fr/methodes/default.asp?page=definitions/salaire-mensuel-base-smb.htm\",\n\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/revenus/activite/salarie.py#L479-489\"\n},\n```\n\n## Variable\n\n### Before\n\n```json\n{\n\t\"@type\": \"Float\",\n\t\"default\": 0,\n\t\"entity\": \"famille\",\n\t\"label\": \"Allocations logements\",\n\t\"start_line_number\": 354,\n\t\"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\",\n\t\"source_file_path\": \"model/mesures.py\",\n\t\"name\": \"aides_logement\",\n\t\"url\": \"http://vosdroits.service-public.fr/particuliers/N20360.xhtml\",\n\t\"formula\": {\n\t\t\"@type\": \"SimpleFormula\",\n\t\t\"comments\": null,\n\t\t\"doc\": \"Prestations logement\"\n\t}\n},\n```\n\n### After\n\n```json\n\"aides_logement\": {\n\t\"description\": \"Allocations logements\",\n\t\"valueType\": \"Float\",\n\t\"defaultValue\": 0,\n\t\"definitionPeriod\": \"month\",\n\t\"entity\": \"famille\",\n\t\"reference\": \"http://vosdroits.service-public.fr/particuliers/N20360.xhtml\",\n\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L354-L367\",\n\t\"formulas\": {\n\t\t\"0001-01-01\": {\n\t\t\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/mesures.py#L360-L367\",\n\t\t\t\"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\"\n\t\t}\n\t}\n},\n```\n\n## DatedVariable\n\n### Before\n\n```json\n{\n\t\"@type\": \"Float\",\n\t\"default\": 0,\n\t\"entity\": \"famille\",\n\t\"label\": \"Revenu de référence, basé sur la situation familiale, pris en compte dans le calcul des AL.\",\n\t\"start_line_number\": 419,\n\t\"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\",\n\t\"source_file_path\": \"model/prestations/aides_logement.py\",\n\t\"name\": \"aide_logement_R0\",\n\t\"formula\": {\n\t\t\"@type\": \"DatedFormula\",\n\t\t\"dated_formulas\": [\n\t\t\t{\n\t\t\t\t\"formula\": {\n\t\t\t\t\t\"@type\": \"SimpleFormula\",\n\t\t\t\t\t\"comments\": null,\n\t\t\t\t\t\"doc\": null\n\t\t\t\t},\n\t\t\t\t\"stop_instant\": \"2014-12-31\",\n\t\t\t\t\"start_instant\": null\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"formula\": {\n\t\t\t\t\t\"@type\": \"SimpleFormula\",\n\t\t\t\t\t\"comments\": \"# cf Décret n° 2014-1739 du 29 décembre 2014 relatif au calcul des aides personnelles au logement\\n\",\n\t\t\t\t\t\"doc\": null\n\t\t\t\t},\n\t\t\t\t\"stop_instant\": null,\n\t\t\t\t\"start_instant\": \"2015-01-01\"\n\t\t\t}\n\t\t]\n\t}\n},\n```\n\n### After\n\n```json\n\"aide_logement_R0\": {\n\t\"description\": \"Revenu de référence, basé sur la situation familiale, pris en compte dans le calcul des AL.\",\n\t\"valueType\": \"Float\",\n\t\"defaultValue\": 0,\n\t\"definitionPeriod\": \"month\",\n\t\"entity\": \"famille\",\n\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L400-L450\",\n\t\"formulas\": {\n\t\t\"2015-01-01\": {\n\t\t\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L440-L450\",\n\t\t\t\"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\"\n\t\t},\n\t\t\"0001-01-01\": {\n\t\t\t\"source\": \"https://github.com/openfisca/openfisca-france/master/model/prestations/aides_logement.py#L430-L440\",\n\t\t\t\"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\"\n\t\t}\n\t}\n},\n``` \n\n## Notes\n\n- The `comments` of the formulas is empty for all but 6 items, 5 of which are TODOs, the last one being an improperly-placed label (PR incoming to fix this). We can drop it.\n- The `doc` of the formulas is mostly misplaced labels with duplicate date information. We can drop it from the API, the data should be normalised into the labels.\n- We are not 100% satisfied with the `source` property name. `href` would be ambiguous since it would make the user leave the realm of the API itself.\n- The parsers do not currently expose the individual dated functions source code.\n- Many formulas have no start date. We default to `datetime.date.min`. We are not sure whether this information should be added by the API or set as a default for all formulas within each tax and benefits system, with the API simply exposing the data.\n- We remove the `class` source code, since all the information it contains is extracted and exposed as properties."}}
{"actor":{"display_login":"MattiSG"}}