def ge_test(file_dir, config_name, pickle_name, data_file): cwd = os.getcwd() os.chdir(file_dir) config_file = config_name pickle_file = pickle_name new_pickle_file = 'test_out.pkl' new_log_file = 'test.log' new_diff_file = 'diff.txt' if os.path.isfile(new_pickle_file): os.remove(new_pickle_file) if os.path.isfile(new_log_file): os.remove(new_log_file) if os.path.isfile(new_diff_file): os.remove(new_diff_file) flags = ['-f', config_file, '-l', new_log_file, '-d', 'DEBUG'] with open(data_file) as f: input_data = f.read() all_years_out = rungedemo.rungedemo(flags, input_data) pickle.dump(all_years_out, open(new_pickle_file, "wb")) if os.path.isfile(new_pickle_file): exp_result = pickle.load(open(pickle_file, 'rb')) new_result = pickle.load(open(new_pickle_file, 'rb')) match = (exp_result == new_result) if not match: f = open(file_dir + '/' + 'diff.txt', 'w') pp = pprint.PrettyPrinter(indent=4, stream=f) f.write('Expected results\n') f.write('=======================\n') pp.pprint(exp_result) f.write('This run results\n') f.write('=======================\n') pp.pprint(new_result) f.close() else: match = False os.chdir(cwd) return match
def ge_test(file_dir, config_name, pickle_name, data_file): cwd = os.getcwd() os.chdir(file_dir) config_file = config_name pickle_file = pickle_name new_pickle_file = "test_out.pkl" new_log_file = "test.log" new_diff_file = "diff.txt" if os.path.isfile(new_pickle_file): os.remove(new_pickle_file) if os.path.isfile(new_log_file): os.remove(new_log_file) if os.path.isfile(new_diff_file): os.remove(new_diff_file) flags = ["-f", config_file, "-l", new_log_file, "-d", "DEBUG"] with open(data_file) as f: input_data = f.read() all_years_out = rungedemo.rungedemo(flags, input_data) pickle.dump(all_years_out, open(new_pickle_file, "wb")) if os.path.isfile(new_pickle_file): exp_result = pickle.load(open(pickle_file, "rb")) new_result = pickle.load(open(new_pickle_file, "rb")) match = exp_result == new_result if not match: f = open(file_dir + "/" + "diff.txt", "w") pp = pprint.PrettyPrinter(indent=4, stream=f) f.write("Expected results\n") f.write("=======================\n") pp.pprint(exp_result) f.write("This run results\n") f.write("=======================\n") pp.pprint(new_result) f.close() else: match = False os.chdir(cwd) return match
print "Content-Type: text/json" print import rungedemo from collections import defaultdict import argparse import json flags = ['-f', 'GEconfig.txt', '-l', 'GEConfig.log'] # file_path = 'new_values_to_model.js' # # with open(file_path) as f: # input_data = f.read() import cgi form = cgi.FieldStorage() input_data = form['sysdata'].value # Note that the format of the results are as follows: # 'cost' - per generation type, total for that decade, in $M # 'output' - per generation type, MWh per year # 'reliability' - the percentage of hours where demand was not met # 'co2_tonnes' - in tonnes, total for that decade # 'period_cost' - total of all 'cost' values, for that decade, in $M, # without discounting. # 'discounted_cumulative_cost' - total of all 'period_cost' values including # the current decade, with discounting at the configured discount rate, # assuming all costs incurred at the start of the decade. all_years_out = rungedemo.rungedemo(flags, input_data) print json.dumps(all_years_out)
print "Content-Type: text/json" print import rungedemo from collections import defaultdict import argparse import json; flags = ['-f', 'GEconfig.txt', '-l', 'GEConfig.log'] # file_path = 'new_values_to_model.js' # # with open(file_path) as f: # input_data = f.read() import cgi form = cgi.FieldStorage() input_data = form['sysdata'].value # Note that the format of the results are as follows: # 'cost' - per generation type, total for that decade, in $M # 'output' - per generation type, MWh per year # 'reliability' - the percentage of hours where demand was not met # 'co2_tonnes' - in tonnes, total for that decade # 'period_cost' - total of all 'cost' values, for that decade, in $M, # without discounting. # 'discounted_cumulative_cost' - total of all 'period_cost' values including # the current decade, with discounting at the configured discount rate, # assuming all costs incurred at the start of the decade. all_years_out = rungedemo.rungedemo(flags, input_data) print json.dumps(all_years_out);