Source code for utility_modules.input

#!/usr/bin/env python
import os
import pdb
import pandas as pd
import numpy as np
import shutil
import time
import datetime

[docs]class Input(): # Borg pattern implementation __shared_state = {} def __init__(self, config_dict = None, data_path = None): # implement the borg pattern self.__dict__ = self.__shared_state if config_dict != None and data_path != None: # manifest constants #above one with inflator updated on 3/13/2018 file name policy input #fid = '1tPTYod8RrFQVHTcWwy4I2BedmDL27TJduVqfSNFMQBo' # this one is Policy Input with new inflator sheet but used (xc) dont use this one #now since we do not read policy input from google sheet, get rid of fid self.data_path = os.path.join(data_path, config_dict['policy_input_option']) if not os.path.exists(self.data_path): os.makedirs(self.data_path) policy_keys = [ 'mcaid_elig', # mcaid_elig, fpl 'fpl', # mcaid_elig, fpl 'fed_tax_rates', 'fed_std_deduction', 'state_tax_rates', 'state_std_deduction', 'pnlty_unin_f', # individual_penalty 'pnlty_unin_ind', # individual_penalty 'prem_ratio', # premium_parameters 'admin_loading', # premium_parameters 'prem_equiv', # premium_parameters 'calc_xc_prem', 'prem_sub', # premium_calculate 'biz_tax', # firm_tax 'w_comp', # firm_tax 'employer_penalty', 'firm_nfte_pnlty', 'gruber_age_rating', # excise_tax 'premium_ratios', # excise_tax 'firm_behavior', # excise_tax 'oop_adjustment', 'xc_oop', 'regional_minwage_17reg', # min_wage by region 'minwage_parameters', # min_wage 'inflators', # min_wage 'fed_std_deduction', # fed_tax 'age_rating', 'sub_parameters', 'xc_admin_loading', 'ca_pop_race', 'reg_xc_prem_17reg', 'regional_pop_allages_17reg', 'regional_pop_under65_17reg', 'tax_thres' ] self.policy_dict = {} unicode_dict = {} for f in os.listdir(self.data_path): unicode_dict.setdefault(f[:-4], 0) # use minwage_calsim or regional_minwage depending on desired input sheet self.policy_dict['minwage_calsim'] = ('minwage_calsim' + '.csv', unicode_dict['regional_minwage']) for key, value in unicode_dict.items(): # convert to str because elements are in unicode key = str(key) if key in policy_keys: self.policy_dict[key] = (key + '.csv', value) try: folder_name = config_dict['prefix']+'_'+datetime.datetime.fromtimestamp(time.time()).strftime('%Y_%m_%d_%H_%M_%S') except: folder_name = datetime.datetime.fromtimestamp(time.time()).strftime('%Y_%m_%d_%H_%M_%S') # Initialize path_dict self.path_dict = { 'Current_path' : 'input_tables/', 'Worker_path' : 'input_tables/worker_table.csv', 'Hieu_path' : 'input_tables/hieu_table.csv', 'Firm_path' : 'input_tables/firm_table.csv' , 'Family_path' : 'input_tables/fam_table.csv' , 'Esi_path' : 'input_tables/esi_table.csv', 'C_params_path' : 'input_tables/', 'Choice_Tables_path': 'choice_files/', 'Out_path' : os.path.join('output_tables_' + config_dict['General']['username'], 'default' \ if config_dict['General']['suffix'] is None else config_dict['General']['suffix'], \ folder_name) }