Skip to content

Commit

Permalink
Use options for full variable API output (#896)
Browse files Browse the repository at this point in the history
* Use options for full variable API output

* Fix bug

* Fix test
  • Loading branch information
nikhilwoodruff authored Nov 20, 2023
1 parent daae3f8 commit 0831706
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
changed:
- Add option to specify full or only-selected-variables /calculate option.
8 changes: 8 additions & 0 deletions policyengine_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
cache.cached(make_cache_key=make_cache_key)(get_calculate)
)

app.route("/<country_id>/calculate-full", methods=["POST"])(
cache.cached(make_cache_key=make_cache_key)(
lambda *args, **kwargs: get_calculate(
*args, **kwargs, add_missing=True
)
)
)

app.route(
"/<country_id>/economy/<policy_id>/over/<baseline_policy_id>",
methods=["GET"],
Expand Down
7 changes: 4 additions & 3 deletions policyengine_api/endpoints/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_household_under_policy(
)


def get_calculate(country_id: str) -> dict:
def get_calculate(country_id: str, add_missing: bool = False) -> dict:
"""Lightweight endpoint for passing in household and policy JSON objects and calculating without storing data.
Args:
Expand All @@ -378,8 +378,9 @@ def get_calculate(country_id: str) -> dict:
household_json = payload.get("household", {})
policy_json = payload.get("policy", {})

# Add in any missing yearly variables to household_json
household_json = add_yearly_variables(household_json, country_id)
if add_missing:
# Add in any missing yearly variables to household_json
household_json = add_yearly_variables(household_json, country_id)

country = COUNTRIES.get(country_id)

Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_yearly_var_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_get_calculate(client):
test_object["policy"] = test_policy
test_object["household"] = test_household

res = client.post("/us/calculate", json=test_object)
res = client.post("/us/calculate-full", json=test_object)
result_object = json.loads(res.text)["result"]

# Create a dict of entity singular and plural terms for testing
Expand Down

0 comments on commit 0831706

Please sign in to comment.