-
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
Make parameters node accessible through the Web API #694
Conversation
Anyone for a review? @sandcha @maukoquiroga @Anna-Livia |
Question from @sandcha from slack (freely translated):
Yep, I thought about that aspect too. The distinction between Exposing leafs under The way I'd see the two routes is the following:
I'm not fully satisfied with that, but I can't think of something better. @MattiSG any light on the matter? |
Bluntly because I'm short on time: I see a stable point in renaming |
|
``` | ||
|
||
* Expose parameters nodes in the Web API | ||
- For instance, `/parameter/benefits` now exists and contains: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Already said above) Shouldn't it be
/parameters
for a node as it's not a parameter? 🤔
if parameter is None: | ||
# Try legacy route | ||
parameter_new_id = parameter_id.replace('.', '/') | ||
parameter = data['parameters'].get(parameter_new_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look for the parameter only when parameter_new_id
differs from parameter_id
to avoid looking into all parameters in that case (+2000 parameters in french model for example)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not looking into all parameters. The get
method of a dictionary has a O(1)
average complexity as it uses hashes.
tests/web_api/basic_case/__init__.py
Outdated
@@ -1,9 +0,0 @@ | |||
# -*- coding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And delete tests/web_api/basic_case/
now empty directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Git only tracks files, not directory. If the directory is empty, it's not tracked by Git. So the directory you see on your machine is only local 🙂 .
tests/web_api/test_parameters.py
Outdated
assert_equal(parameter['values'], {u'2016-12-01': None, u'2010-01-01': 0.25}) | ||
|
||
|
||
def test_bareme(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to test_scale
?
tests/web_api/test_parameters.py
Outdated
'/parameter/with%20url%20encoding': NOT_FOUND, | ||
'/parameter/taxes.income_tax_rate/': OK, | ||
'/parameter/taxes.income_tax_rate/too-much-nesting': NOT_FOUND, | ||
'/parameter//taxes.income_tax_rate/': NOT_FOUND, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to/Add '/parameter//taxes/income_tax_rate/': NOT_FOUND, ?
} | ||
``` | ||
|
||
* Expose parameters nodes in the Web API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit that it exposes 1 level of depth only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK (see node below)
@@ -3,12 +3,12 @@ | |||
from openfisca_core.parameters import Parameter, ParameterNode, Scale | |||
|
|||
|
|||
def transform_values_history(values_history): | |||
values_history_transformed = {} | |||
def build_api_values_history(values_history): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
def walk_node(node, parameters, path_fragments): | ||
def build_source_url(absolute_file_path, country_package_metadata): | ||
relative_path = absolute_file_path.replace(country_package_metadata['location'], '') | ||
return u'{}/blob/{}{}'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
tree
url rather thanblob
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tree
is for directories, and blob
for files, so
- either we detect whether the path is a file or a tree, and adjust the URL accordingly
- or we just let GitHub redirect us when relevant, which is pretty transparent
I'm more in favor of 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in favour of 2.
I missed something in the definition of blob-jects. 😬'
|
||
|
||
def walk_node(node, parameters, path_fragments): | ||
def build_source_url(absolute_file_path, country_package_metadata): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For taxes/income_tax_rate.yaml
parameter, we get "source": "https://github.com/openfisca/openfisca-country-template/blob/3.2.2/openfisca_country_template/parameters/taxes/income_tax_rate.yaml"
that leads to 404 error. Fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by openfisca/country-template#50
|
||
```JSON | ||
{ | ||
"description": "Social benefits", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicit that a node might have metadata? 🤔
I agree with the target, but I'm wondering what would be a good strategy to go towards that while
I think the most straight-forward strategy would be to
As much as it doesn't feel entirely satisfying to extend a route to rename it 2 months later, I think it won't be that bad for users, as they'll have to adapt their |
Fixes #678 (See discussions there about route spec)
Use
/
rather than.
in the path to access a parameter:/parameter/benefits.basic_income
becomes/parameter/benefits/basic_income
.
is for now still supported, but is considered deprecated and will be turned to a 301 redirection in the next major version.Expose parameters
metadata
andsource
in the Web API and:For instance,
/parameter/benefits/basic_income
contains:/parameter/benefits
now exists and contains: