Beispiel #1
0
def run(interface, port, setup_module_name, settings_file, slowdown, seed,
        paused, pause_after, repl, export, export_path, reset_on_finish,
        reset_on_finish_wait, exit_on_finish, exit_on_finish_wait, enable_bc,
        enable_bm, **config_params):
    try:
        if settings_file is not None:
            simulation_settings, advanced_settings = read_settings_from_file(
                settings_file)
            update_advanced_settings(advanced_settings)
            simulation_config = SimulationConfig(**simulation_settings)
        else:
            simulation_config = SimulationConfig(**config_params)

        api_url = "http://{}:{}/api".format(interface, port)
        ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = enable_bm
        simulation = Simulation(setup_module_name=setup_module_name,
                                simulation_config=simulation_config,
                                slowdown=slowdown,
                                seed=seed,
                                paused=paused,
                                pause_after=pause_after,
                                use_repl=repl,
                                export=export,
                                export_path=export_path,
                                reset_on_finish=reset_on_finish,
                                reset_on_finish_wait=reset_on_finish_wait,
                                exit_on_finish=exit_on_finish,
                                exit_on_finish_wait=exit_on_finish_wait,
                                api_url=api_url,
                                redis_job_id=None,
                                use_bc=enable_bc)
    except D3AException as ex:
        raise click.BadOptionUsage(ex.args[0])
    start_web(interface, port, simulation)
    simulation.run()
Beispiel #2
0
def start(scenario, settings):
    logging.getLogger().setLevel(logging.ERROR)
    interface = environ.get('WORKER_INTERFACE', "0.0.0.0")
    port = int(environ.get('WORKER_PORT', 5000))
    api_host = environ.get('WORKER_HOST', interface)
    api_url = "http://{}:{}/api".format(api_host, port)

    job = get_current_job()
    job.meta['api_url'] = api_url
    job.save_meta()

    if settings is None:
        settings = {}

    advanced_settings = settings.get('advanced_settings', None)
    if advanced_settings is not None:
        update_advanced_settings(ast.literal_eval(advanced_settings))

    config = SimulationConfig(
        duration=pendulum.duration(days=1 if 'duration' not in
                                   settings else settings['duration'].days),
        slot_length=pendulum.duration(
            seconds=15 * 60 if 'slot_length' not in
            settings else settings['slot_length'].seconds),
        tick_length=pendulum.duration(
            seconds=15 if 'tick_length' not in
            settings else settings['tick_length'].seconds),
        market_count=settings.get('market_count', 1),
        cloud_coverage=settings.get(
            'cloud_coverage', ConstSettings.PVSettings.DEFAULT_POWER_PROFILE),
        pv_user_profile=settings.get('pv_user_profile', None),
        market_maker_rate=settings.get(
            'market_maker_rate',
            str(ConstSettings.GeneralSettings.DEFAULT_MARKET_MAKER_RATE)),
        iaa_fee=settings.get('iaa_fee',
                             ConstSettings.IAASettings.FEE_PERCENTAGE))

    if scenario is None:
        scenario_name = "default"
    elif scenario in available_simulation_scenarios:
        scenario_name = scenario
    else:
        scenario_name = 'json_arg'
        config.area = scenario

    simulation = Simulation(scenario_name,
                            config,
                            slowdown=settings.get('slowdown', 0),
                            exit_on_finish=True,
                            exit_on_finish_wait=pendulum.duration(seconds=10),
                            api_url=api_url,
                            redis_job_id=job.id)

    start_web(interface, port, simulation)
    simulation.run()