Skip to content

Commit

Permalink
Merge pull request #2292 from martinholmer/better-params
Browse files Browse the repository at this point in the history
Provide simpler syntax to specify policy reforms and assumption updates
  • Loading branch information
martinholmer authored Apr 15, 2019
2 parents ed6413c + 257d9d4 commit 4e30417
Show file tree
Hide file tree
Showing 37 changed files with 4,048 additions and 4,540 deletions.
6 changes: 3 additions & 3 deletions docs/make_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def policy_param_text(pname, param):
else:
txt += '<br><i>Long Name:</i> {}'.format(param['long_name'])
txt += '<br><i>Description:</i> {}'.format(param['description'])
if len(param['notes']) > 0:
if len(param.get('notes', '')) > 0:
txt += '<br><i>Notes:</i> {}'.format(param['notes'])
txt += '<br><i>Has An Effect When Using:</i>'
txt += '&nbsp;&nbsp; <i>PUF data:</i> '
Expand Down Expand Up @@ -118,8 +118,8 @@ def policy_param_text(pname, param):
minval = param['valid_values']['min']
maxval = param['valid_values']['max']
txt += ' min = {} and max = {}'.format(minval, maxval)
txt += '<br><i>Out-of-Range Action:</i> {}'.format(
param['invalid_action'])
invalid_action = param.get('invalid_action', 'stop')
txt += '<br><i>Out-of-Range Action:</i> {}'.format(invalid_action)
txt += '</p>'
return txt

Expand Down
70 changes: 70 additions & 0 deletions new_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Command-line tool that converts Tax-Calculator JSON reform/assumption file
from the old (1.x) format to the new (2.0) format.
------------------------------------------------------------------------
WARNING: This program make certain assumptions about how the JSON file
is formatted, so it will not work correctly on a JSON file
that is not formatted in the assumed way. There is no risk
in trying it because a copy of the original JSON file is made.
------------------------------------------------------------------------
"""
# CODING-STYLE CHECKS:
# pycodestyle new_json.py
# pylint --disable=locally-disabled new_json.py

import os
import sys
import argparse
import shutil
import re


def main():
"""
Contains high-level logic.
"""
# parse command-line argument:
usage_str = 'python new_json.py FILENAME [--help]'
parser = argparse.ArgumentParser(
prog='',
usage=usage_str,
description=('Converts old (1.x) JSON reform/assumption file '
'named FILENAME to new (2.0) format. The newly '
'formatted file is also called FILENAME, while '
'the old file is saved as FILENAME-old.')
)
parser.add_argument('FILENAME', nargs='?',
help=('FILENAME is name of JSON-formatted file that '
'is to be converted.'),
default='')
args = parser.parse_args()
# check existence of FILENAME
if not os.path.isfile(args.FILENAME):
msg = 'ERROR: FILENAME={} does not exist'.format(args.FILENAME)
print(msg)
return 1
# copy FILENAME to FILENAME-old
shutil.copyfile(args.FILENAME, '{}-old'.format(args.FILENAME))
# read FILENAME into string
with open(args.FILENAME, 'r') as oldfile:
txt = oldfile.read()
# convert txt elements
defaults_file = (args.FILENAME == 'policy_current_law.json' or
args.FILENAME == 'consumption.json' or
args.FILENAME == 'growdiff.json')
if defaults_file:
txt = re.sub(r'(^\s*")_', r'\g<1>', txt, flags=re.MULTILINE)
else:
txt = re.sub(r'(\s*")_', r'\g<1>', txt, flags=re.MULTILINE)
txt = re.sub(r'\[([0-9tf\-])', r'\g<1>', txt, flags=re.MULTILINE)
txt = re.sub(r'([0-9e])\]', r'\g<1>', txt, flags=re.MULTILINE)
# write converted txt to FILENAME
with open(args.FILENAME, 'w') as newfile:
newfile.write(txt)
# normal return code
return 0
# end of main function code


if __name__ == '__main__':
sys.exit(main())
124 changes: 62 additions & 62 deletions taxcalc/assumptions/economic_assumptions_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,71 @@
// <http://PSLmodels.github.io/Tax-Calculator/#params>.
{
"consumption": {
"_MPC_e17500": {"2017": [0.0]},
"_MPC_e18400": {"2017": [0.0]},
"_MPC_e19800": {"2017": [0.0]},
"_MPC_e20400": {"2017": [0.0]},
"_BEN_housing_value": {"2017": [1.0]},
"_BEN_snap_value": {"2017": [1.0]},
"_BEN_tanf_value": {"2017": [1.0]},
"_BEN_vet_value": {"2017": [1.0]},
"_BEN_wic_value": {"2017": [1.0]},
"_BEN_mcare_value": {"2017": [1.0]},
"_BEN_mcaid_value": {"2017": [1.0]},
"_BEN_other_value": {"2017": [1.0]}
"MPC_e17500": {"2017": 0.0},
"MPC_e18400": {"2017": 0.0},
"MPC_e19800": {"2017": 0.0},
"MPC_e20400": {"2017": 0.0},
"BEN_housing_value": {"2017": 1.0},
"BEN_snap_value": {"2017": 1.0},
"BEN_tanf_value": {"2017": 1.0},
"BEN_vet_value": {"2017": 1.0},
"BEN_wic_value": {"2017": 1.0},
"BEN_mcare_value": {"2017": 1.0},
"BEN_mcaid_value": {"2017": 1.0},
"BEN_other_value": {"2017": 1.0}
},
"growdiff_baseline": {
"_ABOOK": {"2017": [0.0]},
"_ACGNS": {"2017": [0.0]},
"_ACPIM": {"2017": [0.0]},
"_ACPIU": {"2017": [0.0]},
"_ADIVS": {"2017": [0.0]},
"_AINTS": {"2017": [0.0]},
"_AIPD": {"2017": [0.0]},
"_ASCHCI": {"2017": [0.0]},
"_ASCHCL": {"2017": [0.0]},
"_ASCHEI": {"2017": [0.0]},
"_ASCHEL": {"2017": [0.0]},
"_ASCHF": {"2017": [0.0]},
"_ASOCSEC": {"2017": [0.0]},
"_ATXPY": {"2017": [0.0]},
"_AUCOMP": {"2017": [0.0]},
"_AWAGE": {"2017": [0.0]},
"_ABENOTHER": {"2017": [0.0]},
"_ABENMCARE": {"2017": [0.0]},
"_ABENMCAID": {"2017": [0.0]},
"_ABENSSI": {"2017": [0.0]},
"_ABENSNAP": {"2017": [0.0]},
"_ABENWIC": {"2017": [0.0]},
"_ABENHOUSING": {"2017": [0.0]},
"_ABENTANF": {"2017": [0.0]},
"_ABENVET": {"2017": [0.0]}
"ABOOK": {"2017": 0.0},
"ACGNS": {"2017": 0.0},
"ACPIM": {"2017": 0.0},
"ACPIU": {"2017": 0.0},
"ADIVS": {"2017": 0.0},
"AINTS": {"2017": 0.0},
"AIPD": {"2017": 0.0},
"ASCHCI": {"2017": 0.0},
"ASCHCL": {"2017": 0.0},
"ASCHEI": {"2017": 0.0},
"ASCHEL": {"2017": 0.0},
"ASCHF": {"2017": 0.0},
"ASOCSEC": {"2017": 0.0},
"ATXPY": {"2017": 0.0},
"AUCOMP": {"2017": 0.0},
"AWAGE": {"2017": 0.0},
"ABENOTHER": {"2017": 0.0},
"ABENMCARE": {"2017": 0.0},
"ABENMCAID": {"2017": 0.0},
"ABENSSI": {"2017": 0.0},
"ABENSNAP": {"2017": 0.0},
"ABENWIC": {"2017": 0.0},
"ABENHOUSING": {"2017": 0.0},
"ABENTANF": {"2017": 0.0},
"ABENVET": {"2017": 0.0}
},
"growdiff_response": {
"_ABOOK": {"2017": [0.0]},
"_ACGNS": {"2017": [0.0]},
"_ACPIM": {"2017": [0.0]},
"_ACPIU": {"2017": [0.0]},
"_ADIVS": {"2017": [0.0]},
"_AINTS": {"2017": [0.0]},
"_AIPD": {"2017": [0.0]},
"_ASCHCI": {"2017": [0.0]},
"_ASCHCL": {"2017": [0.0]},
"_ASCHEI": {"2017": [0.0]},
"_ASCHEL": {"2017": [0.0]},
"_ASCHF": {"2017": [0.0]},
"_ASOCSEC": {"2017": [0.0]},
"_ATXPY": {"2017": [0.0]},
"_AUCOMP": {"2017": [0.0]},
"_AWAGE": {"2017": [0.0]},
"_ABENOTHER": {"2017": [0.0]},
"_ABENMCARE": {"2017": [0.0]},
"_ABENMCAID": {"2017": [0.0]},
"_ABENSSI": {"2017": [0.0]},
"_ABENSNAP": {"2017": [0.0]},
"_ABENWIC": {"2017": [0.0]},
"_ABENHOUSING": {"2017": [0.0]},
"_ABENTANF": {"2017": [0.0]},
"_ABENVET": {"2017": [0.0]}
"ABOOK": {"2017": 0.0},
"ACGNS": {"2017": 0.0},
"ACPIM": {"2017": 0.0},
"ACPIU": {"2017": 0.0},
"ADIVS": {"2017": 0.0},
"AINTS": {"2017": 0.0},
"AIPD": {"2017": 0.0},
"ASCHCI": {"2017": 0.0},
"ASCHCL": {"2017": 0.0},
"ASCHEI": {"2017": 0.0},
"ASCHEL": {"2017": 0.0},
"ASCHF": {"2017": 0.0},
"ASOCSEC": {"2017": 0.0},
"ATXPY": {"2017": 0.0},
"AUCOMP": {"2017": 0.0},
"AWAGE": {"2017": 0.0},
"ABENOTHER": {"2017": 0.0},
"ABENMCARE": {"2017": 0.0},
"ABENMCAID": {"2017": 0.0},
"ABENSSI": {"2017": 0.0},
"ABENSNAP": {"2017": 0.0},
"ABENWIC": {"2017": 0.0},
"ABENHOUSING": {"2017": 0.0},
"ABENTANF": {"2017": 0.0},
"ABENVET": {"2017": 0.0}
}
}
10 changes: 0 additions & 10 deletions taxcalc/assumptions/simple_parameters_template.json

This file was deleted.

2 changes: 1 addition & 1 deletion taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
These functions are imported into the Calculator class.
Note: the cpi_offset policy parameter is the only policy parameter that
Note: the CPI_offset policy parameter is the only policy parameter that
does not appear here; it is used in the policy.py file to possibly adjust
the price inflation rate used to index policy parameters (as would be done
in a reform that introduces chained-CPI indexing).
Expand Down
Loading

0 comments on commit 4e30417

Please sign in to comment.