示例#1
0
def test_inject_tariff():
	gp = GamsParser('./test/gams/inject-siteanalysis.gms')
	with open('./test/ao/scenario-context.json') as in_file, \
			open('./test/ao/demand.json') as demand_file, \
			open('./test/ao/nrel-sam-gen.json') as gen_file, \
			open('./test/ao/tariff.json') as tariff_file:
		data=json.load(in_file)
		demand=json.load(demand_file)
		gen=json.load(gen_file)
		tariff=json.load(tariff_file)
		print(tariff.keys())
		print("Inject data")
		d_map={
			"nrel-sam-gen": gen,
			"-LXKR3vVaHl1b3lDunJL": demand,
			"-LXKLG1sepBvV6cTX0EN":tariff
		}
		new_model,inject_map=gp.inject(context=data,data=d_map)
		print("Output")
		#print(new_model)
		inject_simple=[{
			"id": item['item_id'],
			"name": item['item_name'],
			"type": item['item']['type'],
			"rn": item['item']['rn']
		} for item in inject_map]
		pprint.pprint(inject_simple)

		with open('tmp/output-siteanalysis.gms','w') as out_file:
			out_file.write(new_model)
def test_inject_list():
    gp = GamsParser('./test/gams/inject-basic.gms')
    with open('./test/ao/scenario-context.json') as in_file:
        data = json.load(in_file)
        #print(data)
        print("Inject data")
        new_model, inject_map = gp.inject(context=data)
        print("Output")
        print(new_model)
示例#3
0
### Inject project data ####
############################

model_dir = '{sf}/model'.format(sf=task_handle.scenario_folder)
output_dir = '{sf}/output'.format(sf=task_handle.scenario_folder)
try:
    os.makedirs(model_dir)
    os.makedirs('{dir}/time'.format(dir=model_dir))
    os.makedirs(output_dir)
except FileExistsError:
    pass

gp = GamsParser('/var/task/template/siteanalysis.gms')

d_map = {"nrel-sam-gen": solar_data, f_tou_id: tou_data, f_load_id: load_data}
new_model, inject_map = gp.inject(context=task_handle.scenario_context,
                                  data=d_map)

inject_map_file = '{dir}/inject_map.json'.format(dir=model_dir)
with open(inject_map_file, 'w') as out_file:
    json.dump(inject_map, out_file, indent=2)

model_file = '{dir}/siteanalysis.gms'.format(dir=model_dir)
with open(model_file, 'w') as out_file:
    out_file.write(new_model)

gp_gen = GamsParser('/var/task/template/gen.gms')
gen_model, im = gp_gen.inject(context=task_handle.scenario_context, data=d_map)
gen_file = '{dir}/gen.gms'.format(dir=model_dir)
with open(gen_file, 'w') as out_file:
    out_file.write(gen_model)