Пример #1
0
def get_gad_address():
    """Helper to get GRIDAPPS-D address.

    The address is different depending on whether we're operating
    inside or outside the platform.

    TODO: logging
    """
    # Determine whether or not we're running in the platform.
    platform = get_platform_env_var()

    if platform == '1':
        # We're in the platform. Use the API helper.
        address = gad_utils.get_gridappsd_address()
    elif platform == '0':
        # We're not in the platform. Use the local IP address and get
        # the port from the environment.
        try:
            address = (os.environ['host_ip'], os.environ['GRIDAPPSD_PORT'])
        except KeyError:
            # Environment variables not properly set.
            m = ("If running outside the platform ('platform' input is '0'), "
                 + "the environment variables 'host_ip' and 'GRIDAPPSD_PORT' "
                 + "must be set.")
            raise KeyError(m)
    else:
        m = "The 'platform' input must be either '0' or '1.'"
        if isinstance(platform, str):
            raise ValueError(m)
        else:
            raise TypeError(m)

    LOG.debug('GridAPPS-D address obtained.')
    return address
Пример #2
0
def _main():
    _log.debug("Starting application")
    print(
        "Application starting!!!-------------------------------------------------------"
    )
    global message_period
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument(
        "--message_period",
        help="How often the sample app will send open/close capacitor message.",
        default=DEFAULT_MESSAGE_PERIOD)
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    _log.debug("Model mrid is: {}".format(model_mrid))
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())
    topic = "goss.gridappsd.process.request.data.powergridmodel"

    # Run several query to extract the model information
    ACline, obj_msr_loadsw = get_meas_mrid(gapps, model_mrid, topic)

    # Subscribe to simulation output and interface to platform
    toggler = LearnPlatform(opts.simulation_id, gapps, ACline, obj_msr_loadsw)
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #3
0
def _main():
    parser = argparse.ArgumentParser()
    parser.add_argument("simulation_id",
                        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request",
                        help="Simulation Request")
    # These are now set through the docker container interface via env variables or defaulted to
    # proper values.
    #
    # parser.add_argument("-u", "--user", default="system",
    #                     help="The username to authenticate with the message bus.")
    # parser.add_argument("-p", "--password", default="manager",
    #                     help="The password to authenticate with the message bus.")
    # parser.add_argument("-a", "--address", default="127.0.0.1",
    #                     help="tcp address of the mesage bus.")
    # parser.add_argument("--port", default=61613, type=int,
    #                     help="the stomp port on the message bus.")
    #
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    #TODO: read this from simulation request as below 
    # message_interval = sim_request["service_config"]["voltage-violation"]["message_interval"]
    message_interval = 5
    sim_request = json.loads(opts.request.replace("\'",""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    gapps = GridAPPSD(opts.simulation_id, address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())
    nominal_voltage_dict = get_nominal_voltage(gapps, model_mrid)
    subscriber = SimulationSubscriber(opts.simulation_id, gapps, nominal_voltage_dict, message_interval)
    gapps.subscribe(listening_to_topic, subscriber)
    while True:
        time.sleep(0.1)
Пример #4
0
def _main():
    _log.debug("Starting application")
    print(
        "Application starting-------------------------------------------------------"
    )
    global message_period
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument(
        "--message_period",
        help="How often the sample app will send open/close capacitor message.",
        default=DEFAULT_MESSAGE_PERIOD)
    # These are now set through the docker container interface via env variables or defaulted to
    # proper values.
    #
    # parser.add_argument("-u", "--user", default="system",
    #                     help="The username to authenticate with the message bus.")
    # parser.add_argument("-p", "--password", default="manager",
    #                     help="The password to authenticate with the message bus.")
    # parser.add_argument("-a", "--address", default="127.0.0.1",
    #                     help="tcp address of the mesage bus.")
    # parser.add_argument("--port", default=61613, type=int,
    #                     help="the stomp port on the message bus.")
    #
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    print(listening_to_topic)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    print("\n \n The model running is IEEE 123 node with MRID:")
    print(model_mrid)

    _log.debug("Model mrid is: {}".format(model_mrid))
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())

    # Get measurement MRIDS for primary nodes in the feeder
    topic = "goss.gridappsd.process.request.data.powergridmodel"
    message = {
        "modelId": model_mrid,
        "requestType": "QUERY_OBJECT_MEASUREMENTS",
        "resultFormat": "JSON",
        "objectType": "ACLineSegment"
    }
    obj_msr_loads = gapps.get_response(topic, message, timeout=90)
    # print(obj_msr_loads)
    with open('measid.json', 'w') as json_file:
        json.dump(obj_msr_loads, json_file)

    toggler = SwitchingActions(opts.simulation_id, gapps, obj_msr_loads)
    print("Now subscribing")
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #5
0
def _main():
    _log.debug("Starting application")
    print(
        "Application starting!!!-------------------------------------------------------"
    )
    global message_period

    # arguments to be passed
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument(
        "--message_period",
        help="How often the sample app will send open/close capacitor message.",
        default=DEFAULT_MESSAGE_PERIOD)
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    _log.debug("Model mrid is: {}".format(model_mrid))

    # Interaction with the web-based GridAPPSD interface
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())

    # the three lines (uncommented) below are from Shiva
    '''
    The Powergrid Model Data Manager API allows you to query the powergrid model data store.
    
    Query request should be sent on following queue: 
    goss.gridappsd.process.request.data.powergridmodel
    
    i.e. if I want any powergrid component data then the query above has to be addressed
    '''
    topic = "goss.gridappsd.process.request.data.powergridmodel"

    # returns the MRID for AC lines and switch
    ACline, obj_msr_loadsw, obj_msr_reg, switches, regulators = get_meas_mrid(
        gapps, model_mrid, topic)

    # print("\n ************ ACLine ********* \n")
    # print(ACline)

    # print("\n ************ obj_msr_loadsw ********* \n")
    # print(obj_msr_loadsw)
    # print(sh)

    # toggling the switch ON and OFF
    toggler = NodalVoltage(opts.simulation_id, gapps, ACline, obj_msr_loadsw,
                           obj_msr_reg, switches, regulators)

    # gapps.subscribe calls the on_message function
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #6
0
def _main():
    from gridappsd import utils
    _log.info("Starting application")
    _log.info(str(sys.argv))
    _log.info("Args ")
    for arg in sys.argv[1:]:
        _log.info(type(arg))
        _log.info(arg)

    # _log.info("Run local only -JEFF")
    # exit(0)
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument("opt", help="opt")
    opts = parser.parse_args()
    _log.info(opts)
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    print(opts.request)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request['power_system_config']['Line_name']
    start_time = sim_request['simulation_config']['start_time']
    app_config = sim_request["application_config"]["applications"]
    print(app_config)

    # app_config = [json.loads(app['config_string']) for app in app_config if app['name'] == 'solar_forecasting_app'][0]
    app = [
        app for app in app_config if app['name'] == 'solar_forecasting_app'
    ][0]
    print(app)
    if app['config_string']:
        # app_config = json.loads(app['config_string'])
        app_config = json.loads(app['config_string'].replace(u'\u0027', '"'))
    else:
        app_config = {'run_freq': 60, 'run_on_host': False}

    ## Run the docker container. WOOT!
    if 'run_on_host' in app_config and app_config['run_on_host']:
        exit(0)

    _log.info("Model mrid is: {}".format(model_mrid))
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())

    print(listening_to_topic)
    # gapps = GridAPPSD(opts.simulation_id)
    solar_forecast = Solar_Forecast(opts.simulation_id, gapps, model_mrid,
                                    start_time, app_config)
    gapps.subscribe(listening_to_topic, solar_forecast)
    # gapps.subscribe(ghi_weather_topic, solar_forecast)

    # ls_output = subprocess.Popen(["python solar_forecasting/util/post_goss_ghi.py","1357048800","720" , "10"], stdout=subprocess.PIPE)

    while True:
        time.sleep(0.1)
def get_opts():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument(
        "request",
        help=
        "GRIDAPPSD based request that is sent from the client to start a simulation."
    )
    parser.add_argument(
        "log_level", help="The log level for the simulation service overall")

    # parser.add_argument("--nominal", type=float, default=100.0, nargs='+',
    #                     help="Specify the nominal range of sensor measurements.")
    # parser.add_argument("--perunit-confidence", type=float, default=0.01, nargs='+',
    #                     help="Specify the 95% confidence interval, in +/- perunit of nominal range.")
    # parser.add_argument("--perunit-dropping", type=float, default=0.01, nargs='+',
    #                     help="Fraction of measurements that are not republished.")
    # parser.add_argument("--interval", type=float, default=30.0,
    #                     help="Interval in seconds for min, max, average aggregation.")

    parser.add_argument(
        "-u",
        "--username",
        default=utils.get_gridappsd_user(),
        help="The username to authenticate with the message bus.")
    parser.add_argument(
        "-p",
        "--password",
        default=utils.get_gridappsd_pass(),
        help="The password to authenticate with the message bus.")
    parser.add_argument(
        "-a",
        "--address",
        default=utils.get_gridappsd_address(),
        help="The tcp://addr:port that gridappsd is located on.")
    opts = parser.parse_args()
    opts.log_level = 'DEBUG'

    if opts.log_level == 'DEBUG':
        opts.log_level = logging.DEBUG
    elif opts.log_level == 'INFO':
        opts.log_level = logging.INFO
    elif opts.log_level == 'ERROR':
        opts.log_level = logging.ERROR
    elif ops.log_level == 'WARNING' or opts.log_level == 'WARN':
        opts.log_level = logging.WARNING
    elif opts.log_level == 'CRITICAL':
        opts.log_level = logging.CRITICAL
    else:
        opts.log_level = 'INFO'

    assert opts.request, "request must be passed."

    opts.request = json.loads(opts.request)

    return opts
Пример #8
0
def _main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    opts = parser.parse_args()
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())
    x = input("Press Enter to continue...")
    message = {'command': 'StartSimulation'}
    print(fncs_input_topic(opts.simulation_id))
    print(json.dumps(message))
    gapps.send(fncs_input_topic(opts.simulation_id), json.dumps(message))
    while True:
        sleep(0.1)
Пример #9
0
def _main():
    _log.debug("Starting application"
               )  # display of log messages while the simulation is running
    # th elogs are displayed on the web based simulation (you can check this while running the simulation)
    print(
        "Application starting!!!-------------------------------------------------------"
    )
    global message_period
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument(
        "--message_period",
        help="How often the sample app will send open/close capacitor message.",
        default=DEFAULT_MESSAGE_PERIOD)
    # These are now set through the docker container interface via env variables or defaulted to
    # proper values.
    #
    # parser.add_argument("-u", "--user", default="system",
    #                     help="The username to authenticate with the message bus.")
    # parser.add_argument("-p", "--password", default="manager",
    #                     help="The password to authenticate with the message bus.")
    # parser.add_argument("-a", "--address", default="127.0.0.1",
    #                     help="tcp address of the mesage bus.")
    # parser.add_argument("--port", default=61613, type=int,
    #                     help="the stomp port on the message bus.")
    #
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    _log.debug("Model mrid is: {}".format(model_mrid))  # object MRID
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())

    capacitors = get_capacitor_mrids(gapps, model_mrid)
    toggler = CapacitorToggler(opts.simulation_id, gapps, capacitors)
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #10
0
                #     m_names = y.get("modelNames", [])
                if len(dict1) != len(dict2):
                    return False



                return True
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('simulation_id', help="Simulation id")
    opts = parser.parse_args()
    simulation_id = opts.simulation_id
    sim_result_file = '/home/singha42/repos/gridappsd-testing/simulation_baseline_files/9500-simulation.json'


    gapps = GridAPPSD(opts.simulation_id, address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())

    # For subscribing to the simulation output topic uncomment the below line
    #gapps.subscribe(simulation_output_topic(opts.simulation_id), Subscribe.on_message)


    #For testing PowergridAPI uncomment the following lines
    # object = '_0f6f3735-b297-46aa-8861-547d3cd0dee9'
    # with open("/tmp/output/power.json", 'w') as f:
    #     f.write(gapps.query_model_names(model_id=None))
    # r2 = gapps.query_object(object, model_id=None)
    # r3 = gapps.query_object_types(model_id=None)
    # # file.write(f'\n{json.dumps(r1, indent=4, sort_keys=True)},')
    # # file.write(f'\n{json.dumps(r2, indent=4, sort_keys=True)},')
    # #file.write(f'\n{json.dumps(r3, indent=4, sort_keys=True)}')
Пример #11
0

logging.basicConfig(stream=sys.stdout, level=logging.INFO,
                    format="%(asctime)s - %(name)s;%(levelname)s|%(message)s",
                    datefmt="%Y-%m-%d %H:%M:%S")
logging.getLogger('stomp.py').setLevel(logging.ERROR)
_log = logging.getLogger(__name__)

problems = utils.validate_gridappsd_uri()

if problems:
    for p in problems:
        _log.error(p)
    sys.exit(1)

gridapspd_address = utils.get_gridappsd_address()
gridapspd_user = utils.get_gridappsd_user()
gridappsd_pass = utils.get_gridappsd_pass()

if not os.path.isfile("/appconfig"):
    _log.error("Invalid /appconfig reference...map the /appconfig to your container")
    sys.exit(1)

config = json.loads(open("/appconfig").read())
appreg = None
gap = None
while True:

    try:
        if gap is None:
            gap = GridAPPSD(username=gridapspd_user, password=gridappsd_pass,
import json
import pandas as pd
from collections import defaultdict
from tabulate import tabulate
import query_model_adms as query_model
sys.path.append('/usr/src/gridappsd-python')
from gridappsd import GridAPPSD

__GRIDAPPSD_URI__ = os.environ.get("GRIDAPPSD_URI", "localhost:61613")
print(__GRIDAPPSD_URI__)
if __GRIDAPPSD_URI__ == 'localhost:61613':
    gridappsd_obj = GridAPPSD(1234)
else:
    from gridappsd import utils
    # gridappsd_obj = GridAPPSD(simulation_id=1234, address=__GRIDAPPSD_URI__)
    print(utils.get_gridappsd_address())
    gridappsd_obj = GridAPPSD(1069573052,
                              address=utils.get_gridappsd_address(),
                              username=utils.get_gridappsd_user(),
                              password=utils.get_gridappsd_pass())
goss_sim = "goss.gridappsd.process.request.simulation"
timeseries = 'goss.gridappsd.process.request.data.timeseries'


def get_meas_dict(historical_results, convert2rect=True):
    meas_dict = defaultdict(dict)
    pos_dict = defaultdict(dict)
    diff_dict = defaultdict(dict)
    if 'data' in historical_results:
        for row in historical_results['data']['measurements'][0]['points']:
            temp = {
Пример #13
0
def main():
    # Switch for app being managed by platform vs running outside of it.
    IN_PLATFORM = False

    # Read configuration file.
    config = read_config('config.json')

    # Setup log.
    log = setup_log(config['LOG'])
    log.info('Log configured.')

    if IN_PLATFORM:
        # In docker-compose, use the service name.
        MYSQL_HOST = 'mysql-pyvvo'

        # When running inside the platform, use standard MySQL port.
        MYSQL_PORT = 3306

        # Get the gridappsd_address.
        gridappsd_address = utils.get_gridappsd_address()

        # Initialize argument parser.
        parser = argparse.ArgumentParser()

        # Get simulation ID.
        parser.add_argument("sim_id",
                            help="Simulation ID to send/receive "
                            "data/commands")

        # Get the simulation request so we can extract the model ID.
        parser.add_argument("sim_request",
                            help="Request sent to start "
                            "simulation.")

        # Extract arguments.
        args = parser.parse_args()
        log.debug('Arguments parsed.')

        # Get the topic for listening to simulation output.
        sim_out_topic = topics.fncs_output_topic(args.sim_id)

        # Get the topic for sending commands to simulation.
        sim_in_topic = topics.fncs_input_topic(args.sim_id)

        # Get the simulation request into a dictionary.
        sim_request = json.loads(args.sim_request.replace("\'", ""))

        # Extract the model ID. It's silly that they've labeled the model
        # "Line_name"
        model_id = sim_request["power_system_config"]["Line_name"]
        log.debug('Model MRID: {}'.format(model_id))

        # Extract the sim_id.
        sim_id = args.sim_id

    else:
        # For development, use this machine's internal IP.
        '''
        # The code below only works when run OUTSIDE of a container.
        import socket
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        INTERNAL_IP = s.getsockname()[0]
        s.close()
        '''
        INTERNAL_IP = '192.168.0.26'

        MYSQL_HOST = INTERNAL_IP

        # MYSQL_PORT is different when running outside the platform.
        MYSQL_PORT = 3307

        # Define where we can connect to the platform externally.
        gridappsd_address = (INTERNAL_IP, 61613)

        # For now, not listening to a simulation topic.
        # NOTE: the sim_id below is for an offline simulation, so I
        # can grab timeseries information.
        sim_id = "293975150"
        sim_out_topic = None
        sim_in_topic = None

        # Initialize GridAPPSD object so we can pull the model ID.
        gridappsd_object = GridAPPSD(address=gridappsd_address)

        # Get the id for the 8500 node feeder.
        model_name = 'ieee8500'
        model_id = get_model_id(gridappsd_object=gridappsd_object,
                                model_name=model_name,
                                log=log)
        log.info('Retrieved model ID for {}.'.format(model_name))

    # Override the MySQL host and port.
    config['GLD-DB']['host'] = MYSQL_HOST
    config['GLD-DB']['port'] = MYSQL_PORT

    run(log=log,
        config=config,
        sim_id=sim_id,
        model_id=model_id,
        sim_in_topic=sim_in_topic,
        gridappsd_address=gridappsd_address,
        sim_out_topic=None)

    # Initialize GridAPPSD object.
    gridappsd_object = GridAPPSD(simulation_id=sim_id,
                                 address=gridappsd_address,
                                 username=utils.get_gridappsd_user(),
                                 password=utils.get_gridappsd_pass())

    # Grab measurement information
    load_meas = \
        query_and_parse(
            gridappsd_object,
            query_string=sparql_queries.LOAD_MEASUREMENTS_QUERY.format(fdrid=model_id),
            parse_function=sparql_queries.parse_load_measurements_query,
            log_string='Load Measurement', log=log
        )

    log.info('Terminating pyvvo...')
    sys.exit(0)
Пример #14
0
from gridappsd import GridAPPSD
import argparse
import solar_forecasting.app.query_weather as query_weather

__GRIDAPPSD_URI__ = os.environ.get("GRIDAPPSD_URI", "localhost:61613")
print(__GRIDAPPSD_URI__)
if __GRIDAPPSD_URI__ == 'localhost:61613':
    # gridappsd_obj = GridAPPSD(1234)
    gridappsd_obj = GridAPPSD(1234)
    # goss = GOSS()
else:
    from gridappsd import utils
    # goss = GOSS(stomp_address=utils.get_gridappsd_address(),
    #                   username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())
    gridappsd_obj = GridAPPSD(1069573052,
                              address=utils.get_gridappsd_address(),
                              username=utils.get_gridappsd_user(),
                              password=utils.get_gridappsd_pass())

import sys
sys.path.append('/usr/src/gridappsd-solar-forecasting')
# goss.connect()
ghi_weather_topic = '/topic/goss.gridappsd.weather.ghi'
GHI_type = 'AtmosphericAnalogKind.irradanceGlobalHorizontal'


def post_from_db(start_time=1357140600,
                 duration=3600 * 8,
                 interval=60,
                 time_sleep=.1):
    # start_time+=(7 * 60 * 60)
Пример #15
0
def _main():
    parser = argparse.ArgumentParser()
    parser.add_argument("simulation_id",
                        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request",
                        help="Simulation Request")
    # These are now set through the docker container interface via env variables or defaulted to
    # proper values.
    #
    # parser.add_argument("-u", "--user", default="system",
    #                     help="The username to authenticate with the message bus.")
    # parser.add_argument("-p", "--password", default="manager",
    #                     help="The password to authenticate with the message bus.")
    # parser.add_argument("-a", "--address", default="127.0.0.1",
    #                     help="tcp address of the mesage bus.")
    # parser.add_argument("--port", default=61613, type=int,
    #                     help="the stomp port on the message bus.")
    #
    opts = parser.parse_args()
    sim_output_topic = simulation_output_topic(opts.simulation_id)
    sim_input_topic = simulation_input_topic(opts.simulation_id)
    sim_request = json.loads(opts.request.replace("\'",""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    gapps = GridAPPSD(opts.simulation_id, address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())
    capacitors_dict = {}
    switches_dict = {}
    capacitors_meas_dict = {}
    switches_meas_dict = {}

    request = {
        "modelId": model_mrid,
        "requestType": "QUERY_OBJECT_DICT",
        "resultFormat": "JSON",
        "objectType": "LinearShuntCompensator"
        }

    response = gapps.get_response("goss.gridappsd.process.request.data.powergridmodel",request)
    for capacitor in response["data"]:
        capacitors_dict[capacitor["id"]] = capacitor

    request = {
        "modelId": model_mrid,
        "requestType": "QUERY_OBJECT_DICT",
        "resultFormat": "JSON",
        "objectType": "LoadBreakSwitch"
        }

    response = gapps.get_response("goss.gridappsd.process.request.data.powergridmodel",request)
    for switch in response["data"]:
        switches_dict[switch["id"]] = switch

    #print(capacitors_dict)
    #print(switches_dict)
    
    request = {"modelId": model_mrid,
               "requestType": "QUERY_OBJECT_MEASUREMENTS",
               "resultFormat": "JSON",
               "objectType": "LinearShuntCompensator"
               }
    
    response = gapps.get_response("goss.gridappsd.process.request.data.powergridmodel",request)
    for measurement in response["data"]:
        capacitors_meas_dict[measurement["measid"]] = measurement
        
    request = {"modelId": model_mrid,
               "requestType": "QUERY_OBJECT_MEASUREMENTS",
               "resultFormat": "JSON",
               "objectType": "LoadBreakSwitch"
               }
    
    response = gapps.get_response("goss.gridappsd.process.request.data.powergridmodel",request)
    for measurement in response["data"]:
        switches_meas_dict[measurement["measid"]] = measurement

    #print(capacitors_meas_dict)
    #print(switches_meas_dict)

    #capacitors_dict = get_capacitor_measurements(gapps, model_mrid)
    #switches_dict = get_switch_measurements(gapps, model_mrid)
    subscriber = SimulationSubscriber(opts.simulation_id, gapps, capacitors_dict, switches_dict, capacitors_meas_dict, switches_meas_dict)
    gapps.subscribe(sim_input_topic, subscriber)
    gapps.subscribe(sim_output_topic, subscriber)
    while True:
        time.sleep(0.1)
Пример #16
0
def _main():
    _log.debug("Starting application")
    print("Application starting-------------------------------------------------------")
    global message_period
    parser = argparse.ArgumentParser()
    parser.add_argument("simulation_id",
                        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request",
                        help="Simulation Request")
    parser.add_argument("--message_period",
                        help="How often the sample app will send open/close capacitor message.",
                        default=DEFAULT_MESSAGE_PERIOD)
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'",""))
    model_mrid = sim_request['power_system_config']['Line_name']
    print("\n \n The model running is IEEE 9500-node with MRID:", model_mrid)
    
    _log.debug("Model mrid is: {}".format(model_mrid))
    gapps = GridAPPSD(opts.simulation_id, address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())

    # Get measurement MRIDS for Loadbreakswitches in the feeder
    print('Get Measurement MRIDS for Loadbreakswitches.....')
    topic = "goss.gridappsd.process.request.data.powergridmodel"
    message = {
        "modelId": model_mrid,
        "requestType": "QUERY_OBJECT_MEASUREMENTS",
        "resultFormat": "JSON",
        "objectType": "LoadBreakSwitch"}     
    obj_msr_loadsw = gapps.get_response(topic, message, timeout=180)
    with open('measid_LoadbreakSwitch.json', 'w') as json_file:
        json.dump(obj_msr_loadsw, json_file)    

    # Get measurement MRIDS for kW consumptions at each node
    print('Get Measurement MRIDS for EnergyConsumers.....')
    message = {
        "modelId": model_mrid,
        "requestType": "QUERY_OBJECT_MEASUREMENTS",
        "resultFormat": "JSON",
        "objectType": "EnergyConsumer"}     
    obj_msr_demand = gapps.get_response(topic, message, timeout=180)

    # Get Eq. MRIDs of Loadbreakswitches
    print('Get Switches Information.....')    
    switches = get_switches_mrids(gapps, model_mrid)

    # Load demand and lineparameters
    with open('Demand9500.json', 'r') as read_file:
        demand = json.load(read_file)
    with open('LineData.json', 'r') as read_file:
        line = json.load(read_file)

    print("Initialize.....")
    toggler = SwitchingActions(opts.simulation_id, gapps, switches, \
    obj_msr_loadsw, obj_msr_demand, demand, line)
    print("Now subscribing....")
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #17
0
import os
import sys
import pandas as pd
sys.path.append('/usr/src/gridappsd-python')
from gridappsd import GridAPPSD


__GRIDAPPSD_URI__ = os.environ.get("GRIDAPPSD_URI", "localhost:61613")
print(__GRIDAPPSD_URI__)
if __GRIDAPPSD_URI__ == 'localhost:61613':
    gridappsd_obj = GridAPPSD(1234)
else:
    from gridappsd import utils
    # gridappsd_obj = GridAPPSD(simulation_id=1234, address=__GRIDAPPSD_URI__)
    print(utils.get_gridappsd_address())
    gridappsd_obj = GridAPPSD(1069573052, address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())
goss_sim = "goss.gridappsd.process.request.simulation"
weather_channel = 'goss.gridappsd.process.request.data.timeseries'

def query_weather(start_time, end_time):
    query = {"queryMeasurement":"weather",
            "queryFilter":{"startTime":"1357048800000000",
                            "endTime":"1357058860000000"},
                            "responseFormat":"JSON"}
    query['queryFilter']['startTime'] = str(start_time)
    query['queryFilter']['endTime'] = str(end_time)

    weather_results = gridappsd_obj.get_response(weather_channel, query, timeout=120)
Пример #18
0
def _main():
    _log.debug("Starting application")
    print(
        "Application starting-------------------------------------------------------"
    )
    global message_period
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "simulation_id",
        help="Simulation id to use for responses on the message bus.")
    parser.add_argument("request", help="Simulation Request")
    parser.add_argument(
        "--message_period",
        help="How often the sample app will send open/close capacitor message.",
        default=DEFAULT_MESSAGE_PERIOD)

    #
    opts = parser.parse_args()
    listening_to_topic = simulation_output_topic(opts.simulation_id)
    print(listening_to_topic)
    message_period = int(opts.message_period)
    sim_request = json.loads(opts.request.replace("\'", ""))
    model_mrid = sim_request["power_system_config"]["Line_name"]
    print("\n \n The model running is 9500 node with MRID:")
    # print(model_mrid)

    _log.debug("Model mrid is: {}".format(model_mrid))
    gapps = GridAPPSD(opts.simulation_id,
                      address=utils.get_gridappsd_address(),
                      username=utils.get_gridappsd_user(),
                      password=utils.get_gridappsd_pass())

    # # Get measurement MRIDS for regulators in the feeder
    topic = "goss.gridappsd.process.request.data.powergridmodel"

    # Run queries to get model information
    print('Get Model Information..... \n')
    query = MODEL_EQ(gapps, model_mrid, topic)
    obj_msr_loadsw, obj_msr_demand, obj_msr_reg, obj_msr_cap, obj_msr_inv, obj_msr_node = query.meas_mrids(
    )
    # print('Get Object MRIDS.... \n')
    switches = query.get_switches_mrids()
    regulator = query.get_regulators_mrids()
    # print('regultor is printed')
    capacitor = query.get_capacitors_mrids()
    # print('capacitor is printed')
    LoadData, xfmr = query.distLoad()

    obj_msr_inv = obj_msr_inv['data']
    # print(obj_msr_inv)
    obj_msr_inv = [
        d for d in obj_msr_inv if d['type'] != 'PNV' and 'pv' in d['eqname']
    ]
    # print(obj_msr_inv[0])
    obj_inv = query.Inverters()
    # print(obj_inv[0])

    for inv in obj_msr_inv:
        for sinv in obj_inv:
            if sinv['mrid'] == inv['eqid']:
                inv['Srated'] = sinv['ratedS']

    sP = 0.
    sQ = 0.
    for l in LoadData:
        sP += float(l['kW'])
        sQ += float(l['kVaR'])

        # Load Line parameters
    with open('LineData.json', 'r') as read_file:
        line = json.load(read_file)

    print("Initialize..... \n")

    toggler = SwitchingActions(opts.simulation_id, gapps, regulator, capacitor,
                               LoadData, line, xfmr, obj_msr_demand,
                               obj_msr_cap, obj_msr_reg, obj_msr_loadsw,
                               switches, obj_msr_inv, obj_msr_node)
    print("Now subscribing")
    gapps.subscribe(listening_to_topic, toggler)
    while True:
        time.sleep(0.1)
Пример #19
0
def _startTest(username,password,gossServer='localhost',stompPort='61613', simulationID=1234, rulePort=5000, topic="input"):

    req_template = {"power_system_config": {"SubGeographicalRegion_name": "_1CD7D2EE-3C91-3248-5662-A43EFEFAC224",
                                            "GeographicalRegion_name": "_24809814-4EC6-29D2-B509-7F8BFB646437",
                                            "Line_name": "_C1C3E687-6FFD-C753-582B-632A27E28507"},
                    "simulation_config": {"power_flow_solver_method": "NR",
                                          "duration": 120,
                                          "simulation_name": "ieee123",
                                          "simulator": "GridLAB-D",
                                          "start_time": 1248156000,
                                          "run_realtime": True,
                                          "timestep_frequency": "1000",
                                          "timestep_increment": "1000",
                                          "model_creation_config": {"load_scaling_factor": 1.0, "triplex": "y",
                                                                    "encoding": "u", "system_frequency": 60,
                                                                    "voltage_multiplier": 1.0,
                                                                    "power_unit_conversion": 1.0, "unique_names": "y",
                                                                    "schedule_name": "ieeezipload", "z_fraction": "0",
                                                                    "i_fraction": "1", "p_fraction": "0",
                                                                    "randomize_zipload_fractions": False,
                                                                    "use_houses": False},
                                          "simulation_broker_port": 52798, "simulation_broker_location": "127.0.0.1"},
                    "application_config": {"applications": [{"name": "der_dispatch_app", "config_string": "{}"}]},
                    "simulation_request_type": "NEW", "test_config": {"events": []}}
 #138236b0
    xxx =  {"power_system_config":
                {"GeographicalRegion_name":"_73C512BD-7249-4F50-50DA-D93849B89C43",
                 "SubGeographicalRegion_name":"_A1170111-942A-6ABD-D325-C64886DC4D7D",
                 "Line_name":"_AAE94E4A-2465-6F5E-37B1-3E72183A4E44"},
                "application_config":{"applications":[]},
            "simulation_config":{
                "start_time":"1572040521",
                "duration":"120",
                "simulator":"GridLAB-D",
                "timestep_frequency":"1000",
                "timestep_increment":"1000",
                "run_realtime":True,
                "simulation_name":"test9500new",
                "power_flow_solver_method":"NR",
                "model_creation_config":{"load_scaling_factor":"1",
                                         "schedule_name":"ieeezipload",
                                         "z_fraction":"0",
                                         "i_fraction":"1",
                                         "p_fraction":"0",
                                         "randomize_zipload_fractions":False,
                                         "use_houses":False}
            },
            "test_config":{"events":[],"appId":""},"service_configs":[]}

    sw5_event = {
            "message": {
                "forward_differences": [
                    {
                        "object": "_60208A8D-E4EA-DA37-C758-428756C84F0D",
                        "attribute": "Switch.open",
                        "value": 1
                    }
                ],
                "reverse_differences": [
                    {
                        "object": "_60208A8D-E4EA-DA37-C758-428756C84F0D",
                        "attribute": "Switch.open",
                        "value": 0
                    }
                ]
            },
            "event_type": "ScheduledCommandEvent",
            "occuredDateTime": 1374510750,
            "stopDateTime": 1374510960
        }

    sw3_event = {
            "message": {
                "forward_differences": [
                    {
                        "object": "_4AA2369A-BF4B-F677-1229-CF5FB9A3A07E",
                        "attribute": "Switch.open",
                        "value": 1
                    }
                ],
                "reverse_differences": [
                    {
                        "object": "_4AA2369A-BF4B-F677-1229-CF5FB9A3A07E",
                        "attribute": "Switch.open",
                        "value": 0
                    }
                ]
            },
            "event_type": "ScheduledCommandEvent",
            "occuredDateTime": 1374258660 + (4*60),
            "stopDateTime": 1374258660 + (8*60)
        }
    event_l114 =  {"PhaseConnectedFaultKind": "lineToLineToGround",
                "FaultImpedance": {
                    "xGround": 0.36,
                    "rGround": 0.36,
                    "xLineToLine": 0.36,
                    "rLineToLine": 0.36
                },
                "ObjectMRID": ["_81CF3E64-ABA9-EF74-EE81-B86439ED61D5"], #  _ACA88F2A-96E3-B942-B09B-274CDD213CA6 PV no switches
                "phases": "ABC",
                "event_type": "Fault",
                "occuredDateTime": 1374258600 + (4*60),
                "stopDateTime":  1374258600 + (8*60)
    }
    event_1_v2019_10_0 = {
        "message": {
            "forward_differences": [
                {
                    "object": "_1B6A5DFD-9ADA-404A-83DF-C9AC89D9323C", # l9191_48332_sw
                    "attribute": "Switch.open",
                    "value": 1
                }
            ],
            "reverse_differences": [
                {
                    "object": "_1B6A5DFD-9ADA-404A-83DF-C9AC89D9323C",
                    "attribute": "Switch.open",
                    "value": 0
                }
            ]
        },
        "event_type": "ScheduledCommandEvent",
        "occuredDateTime": 1248174120,  # 2009-07-21 11:02:00 AM
        "stopDateTime": 1248174240      # 2009-07-21 11:04:00 AM
    }
    event_1 = {'message': {'forward_differences': [{'object': '_302E3119-B3ED-46A1-87D5-EBC8496357DF', 'attribute': 'Switch.open', 'value': 1}],
                           'reverse_differences': [{'object': '_302E3119-B3ED-46A1-87D5-EBC8496357DF', 'attribute': 'Switch.open', 'value': 0}]},
               'event_type': 'ScheduledCommandEvent',
               'occuredDateTime': 1248177660,
               'stopDateTime': 1248177780}

    restore_event_1 = {
      "message": {
        "forward_differences": [
          {
            "object": "_D287FFEF-4813-44C4-8F30-CBF836D58DF7",
            "attribute": "Switch.open",
            "value": 1
          },
          {
            "object": "_E976600E-B276-4B9A-A65F-DEEF65A7F080",
            "attribute": "Switch.open",
            "value": 1
          },
          {
            "object": "_57574CED-ACDC-4B14-AD36-D8BE9B6DD42C",
            "attribute": "Switch.open",
            "value": 0
          },
          {
            "object": "_37619299-61AC-40B4-BB3E-6B7C2A5D5719",
            "attribute": "Switch.open",
            "value": 0
          }
        ],
        "reverse_differences": [
          {
            "object": "_D287FFEF-4813-44C4-8F30-CBF836D58DF7",
            "attribute": "Switch.open",
            "value": 0
          },
          {
            "object": "_E976600E-B276-4B9A-A65F-DEEF65A7F080",
            "attribute": "Switch.open",
            "value": 0
          },
          {
            "object": "_57574CED-ACDC-4B14-AD36-D8BE9B6DD42C",
            "attribute": "Switch.open",
            "value": 1
          },
          {
            "object": "_37619299-61AC-40B4-BB3E-6B7C2A5D5719",
            "attribute": "Switch.open",
            "value": 1
          }
        ]
      },
      "event_type": "ScheduledCommandEvent",
      "occuredDateTime": 1248177690.0,
      "stopDateTime": 1248177810.0
    }

    event_3_v2019_10_0 = {"message": {
        "forward_differences": [
          {
            "object": "_2455DC96-1030-44F6-81E9-000A3702E157",
            "attribute": "Switch.open",
            "value": 1
          },
          {
            "object": "_A7AAF230-5237-4ABC-9F0B-845DD245CC1E",
            "attribute": "Switch.open",
            "value": 1
          }
        ],
        "reverse_differences": [
          {
            "object": "_2455DC96-1030-44F6-81E9-000A3702E157",
            "attribute": "Switch.open",
            "value": 0
          },
          {
            "object": "_A7AAF230-5237-4ABC-9F0B-845DD245CC1E",
            "attribute": "Switch.open",
            "value": 0
          }
        ]
      },
      "event_type": "ScheduledCommandEvent",
      "occuredDateTime": 1563796860,
      "stopDateTime": 1563796980
    }



    # 2009-07-21 05:00:00 AM
    # ##### event_1
    # Line LINE.LN5593236-6
    # node m1047515

    # "dg_84": "_233D4DC1-66EA-DF3C-D859-D10438ECCBDF", "dg_90": "_60E702BC-A8E7-6AB8-F5EB-D038283E4D3E"
    # Meas "_facde6ab-95e2-471b-b151-1b7125d863f0","_888e15c8-380d-4dcf-9876-ccf8949d45b1"

    # sx2991914c.1
    # new Line.2002200004991174_sw phases=3 bus1=d6290228-6_int.1.2.3 bus2=q16642.1.2.3 switch=y // CIM LoadBreakSwitch
    # ~ normamps=400.00 emergamps=600.00
    #   close Line.2002200004991174_sw 1
    # {'command': 'update', 'input': {'simulation_id': 966953393, 'message': {'timestamp': 1571850450, 'difference_mrid': 'caf85954-d594-42ec-b3d1-644a32941a4a', 'reverse_differences': [{'object': '_CB845255-3CD8-4E25-9B48-3CB74EE59F63', 'attribute': 'Switch.open', 'value': 1}], 'forward_differences': [{'object': '_CB845255-3CD8-4E25-9B48-3CB74EE59F63', 'attribute': 'Switch.open', 'value': 0}]}}}

    pv_84_90_event = {
        "allOutputOutage": False,
        "allInputOutage": False,
        "inputOutageList": [{"objectMRID": "_233D4DC1-66EA-DF3C-D859-D10438ECCBDF", "attribute": "PowerElectronicsConnection.p"},
                            {"objectMRID": "_233D4DC1-66EA-DF3C-D859-D10438ECCBDF", "attribute": "PowerElectronicsConnection.q"},
                            {"objectMRID": "_60E702BC-A8E7-6AB8-F5EB-D038283E4D3E", "attribute": "PowerElectronicsConnection.p"},
                            {"objectMRID": "_60E702BC-A8E7-6AB8-F5EB-D038283E4D3E", "attribute": "PowerElectronicsConnection.q"},
                            ],
        "outputOutageList": ['_a5107987-1609-47b2-8f5b-f91f99658390', '_2c4e0cb2-4bf0-4a2f-be94-83ee9b87d1e5'],
        "event_type": "CommOutage",
        "occuredDateTime": 1374510600 + (5*60),
        "stopDateTime": 1374510600 + (10*60)
    }

    # _EAE0584D-6B67-2F23-FC02-E3F2C8C6A48D"
    # _73E7B579-37DB-B7F2-EBC6-D083E8BBA1F3
    # 104.3 dg_84 _b8442bbd-4d3e-4b2e-884e-96639bb207bc
    # 113.1 dg_90 _b005322e-7dba-48d3-b6ce-f6fe57c4dd61

    pv_84_90_event = {
        "allOutputOutage": False,
        "allInputOutage": False,
        "inputOutageList": [{"objectMRID": "_EAE0584D-6B67-2F23-FC02-E3F2C8C6A48D", "attribute": "PowerElectronicsConnection.p"},
                            {"objectMRID": "_EAE0584D-6B67-2F23-FC02-E3F2C8C6A48D", "attribute": "PowerElectronicsConnection.q"},
                            {"objectMRID": "_73E7B579-37DB-B7F2-EBC6-D083E8BBA1F3", "attribute": "PowerElectronicsConnection.p"},
                            {"objectMRID": "_73E7B579-37DB-B7F2-EBC6-D083E8BBA1F3", "attribute": "PowerElectronicsConnection.q"},
                            ],
        "outputOutageList": ['_b8442bbd-4d3e-4b2e-884e-96639bb207bc', '_b005322e-7dba-48d3-b6ce-f6fe57c4dd61'],
        "event_type": "CommOutage",
        "occuredDateTime": 1374510600 + (5*60),
        "stopDateTime": 1374510600 + (10*60)
    }


    # {"applications": [{"name": "der_dispatch_app", "config_string": ""}]}
    req_template['simulation_config']['model_creation_config']['load_scaling_factor'] = 1
    req_template['simulation_config']['run_realtime'] = False
    req_template['simulation_config']['duration'] = 60 * 60 * 1
    req_template['simulation_config']['duration'] = 60 * 20

    req_template['simulation_config']['start_time'] = 1538510000
    req_template['simulation_config']['start_time'] = 1374498000  # GMT: Monday, July 22, 2013 1:00:00 PM What I was doing
    req_template['simulation_config']['start_time'] = 1374510600  # GMT: Monday, July 22, 2013 4:30:00 PM MST 10:30:00 AM
    # req_template['simulation_config']['start_time'] = 1374517800   # GMT: Monday, July 22, 2013 6:30:00 PM
    # req_template['simulation_config']['start_time'] = 1374510720  # GMT: Monday, July 22, 2013 4:30:00 PM PLUS 2 minutes!!
    # July 22, 2013 4:32:00 GMT
    # July 22, 2013 10:32:00 2013-07-22 10:32:00
    # req_template['simulation_config']['start_time'] = 1374514200  # GMT: Monday, July 22, 2013 5:30:00 PM

    # req_template['simulation_config']['start_time'] = 1374519600  # (GMT): Monday, July 22, 2013 7:00:00 PM
    # req_template['simulation_config']['start_time'] = 1374530400  # (GMT): Monday, July 22, 2013 10:00:00 PM Cause
    # req_template['simulation_config']['start_time'] = 1374454800  # (GMT): Monday, July 22, 2013 1:00:00 AM
    # req_template['simulation_config']['start_time'] = 1374411600  # 7/21/2013 7AM
    req_template['simulation_config']['start_time'] = 1374256800  # (GMT): Friday, July 19, 2013 6:00:00 PM
    req_template['simulation_config']['start_time'] = 1374217200  # July 19 07:00 AM GMT / 1:00 AM MST
    req_template['simulation_config']['start_time'] = 1374228000  # July 19 10:00 AM GMT / 4:00 AM MST
    req_template['simulation_config']['start_time'] = 1374233400  # July 19 11:30 AM GMT / 5:30 AM MST
    req_template['simulation_config']['start_time'] = 1374240600  # July 19 13:30 AM GMT / 7:30 AM MST
    req_template['simulation_config']['start_time'] = 1374213600  # July 19 06:00 AM GMT / 00:00 AM MST
    req_template['simulation_config']['start_time'] = 1374235200  # July 19 12:00 PM GMT / 06:00 AM MST
    req_template['simulation_config']['start_time'] = 1248156000  # Tuesday, July 21, 2009 6:00:00 AM
    req_template['simulation_config']['start_time'] = 1248192000  # Tuesday, July 21, 2009 4:00:00 PM / 10:00:00 AM
    req_template['simulation_config']['start_time'] = 1248199200  # Tuesday, July 21, 2009 6:00:00 PM / 12:00:00 PM
    req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 13:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 12:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    req_template['simulation_config']['start_time'] = timegm(strptime('2019-07-22 11:01:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))

    req_template['simulation_config']['start_time'] = timegm(strptime('2019-07-23 14:50:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    req_template['simulation_config']['start_time'] = timegm(strptime('2013-07-22 12:01:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    #2013-07-14 08:00:00

    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 10:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 09:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 18:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 20:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 21:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-21 18:00:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))
    # req_template['simulation_config']['start_time'] = 1374249600  #  July 19, 2013 4:00:00 PM
    # req_template['simulation_config']['start_time'] = 1374258600  # July 19, 2013 6:30:00 PM  - 2013-07-19 18:30:00 / 12:30 PM MST  # MAX PV!!!
    # req_template['simulation_config']['start_time'] = timegm(strptime('2009-07-19 12:30:00 GMT', '%Y-%m-%d %H:%M:%S %Z'))  # July 19, 2013 6:30:00 PM  - 2013-07-19 18:30:00 / 12:30 PM MST  # MAX PV!!!
    # dg_42 _2B5D7749-6C18-D77E-B848-3F4C31ADC3E6 p=146621.68181873375 q=-179.94738632961975
    # 2013-07-19 18:32:00
    # 2013-07-19 18:35:00

    # pv_84_90_event["occuredDateTime"] = req_template['simulation_config']['start_time'] + (5*60)
    # pv_84_90_event["stopDateTime"]    = req_template['simulation_config']['start_time'] + (10*60)
    # req_template["test_config"]["events"].append(pv_84_90_event)

    # req_template["test_config"]["events"].append(sw3_event)
    # req_template["test_config"]["events"].append(event_l114)

    # event_1_v2019_10_0["occuredDateTime"] = req_template['simulation_config']['start_time'] + (1*60)
    # event_1_v2019_10_0["stopDateTime"]    = req_template['simulation_config']['start_time'] + (3*60)
    # req_template["test_config"]["events"].append(event_1_v2019_10_0)

    # event_1["occuredDateTime"] = req_template['simulation_config']['start_time'] + (1*60)
    # event_1["stopDateTime"]    = req_template['simulation_config']['start_time'] + (3*60)
    # req_template["test_config"]["events"].append(event_1)

    #event_3_v2019_10_0
    event_3_v2019_10_0["occuredDateTime"] = req_template['simulation_config']['start_time'] + (1*60)
    event_3_v2019_10_0["stopDateTime"]    = req_template['simulation_config']['start_time'] + (3*60)
    # req_template["test_config"]["events"].append(event_3_v2019_10_0)

    # event_3["occuredDateTime"] = req_template['simulation_config']['start_time'] + (1*60)
    # event_3["stopDateTime"]    = req_template['simulation_config']['start_time'] + (3*60)
    # req_template["test_config"]["events"].append(event_3)

    app_config = {'OPF': 1, 'run_freq': 15, 'run_on_host': True}
    app_config['run_realtime'] = req_template['simulation_config']['run_realtime']
    app_config['stepsize_xp'] = 0.2
    app_config['stepsize_xq'] = 2
    # app_config['coeff_p'] = 0.1
    # app_config['coeff_q'] = 0.00005
    app_config['coeff_p'] = 0.005
    app_config['coeff_q'] = 0.0005
    app_config['Vupper'] = 1.025
    app_config['Vlower'] = 0.95
    app_config['stepsize_mu'] = 50000
    app_config['optimizer_num_iterations'] = 10
    print(json.dumps(app_config,indent=2))
    # exit(0)

    #TODO stepsize_mu = 50000 lower this! 500 or 50
    req_template["application_config"]["applications"] = [{"name": "der_dispatch_app", "config_string": json.dumps(app_config)}]

    # GMT: Tuesday, October 2, 2018 4:50:00 PM
    # Your time zone: Tuesday, October 2, 2018 10:50:00 AM GMT-06:00 DST
    req_template['power_system_config']['Line_name'] = '_E407CBB6-8C8D-9BC9-589C-AB83FBF0826D'  # Mine 123pv'
    # req_template['power_system_config']['Line_name'] = '_EBDB5A4A-543C-9025-243E-8CAD24307380'  # 123 with reg
    # req_template['power_system_config']['Line_name'] = '_88B3A3D8-51CD-7466-5E29-B692F21723CB' # Mine with feet conv
    req_template['power_system_config']['Line_name'] = '_DA00D94F-4683-FD19-15D9-8FF002220115'  # mine with house

    # req_template['power_system_config']['Line_name'] = '_49AD8E07-3BF9-A4E2-CB8F-C3722F837B62'  # 13
    req_template['power_system_config']['Line_name'] = '_AAE94E4A-2465-6F5E-37B1-3E72183A4E44'  # New 8500 9500
    # req_template['power_system_config']['Line_name'] = '_C1C3E687-6FFD-C753-582B-632A27E28507'

    # req_template['power_system_config']['Line_name'] = '_4F76A5F9-271D-9EB8-5E31-AA362D86F2C3'
    # req_template["application_config"]["applications"][0]['name'] = 'sample_app'
    req_template["application_config"]["applications"][0]['name'] = 'der_dispatch_app'

    req_template['power_system_config']['Line_name'] = '_49AD8E07-3BF9-A4E2-CB8F-C3722F837B62'
    # req_template['power_system_config']['Line_name'] = '_E407CBB6-8C8D-9BC9-589C-AB83FBF0826D'
    req_template['power_system_config']['Line_name'] = '_AAE94E4A-2465-6F5E-37B1-3E72183A4E44'

    ## TOD test with 13 8/24/2020

    simCfg13pv = json.dumps(req_template)
    print(simCfg13pv)

    goss = GOSS()
    goss.connect()

    simulation_id = goss.get_response(goss_sim, simCfg13pv, timeout=220) # 180 Maybe?
    simulation_id = int(simulation_id['simulationId'])
    print(simulation_id)
    print('sent simulation request')
    time.sleep(1)

    if app_config['run_on_host']:
        from main_app_new import DER_Dispatch
        listening_to_topic = simulation_output_topic(simulation_id)
        print(listening_to_topic)
        log_topic = simulation_log_topic(simulation_id)
        model_mrid = req_template['power_system_config']['Line_name']
        start_time = req_template['simulation_config']['start_time']
        app_configs = req_template["application_config"]["applications"]
        app_config = [json.loads(app['config_string']) for app in app_configs if app['name'] == 'der_dispatch_app'][0]

        # gapps = GridAPPSD(simulation_id)
        from gridappsd import utils
        gapps = GridAPPSD(simulation_id, address=utils.get_gridappsd_address(),
                          username=utils.get_gridappsd_user(), password=utils.get_gridappsd_pass())
        load_scale = req_template['simulation_config']['model_creation_config']['load_scaling_factor']
        der_0 = DER_Dispatch(simulation_id, gapps, model_mrid, './FeederInfo', start_time, app_config, load_scale)
        der_0.setup()
        gapps.subscribe(listening_to_topic, der_0)
        gapps.subscribe(log_topic, der_0)

        while der_0.running():
            time.sleep(0.1)