-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a simple computation endpoint #520
Comments
Features
Headers
Errors
Documentation
|
We started to discuss suggestions to represent scenarios (persons and entities) with @Anna-Livia: ❌ Suggestion 1: Persons reference their entities"persons": {
"bob": {
"birth_date": "1972-01-01",
"family": {
"dupont": "parent"
},
"company": {
"Boulangerie": "owner"
},
},
"bill": {
"birth_date": "1975-01-01",
"family": {
"dupont": "parent"
},
"company": {
"Boulangerie": "employee"
},
},
"janet": {
"birth_date": "1990-01-01",
"company": {
"Electrician": "employee"
},
"family": {
"dupont": "child"
},
},
},
"families": {
"dupont": {
"zipcode": "90210"
}
},
"companies": {
"boulangerie": {
"revenue": 20000
},
"electrician": {
"revenue": 40000
}
}
Details :
Advantages:
Constraints:
|
✅ Suggestion 2: Entities reference their members through their ID"persons": {
"bob": {
"birth_date": "1972-01-01",
},
"bill": {
"birth_date": "1975-01-01",
},
"janet": {
"birth_date": "1990-01-01",
},
},
"familles": {
"dupont": {
"parents": ["bob", "bill"],
"children": ["janet"],
"zip_code": "90210"
}
},
"companies":
"boulangerie": {
"owner": ["bob"],
"employee": ["bill"],
"revenue": 20000
},
"electrician": {
"employee": ["janet"],
"revenue": 40000
}
} Details :
Advantages:
Constraints:
Note : this is a slightly simplified version of the current API |
❌ Suggestion 3 - Persons can be defined inside entities3a - Using unique ids for persons"families": {
"dupont": {
"parents": {
"bob": {"birth_date": "1972-01-01"},
"bill": {"birth_date": "1975-01-01"}
},
"children": {
"janet": {"birth_date": "1990-01-01"}
}
},
},
"companies": {
"boulangerie": {
"owner": ["bob"],
"employees": ["bill"],
"revenue": 20000,
},
"electrician": {
"employees":["janet"],
"revenue": 40000,
}
} This is strictly equivalent to: "families": {
"dupont": {
"parents": ["bob", "bill"],
"children": ["janet"],
"zipcode": "90210"
}
},
"companies": {
"boulangerie": {
"owner": {
"bob": {"birth_date": 1972-01-01}
},
"employees": {
"bill": {"birth_date": 1975-01-01},
},
"revenue": 20000,
},
"electrician": {
"employees": {
"janet": {"birth_date": 1990-01-01}
},
"revenue": 40000,
}
}, Details:
Advantages:
Constraints:
For clients who are not interested in any group entity, this would be allowed as well: "persons": {
"bill": {"birth_date": "1972-01-01", "salary": "2000"},
"bob": {"birth_date": "1972-01-01", "salary": "1500"},
} |
❌ 3b - Using JSON pathThe first example of "families": {
"dupont": {
"parents": {
"bob": {"birth_date": "1972-01-01"},
"bill": {"birth_date": "1975-01-01"}
},
"children": {
"janet": {"birth_date": "1990-01-01"}
}
},
},
"companies": {
"boulangerie": {
"owner": ["$.families.dupont.parents.bob"],
"employees": ["$.families.dupont.parents.bill"],
"revenue": 20000,
},
"electrician": {
"employees":["$.families.dupont.children.janet"],
"revenue": 40000,
}
}, Compared to Advantages:
Constraints:
|
❌ 3c - Using arrays for all person listsThe first example of "families": {
"dupont": {
"parents": [
{"bob": {"birth_date": "1972-01-01"}},
{"bill": {"birth_date": "1975-01-01"}}
],
"children": [
{"janet": {"birth_date": "1990-01-01"}}
]
},
},
"companies": {
"boulangerie": {
"owner": ["bob"],
"employees": ["bill"],
"revenue": 20000,
},
"electrician": {
"employees":["janet"],
"revenue": 40000,
}
} Compared to Details:
Advantages:
Constraints:
|
Another topic to discuss is how the client expresses which variable they want to calculate. ❌ Suggestion I : in the URLIa: with a common period of requested variableFollowing the model of the current
or
to compute several variables. Advantages: Constraints
|
❌ Suggestion II : in the request body, separated from the scenarioFor instance: "scenario": {
"familles": {"...": "..."}
},
"outputs": {
"2010-01": ["rsa", "salaire_net"]
} Advantages:
Constraints:
|
✅ Suggestion III: in the request body, integrated in the scenario"persons": {
"bob": {
"birth_date": "1972-01-01",
"salaire_brut": {"2010-01": 2000 },
"salaire_net": {"2010-01": null }
},
"bill": {
"birth_date": "1975-01-01",
},
"janet": {
"birth_date": "1990-01-01",
},
},
"familles": {
"dupont": {
"parents": ["bob", "bill"],
"children": ["janet"],
"zip_code": "90210"
}
},
"companies":
"boulangerie": {
"owner": ["bob"],
"employee": ["bill"],
"revenue": 20000
},
"electrician": {
"employee": ["janet"],
"revenue": 40000
}
} Details:
Advantages:
"janet": {
"student": {"$from": "2010-09", "$to": "2013-06", "$value": true}
} Constraints:
|
About the calculation : I like having the calculation variable inside the URL:
About the periods, I think that one API call should concern one period. There should be a way to alert the user and/or handle the calculation on a period not adapted to the variable. Suggestion IA for calculations seems to me to be the best suited :) |
@fpagnoux : my preference goes to suggestion 2 and suggestion II (the latter for clarity but I cannot estimate the burden induced by a complex/complete header). |
Thanks a lot @fpagnoux & @Anna-Livia for this work! 👏 EntitiesBeliefs
OpinionI like the readability of 1, but I prefer the writability and consolidation of 2. Each entity type defines its specific variables, which means it is easier to have a common data model between OpenFisca and the client code. ConclusionI'm in favour of 2. Computation requestBeliefs
Opinion
Open questions
|
Great, it seems that we have our first consensus: entities will be described according to suggestion 2. If anyone disagree, let them speak now or forever hold their peace. |
With I and II, if the client requires to calculate This is a little advantage for III : if I'm only interested in the output for one person, I may be confused by the 4 results I'm getting for all the family members. |
Another topic to discuss, and that may influence our choice for II vs III is the output format. IMO, the output format should be similar to the input one, as in both cases we are describing the values of some variables for some entities. So, if we are computing ❌ Suggestion A"persons": {
"bob": {
"salaire_net": {"2010-01": 1500}
},
"bill": {
"salaire_net": {"2010-01": 0}
},
"janet": {
"salaire_net": {"2010-01": 0}
},
},
"familles": {
"dupont": {
"rsa": {"2010-01": 500}
}
} Details:
Advantages:
Constraints:
|
The opposite solution is to repeat the whole input: ✅ Suggestion B"persons": {
"bob": {
"birth_date": {"ETERNITY": "1972-01-01" },
"salaire_net": {"2010-01": 1500}
},
"bill": {
"birth_date": {"ETERNITY": "1975-01-01" },
"salaire_net": {"2010-01": 0}
},
"janet": {
"birth_date": {"ETERNITY": "1990-01-01" },
"salaire_net": {"2010-01": 0}
},
},
"families": {
"dupont": {
"parents": ["bob", "bill"],
"children": ["janet"],
"zip_code": {"2010-01": "90210"},
"rsa": {"2010-01": 500}
}
},
"companies":
"boulangerie": {
"owner": ["bob"],
"employee": ["bill"],
"revenue": {"2010-01": 20000}
},
"electrician": {
"employee": ["janet"],
"revenue": {"2010-01": 40000}
}
} Details:
Advantages:
Constraints:
This approach seems interesting if combined with III. |
Additional constraint on B : I need the input to know what was computed vs what was provided as input. |
This feels like a performance vs usability case, with no information on the impact on either performance or usability. I don't think we can have a definite decision in pure theory.
I'd go with IIIA and observe implementors usage, because A is forward-compatible with B while B isn't with A. |
Just a recap (to amend if incorrect):
Suggestion AbCloser to the current response (https://mes-aides.gouv.fr/api/situations/58d3eeddd1eb3ef92014ad64/openfisca-response) (replace {
"computations": {
/*Results from suggestion A*/
"familles": {"...": "..."},
"persons": {"...": "..."}
},
} Optionally, inputs can be included as-is ( Thinking on paper: A Suggestion IIb could be {
/* ... */
request: {
variables: { "2010-01": ["rsa", "salaire_net"] },
include_intermediate_variables: true,
/* other parameters */
}
} . I will try to discuss with @fpagnoux IRL today and provide more details here if it is relevant. |
Ok, so if I understand well you suggest to:
|
@MattiSG To be sure: you mean using the placeholders |
Yes. I am not sure |
ErrorsVariable doesn't existIf I send the flawed request: "persons": {
"bob": {
"birth_date": "1972-01-01",
"variable_that_doesnt_exist": {"2010-01": 2000 },
"salaire_net": {"2010-01": null }
},
"bill": {
"birth_date": "1975-01-01",
},
"janet": {
"birth_date": "1990-01-01",
}
},
"familles": {
"dupont": {
"parents": ["bob", "bill"],
"children": ["janet"],
"zip_code": "90210"
}
},
"companies":
"boulangerie": {
"owner": ["bob"],
"employee": ["bill"],
"revenue": 20000
},
"electrician": {
"employee": ["janet"],
"revenue": 40000
}
} The response has the error code "persons": {
"bob": {
"variable_that_doesnt_exist": "You tried to calculate or to set a value for variable 'variable_that_doesnt_exist', but it was not found in the loaded tax and benefit system (openfisca-france@18.5.1). Are you sure you spelled 'variable_that_doesnt_exist' correctly? If this code used to work and suddenly does not, this is most probably linked to an update of the tax and benefit system. Look at its changelog to learn about renames and removals and update your code. If it is an official package, it is probably available on <https://github.com/openfisca/openfisca-france/blob/master/CHANGELOG.md>.",
}
} |
Other cases:
|
As a producer,
I can send a situation to api.openfisca.fr and compute variables on it,
So that I don't have to manage my own instance
This currently exists through the
simulate
andcalculate
endpoints, but their data formats are very complex and not properly documented. This new endpoint should remind of the simpler versions of the/parameters
and/variables
endpoint that have already been added to the Core.The text was updated successfully, but these errors were encountered: