openfisca / legislation-explorer

Explore legislation formulas and parameters.
https://legislation.demo.openfisca.org
GNU Affero General Public License v3.0
26 stars 12 forks source link

List enum member names #95

Closed guillett closed 7 years ago

guillett commented 7 years ago

Some variables are EnumCol (cf. rsa_non_calculable in legislation explorer and rsa_non_calculable code).

As a user/consumer:

Currently, I would use those details to validate a structure in a client application - MesAides that add metadata to openfisca variables.

benjello commented 7 years ago

Same problem for allegement_fillon_mode_recouvrement

MattiSG commented 7 years ago

Thanks for this suggestion @guillett! However, it is not very clear to me what you're suggesting, since this issue is opened in legislation-explorer but mentions the API. What is the most important for you: machine access of enum members through the API (and in this case, on which endpoint?), or listing these members in the legislation explorer? 🙂

benjello commented 7 years ago

For me it is listing these members in the legislation explorer

guillett commented 7 years ago

@MattiSG, the most important for me is the machine access via the API. That is why I created an new issue in openfisca-web-api.

Having said that once it is available via the API, I would love to see it in the legislation explorer. 🙂

MattiSG commented 7 years ago
fpagnoux commented 7 years ago

To implement this, we'll need to expose the values of the enum elements in the API.

Structure

Suggestion 1

{
  "defaultValue": 0, 
  "description": "Activité", 
  "id": "activite", 
  "valueType": "Enum",
  "possibleValues": {
    "Actif occupé": 0,
    "Autre inactif": 4,
    "ChĂ´meur": 1,
    "Étudiant, élève": 2,
    "Retraité": 3
  }
}

Suggestion 2

{
  "defaultValue": 0, 
  "description": "Activité", 
  "id": "activite", 
  "valueType": "Enum",
  "possibleValues": {
    "0": "Actif occupé",
    "1": "ChĂ´meur",
    "2": "Étudiant, élève",
    "3": "Retraité",
    "4": "Autre inactif"
  }
}

Keyword

Suggestion A: possibleValues Suggestion B: values Suggestion C: elements

@guillett @benjello @MattiSG @Anna-Livia @sandcha @Morendil thoughts ?

EDIT: I forgot @michelbl

guillett commented 7 years ago

Suggestion D: members ?

2 - D

fpagnoux commented 7 years ago

members is already used in another context in OpenFisca (the members of an entity). Plus, is it clear what the members of a variable are ?

fpagnoux commented 7 years ago

Or, following swagger style:

Suggestion 3

{
  "defaultValue": "Actif occupé", 
  "description": "Activité", 
  "id": "activite", 
  "valueType": "String",
  "enum": [
    "Actif occupé",
    "Autre inactif",
    "ChĂ´meur",
    "Étudiant, élève",
    "Retraité"
  ]
}

But that notation totally omits the indexes. We can make sure the API accepts strings as inputs for enums (instead of ints) but inside OpenFisca, enums values are integers 🤔 .

For instance, this code doesn't work as expected:

person('activite', period) == u'ChĂ´meur'  # False, as person('activite', period)  is an integer
guillett commented 7 years ago

Note for suggestion 3: It can contain null for enum like statut_marital that start at 1

Anna-Livia commented 7 years ago

suggestion 3 for the structure, "possibleValues" for the key :)

Morendil commented 7 years ago

3 - B

I favor the array representation over the other ones because it communicates an intention of doing the simplest thing, labeling enum values like array indexes - starting at 0, in order and without skipping any values.

benjello commented 7 years ago

2-B