Skip to content

Commit

Permalink
Make API to reform functionality more editable (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff authored Dec 27, 2023
1 parent a3fbacf commit c6723bc
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 = []
for start_stop_str in list(parameter_values[path].keys()):
start, stop = start_stop_str.split(".")
time_period = str(
period_("year:2000:100").intersection(
instant_(start), instant_(stop)
)
)
parameter_values[path][time_period] = parameter_values[path][
start_stop_str
]
keys_to_remove.append(start_stop_str)
for key in keys_to_remove:
del parameter_values[path][key]

return Reform.from_dict(
parameter_values,
country_id,
data.get("result", {}).get("label", None),
)

@classproperty
def api_id(self):
Expand Down

0 comments on commit c6723bc

Please sign in to comment.