Example #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)
def test_transform_real_shopmodel():
    with open('./test/gams/real-shopmodel.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        model = gp.transform()

        print("\nModel\n")
        print(model)

        print("\nSymbols:\n")
        for s in model.symbol():
            print(s)
def test_transform_equation_def():
    with open('./test/gams/equation-basic.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
        model = gp.transform()

        print("\nModel\n")
        print(model)
        print("\nSymbols:\n")
        for s in model.symbol():
            print(s)
def test_transform_model_siteanalysis():
    with open('./test/gams/real-siteanalysis.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        model = gp.transform()

        print("\nModel\n")
        print(model)

        print("\nSymbols:\n")
        for s in model.symbol():
            print(s)

        dm = model.toJSON()

        #print("\nmodel.toJSON\n")
        #print(dm)

        print("\nmodel.toDict Hack\n")
        m = model.toDict()
        scrub_meta(m)
        pprint.pprint(m)
def test_transform_real_shopmodel():
    with  open('./test/gams/inject-datagen.inc','r') as gen_file, \
      open('./test/gams/inject-datademand.inc','r') as demand_file, \
      open('./test/gams/inject-siteanalysis.gms','r') as main_file:

        gp_main = GamsParser(main_file)
        gp_gen = GamsParser(gen_file)
        gp_demand = GamsParser(demand_file)

        model_main = gp_main.transform()
        model_gen = gp_gen.transform()
        model_demand = gp_gen.transform()

        model = model_main + model_gen + model_demand

        print("\nModel\n")
        print(model)

        print("\nSymbols:\n")
        for s in model.symbol():
            print(s)
Example #7
0
def test_real_siteanalysis():
    with open('./test/gams/real-siteanalysis.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
def test_assignment_basic():
    with open('./test/gams/assignment-basic.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #9
0
def test_misc_comments():
    with open('./test/gams/misc-comments.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #10
0
def test_misc_include():
    with open('./test/gams/misc-include.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #11
0
def test_open_file():
    gp = GamsParser('./test/gams/set-ranged.gms')
    parse_tree = gp.parse()
    print(parse_tree.pretty())
def test_equation_indexoperator():
    with open('./test/gams/equation-indexoperator.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
def test_scalar_basic():
    with open('./test/gams/scalar-basic.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #14
0
def test_real_eminit():
    with open('./test/gams/real-eminit.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
def test_equation_elementindex():
    with open('./test/gams/equation-elementindex.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #16
0
def test_set_multi():
    with open('./test/gams/set-multi.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
def test_equation_basic():
    with open('./test/gams/equation-basic.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #18
0
def test_parameter_tuple():
    with open('./test/gams/parameter-tuple.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #19
0
def test_real_shopmodel():
    with open('./test/gams/real-shopmodel.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #20
0
def test_variable_basic():
    with open('./test/gams/variable-basic.gms', 'r') as in_file:
        gp = GamsParser(in_file)
        parse_tree = gp.parse()
        print(parse_tree.pretty())
Example #21
0
    sys.exit(1)

############################
### 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)