Beispiel #1
0
def run_gams_model():
    try:
        log.info("Running GAMS model .....")
        cur_time=datetime.now()
        working_directory=os.path.dirname(args.gms_file)
        model = GamsModel(args.gams_path, working_directory)
        model.add_job(args.gms_file)
        model.run()
        log.info("Running GAMS model finsihed")
        # if result file is not provided, it looks for it automatically at GAMS WD
        if(args.gdx_file==None):
            log.info("Extract result file name.....")
            files_list=get_files_list(working_directory, '.gdx')
            for file_ in files_list:
                from dateutil import parser
                dt = parser.parse(files_list[file_])
                delta= (dt-cur_time).total_seconds()
                if delta>0:
                    args.gdx_file=working_directory+"\\"+file_
            if(args.gdx_file==None):
                  raise HydraPluginError('Result file is not provided/found.')

    except Exception as e:
        errors = [e.message]
        print "Error is: ", errors
        err = PluginLib.create_xml_response('GAMS_run_model', args.network, [args.scenario], errors = errors)
        print err
        sys.exit(0)
Beispiel #2
0
def export_network():
    try:
        template_id = None
        exporter = GAMSexport(int(args.network),
                              int(args.scenario),
                              template_id,#int(args.template_id),
                              args.output,
                              link_export_flag,
                              url=args.server_url)

        if args.template_id is not None:
            exporter.template_id = int(args.template_id)

        exporter.export_network()

        if args.start_date is not None and args.end_date is not None \
                and args.time_step is not None:
            exporter.write_time_index(start_time=args.start_date,
                                      end_time=args.end_date,
                                      time_step=args.time_step)
        elif args.time_axis is not None:
            exporter.write_time_index(time_axis=args.time_axis)
        else:
            raise HydraPluginError('Time axis not specified.')
        exporter.export_data()
        exporter.write_file()

    except HydraPluginError, e:
          errors = [e.message]
          err = PluginLib.create_xml_response('GAMSexport', args.network, [args.scenario], errors = errors)
          print err
          sys.exit(0)
Beispiel #3
0
def import_results():
     try:
        gdximport = GAMSimport()
        gdximport.load_network(args.network, args.scenario)
        get_result(gdximport)

     except HydraPluginError, e:
          errors = [e.message]
          err = PluginLib.create_xml_response('GAMSimport', args.network, [args.scenario], errors = errors)
          print err
Beispiel #4
0
    parser = commandline_parser()
    args = parser.parse_args()
    steps = 12
    try:
        check_args(args)
        netword_id = convert_to_int(args.network, "Network Id")
        scenario_id = convert_to_int(args.scenario, "scenario Id")
        link_export_flag = "nn"
        if args.link_name is True:
            link_export_flag = "l"
        network = export_data(args)
        vars, objs = run_model(args.output, args.model_file)
        actual_time_steps = read_inputData(args.output)
        import_result(args, vars, objs, actual_time_steps)
        message = "Run successfully"
        print PluginLib.create_xml_response("PyomoAuto", args.network, [args.scenario], message=message)

    except HydraPluginError, e:
        write_progress(steps, steps)
        log.exception(e)
        err = PluginLib.create_xml_response("PyomoAuto", args.network, [args.scenario], errors=[e.message])
        print err
    except Exception as e:
        write_progress(steps, steps)
        errors = []
        if e.message == "":
            if hasattr(e, "strerror"):
                errors = [e.strerror]
        else:
            errors = [e.message]
Beispiel #5
0
        
        net = hobbes_importer.import_network_topology(args.project_id)

        scenario = hobbes_importer.import_data()

        #scenarios = [s.id for s in net.scenarios]
        network_id = net.id
        scenario_id = scenario.id
        message = "Import complete"
    except HydraPluginError as e:
        message="An error has occurred"
        errors = [e.message]
        log.exception(e)
    except Exception, e:
        message="An unknown error has occurred"
        log.exception(e)
        errors = [e]

    xml_response = PluginLib.create_xml_response('Import Hobbes',
                                                 network_id,
                                                 [scenario_id],
                                                 errors,
                                                 hobbes_importer.warnings,
                                                 message,
                                                 hobbes_importer.files)
    print xml_response

if __name__ == '__main__':
    run()

Beispiel #6
0
    gdximport.read_gdx_data()
    gdximport.parse_variables()
    gdximport.assign_attr_data()
    gdximport.save()

if __name__ == '__main__':
    parser = commandline_parser()
    args = parser.parse_args()
    #if switch is not provided, the default is auto is applied
    if(args.switch==None):
        args.switch='A'
    else:
        #chech the switch vrs the 3 defined modes (E, I, and A)
        if(args.switch.upper()!='I' and args.switch.upper()!='E' and args.switch.upper()!='A'):
            errors = ["Unknow swithc: -sh "+args.switch]
            err = PluginLib.create_xml_response('GAMS', args.network, [args.scenario], errors = errors)
            print err
            exit(0)
        else:
            args.switch=args.switch.upper()
    link_export_flag = 'nn'
    if args.link_name is True:
         link_export_flag = 'l'
    # run exporter if the mode is auto or export only
    if(args.switch=='A' or args.switch=='E'):
        exporter=export_network()
        #if the mode is E, it exits
        if(args.switch=='E'):
             message="Run successfully"
             print PluginLib.create_xml_response('GAMS Exporter', args.network, [args.scenario], message=message)
             exit(0)
Beispiel #7
0
    args = parser.parse_args()
    steps = 12
    try:
        check_args(args)
        netword_id = convert_to_int(args.network, "Network Id")
        scenario_id = convert_to_int(args.scenario, "scenario Id")
        link_export_flag = 'nn'
        if args.link_name is True:
            link_export_flag = 'l'
        network = export_data(args)
        vars, objs = run_model(args.output, args.model_file)
        actual_time_steps = read_inputData(args.output)
        import_result(args, vars, objs, actual_time_steps)
        message = "Run successfully"
        print PluginLib.create_xml_response('PyomoAuto',
                                            args.network, [args.scenario],
                                            message=message)

    except HydraPluginError, e:
        write_progress(steps, steps)
        log.exception(e)
        err = PluginLib.create_xml_response('PyomoAuto',
                                            args.network, [args.scenario],
                                            errors=[e.message])
        print err
    except Exception as e:
        write_progress(steps, steps)
        errors = []
        if e.message == '':
            if hasattr(e, 'strerror'):
                errors = [e.strerror]
Beispiel #8
0
        else:
            hobbes_importer.fetch_template(args.template_id)

        net = hobbes_importer.import_network_topology(args.project_id)

        scenario = hobbes_importer.import_data()

        #scenarios = [s.id for s in net.scenarios]
        network_id = net.id
        scenario_id = scenario.id
        message = "Import complete"
    except HydraPluginError as e:
        message = "An error has occurred"
        errors = [e.message]
        log.exception(e)
    except Exception, e:
        message = "An unknown error has occurred"
        log.exception(e)
        errors = [e]

    xml_response = PluginLib.create_xml_response('Import Hobbes', network_id,
                                                 [scenario_id], errors,
                                                 hobbes_importer.warnings,
                                                 message,
                                                 hobbes_importer.files)
    print xml_response


if __name__ == '__main__':
    run()
Beispiel #9
0
if __name__ == '__main__':
    steps=8
    parser = commandline_parser()
    args = parser.parse_args()
    try:
        check_args(args)
        netword_id=convert_to_int(args.network, "Network Id")
        scenario_id=convert_to_int(args.scenario, "scenario Id")
        link_export_flag = 'nn'
        if args.link_name is True:
            link_export_flag = 'l'
        network=export_data(args)
        #write_progress(4, steps)
        message="Run successfully"
        print PluginLib.create_xml_response('PyomoExporter', args.network, [args.scenario], message=message)
    except HydraPluginError, e:
        import traceback
        traceback.print_exc(file=sys.stderr)
        log.exception(e)
        err = PluginLib.create_xml_response('PyomoExporter', args.network, [args.scenario], errors = [e.message])
        write_progress(steps, steps)
        print err
    except Exception as e:
        errors = []
        if e.message == '':
            if hasattr(e, 'strerror'):
                errors = [e.strerror]
        else:
            errors = [e.message]