Skip to content

Commit

Permalink
Make API to reform functionality more editable
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Dec 27, 2023
1 parent a3fbacf commit fe5bf0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 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: patch
changes:
fixed:
- API to reform functionality made more editable.
43 changes: 26 additions & 17 deletions policyengine_core/reforms/reform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

from policyengine_core.parameters import ParameterNode, Parameter
from policyengine_core.taxbenefitsystems import TaxBenefitSystem
from policyengine_core.periods import period as period_, instant as instant_
from policyengine_core.periods import (
period as period_,
instant as instant_,
Period,
)

import requests

Expand Down Expand Up @@ -163,22 +167,27 @@ def from_api(

parameter_values = data.get("result", {}).get("policy_json", {})

class reform(Reform):
def apply(self):
for parameter, schedule in parameter_values.items():
for time_period_string, value in schedule.items():
start, end = time_period_string.split(".")
self.modify_parameters(
set_parameter(
path=parameter,
start=start,
stop=end,
value=value,
return_modifier=True,
)
)

return reform
for path in parameter_values:
keys_to_remove = []

Check warning on line 171 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L171

Added line #L171 was not covered by tests
for start_stop_str in list(parameter_values[path].keys()):
start, stop = start_stop_str.split(".")
time_period = str(

Check warning on line 174 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L173-L174

Added lines #L173 - L174 were not covered by tests
period_("year:2000:100").intersection(
instant_(start), instant_(stop)
)
)
parameter_values[path][time_period] = parameter_values[path][

Check warning on line 179 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L179

Added line #L179 was not covered by tests
start_stop_str
]
keys_to_remove.append(start_stop_str)

Check warning on line 182 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L182

Added line #L182 was not covered by tests
for key in keys_to_remove:
del parameter_values[path][key]

Check warning on line 184 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L184

Added line #L184 was not covered by tests

return Reform.from_dict(

Check warning on line 186 in policyengine_core/reforms/reform.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/reforms/reform.py#L186

Added line #L186 was not covered by tests
parameter_values,
country_id,
data.get("result", {}).get("label", None),
)

@classproperty
def api_id(self):
Expand Down

0 comments on commit fe5bf0d

Please sign in to comment.