Example #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()
Example #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()
Example #3
0
def run_sim_with_config_setting(context, cloud_coverage, iaa_fee, scenario):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    simulation_config = SimulationConfig(duration(hours=int(24)),
                                         duration(minutes=int(60)),
                                         duration(seconds=int(60)),
                                         market_count=4,
                                         cloud_coverage=int(cloud_coverage),
                                         iaa_fee=int(iaa_fee))

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    no_export = True
    export_path = None
    export_subdir = None
    context.simulation = Simulation(
        scenario,
        simulation_config,
        None,
        slowdown,
        seed,
        paused,
        pause_after,
        repl,
        no_export,
        export_path,
        export_subdir,
    )
    context.simulation.run()
Example #4
0
def running_the_simulation(context):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    no_export = True
    export_path = None
    export_subdir = None
    context.simulation = Simulation(
        'json_arg',
        context._settings,
        None,
        slowdown,
        seed,
        paused,
        pause_after,
        repl,
        no_export,
        export_path,
        export_subdir,
    )
    context.simulation.run()
Example #5
0
def run_sim(context, scenario, total_duration, slot_length, tick_length,
            iaa_fee, market_count):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    simulation_config = SimulationConfig(duration(hours=int(total_duration)),
                                         duration(minutes=int(slot_length)),
                                         duration(seconds=int(tick_length)),
                                         market_count=int(market_count),
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         iaa_fee=int(iaa_fee))

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    export = False
    export_path = None
    reset_on_finish = False
    reset_on_finish_wait = duration()
    exit_on_finish = True
    exit_on_finish_wait = duration()

    api_url = "http://localhost:5000/api"
    context.simulation = Simulation(scenario, simulation_config, slowdown,
                                    seed, paused, pause_after, repl, export,
                                    export_path, reset_on_finish,
                                    reset_on_finish_wait, exit_on_finish,
                                    exit_on_finish_wait, api_url)
    context.simulation.run()
Example #6
0
def run_sim_with_config_setting(context, cloud_coverage, iaa_fee, scenario):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    simulation_config = SimulationConfig(
        duration(hours=int(24)),
        duration(minutes=int(60)),
        duration(seconds=int(60)),
        market_count=4,
        cloud_coverage=int(cloud_coverage),
        market_maker_rate=context._market_maker_rate,
        iaa_fee=int(iaa_fee))

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    export = False
    export_path = None
    reset_on_finish = False
    reset_on_finish_wait = duration()
    exit_on_finish = True
    exit_on_finish_wait = duration()

    api_url = "http://localhost:5000/api"
    context.simulation = Simulation(scenario, simulation_config, slowdown,
                                    seed, paused, pause_after, repl, export,
                                    export_path, reset_on_finish,
                                    reset_on_finish_wait, exit_on_finish,
                                    exit_on_finish_wait, api_url)
    context.simulation.run()
Example #7
0
def create_sim_object(context, scenario):
    simulation_config = SimulationConfig(duration(hours=int(24)),
                                         duration(minutes=int(15)),
                                         duration(seconds=int(30)),
                                         market_count=4,
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         iaa_fee=5)

    context.simulation = Simulation(scenario, simulation_config, 0, 0, False,
                                    duration(), False, False, None, False,
                                    duration(), True, duration(), None, "1234")
Example #8
0
    def test_results_not_send_via_kafka_if_started_from_cli():
        redis_job_id = "1234"
        simulation_config = SimulationConfig(duration(hours=int(12)),
                                             duration(minutes=int(60)),
                                             duration(seconds=int(60)),
                                             market_count=1,
                                             cloud_coverage=0,
                                             market_maker_rate=30,
                                             start_date=today(tz=TIME_ZONE),
                                             external_connection_enabled=False)
        simulation = Simulation("default_2a", simulation_config, None, 0,
                                False, duration(), False, True, None, None,
                                redis_job_id, False)
        simulation.endpoint_buffer = MagicMock(spec=SimulationEndpointBuffer)
        results_mapping = ResultsHandler().results_mapping
        simulation.endpoint_buffer.results_handler = MagicMock(
            spec=ResultsHandler)
        simulation.kafka_connection = MagicMock(spec=KafkaConnection)
        simulation.endpoint_buffer.results_handler.all_ui_results = {
            k: {}
            for k in results_mapping
        }

        simulation._update_and_send_results()

        simulation.endpoint_buffer.prepare_results_for_publish.assert_called_once(
        )
        simulation.kafka_connection.publish.assert_called_once()
Example #9
0
def create_sim_object(context, scenario):
    simulation_config = SimulationConfig(duration(hours=int(12)),
                                         duration(minutes=int(60)),
                                         duration(seconds=int(60)),
                                         market_count=1,
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         start_date=today(tz=TIME_ZONE),
                                         external_connection_enabled=False)

    context.simulation = Simulation(scenario, simulation_config, None, 0,
                                    False, duration(), False, True, None, None,
                                    "1234", False)
Example #10
0
def run_sim(context, scenario, total_duration, slot_length, tick_length,
            market_count):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.ERROR)

    simulation_config = SimulationConfig(duration(hours=int(total_duration)),
                                         duration(minutes=int(slot_length)),
                                         duration(seconds=int(tick_length)),
                                         market_count=int(market_count),
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         external_connection_enabled=False)

    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    export_subdir = None
    context.export_path = os.path.join(context.simdir, scenario)
    os.makedirs(context.export_path, exist_ok=True)
    try:
        context.simulation = Simulation(
            scenario,
            simulation_config,
            None,
            seed,
            paused,
            pause_after,
            repl,
            context.no_export,
            context.export_path,
            export_subdir,
        )
        context.simulation.run()
    except Exception as er:
        if context.raise_exception_when_running_sim:
            root_logger.critical(
                f"Error reported when running the simulation: {er}")
            root_logger.critical(f"Traceback: {traceback.format_exc()}")
            raise Exception(er)
        else:
            context.sim_error = er
Example #11
0
def run_sim_multiday(context, scenario, start_date, total_duration,
                     slot_length, tick_length):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)
    if start_date == "None":
        start_date = today(tz=TIME_ZONE)
    else:
        start_date = from_format(start_date, DATE_FORMAT)

    simulation_config = SimulationConfig(duration(hours=int(total_duration)),
                                         duration(minutes=int(slot_length)),
                                         duration(seconds=int(tick_length)),
                                         market_count=1,
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         iaa_fee=1,
                                         start_date=start_date)

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    no_export = True
    export_path = None
    export_subdir = None
    context.simulation = Simulation(
        scenario,
        simulation_config,
        None,
        slowdown,
        seed,
        paused,
        pause_after,
        repl,
        no_export,
        export_path,
        export_subdir,
    )
    context.simulation.run()
Example #12
0
def run_sim(context, scenario, total_duration, slot_length, tick_length,
            market_count):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    simulation_config = SimulationConfig(duration(hours=int(total_duration)),
                                         duration(minutes=int(slot_length)),
                                         duration(seconds=int(tick_length)),
                                         market_count=int(market_count),
                                         cloud_coverage=0,
                                         market_maker_rate=30,
                                         external_connection_enabled=False)

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    no_export = True
    export_path = None
    export_subdir = None
    try:
        context.simulation = Simulation(
            scenario,
            simulation_config,
            None,
            slowdown,
            seed,
            paused,
            pause_after,
            repl,
            no_export,
            export_path,
            export_subdir,
        )
        context.simulation.run()
    except Exception as er:
        root_logger.critical(
            f"Error reported when running the simulation: {er}")
        context.sim_error = er
Example #13
0
def running_the_simulation(context):

    root_logger = logging.getLogger()
    root_logger.setLevel(logging.CRITICAL)

    slowdown = 0
    seed = 0
    paused = False
    pause_after = duration()
    repl = False
    export = False
    export_path = None
    reset_on_finish = False
    reset_on_finish_wait = duration()
    exit_on_finish = True
    exit_on_finish_wait = duration()

    api_url = "http://localhost:5000/api"
    context.simulation = Simulation('json_arg', context._settings, slowdown,
                                    seed, paused, pause_after, repl, export,
                                    export_path, reset_on_finish,
                                    reset_on_finish_wait, exit_on_finish,
                                    exit_on_finish_wait, api_url)
    context.simulation.run()