Example #1
0
def storage_never_selling(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    for time_slot, core_stats in context.raw_sim_data.items():
        for trade in core_stats[context.name_uuid_map['House 1']]['trades']:
            assert trade['seller'] != "H1 Storage"
            assert trade['buyer'] == "H1 Storage"
Example #2
0
def check_buy_behaviour_ib(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    name_uuid_map = get_area_name_uuid_mapping(context.area_tree_summary_data)
    grid = context.simulation.area
    bus = list(filter(lambda x: x.name == "Infinite Bus", grid.children))[0]
    for time_slot, core_stats in context.raw_sim_data.items():
        for trade in core_stats[name_uuid_map['Grid']]['trades']:
            if trade['seller'] == "Infinite Bus":
                assert limit_float_precision(trade['energy_rate']) >= \
                       core_stats[name_uuid_map['Infinite Bus']]['energy_rate']
            else:
                assert limit_float_precision(trade['energy_rate']) <= \
                       core_stats[name_uuid_map['Infinite Bus']]['energy_rate']

            if trade['buyer'] == "Infinite Bus":
                # TODO: energy_buy_rate is not part of the raw simulation data, therefore
                # it is obligatory to retrieve it from the strategy. This needs to change once
                # we add the energy_buy_rate to the infinite bus result data.
                assert limit_float_precision(trade['energy_rate']) <= \
                       list(bus.strategy.energy_buy_rate.values())[0]

            if trade['buyer'] == "H1 General Load":
                assert trade['energy'] == \
                       core_stats[name_uuid_map['H1 General Load']]['load_profile_kWh']
            elif trade['seller'] == 'Infinite Bus':
                assert isclose(
                    trade['energy'],
                    (core_stats[
                        name_uuid_map['H1 General Load']]['load_profile_kWh'] -
                     core_stats[name_uuid_map['H1 PV']]['pv_production_kWh']))
Example #3
0
def test_net_energy_flow_stats(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    from d3a_interface.sim_results.area_throughput_stats import AreaThroughputStats
    area_throughput = AreaThroughputStats()
    for time_slot, core_stats in context.raw_sim_data.items():

        area_throughput.update(context.area_tree_summary_data, core_stats,
                               time_slot)
        house_result = area_throughput.results_redis[
            context.name_uuid_map['House 1']][time_slot]
        assert house_result['import']['peak_energy_trade_kWh'] == 1.0
        assert house_result['import']['peak_energy_net_kWh'] == 0.5
        exp_percentage = (
            house_result['import']['peak_energy_net_kWh'] /
            house_result['import']['baseline_peak_energy_kWh']) * 100
        assert house_result['import']['peak_percentage'] == exp_percentage
        assert house_result['import']['baseline_peak_energy_kWh'] == 1
        assert house_result['import']['capacity_kWh'] == 1
        assert house_result['export']['peak_energy_trade_kWh'] == 0.5
        assert isclose(house_result['export']['peak_energy_net_kWh'],
                       0.0,
                       rel_tol=1e-1)
        exp_percentage = (
            house_result['export']['peak_energy_net_kWh'] /
            house_result['export']['baseline_peak_energy_kWh']) * 100
        assert isclose(house_result['export']['peak_percentage'],
                       exp_percentage,
                       abs_tol=1e-10)
        assert isclose(house_result['net_energy_flow']['peak_energy_kWh'],
                       0.5,
                       rel_tol=1e-1)
Example #4
0
def check_matching_trades(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    for time_slot, core_stats in context.raw_sim_data.items():
        grid_trades = core_stats[context.name_uuid_map['Grid']]['trades']
        house_trades = core_stats[context.name_uuid_map['House 1']]['trades']
        assert len(grid_trades) == len(house_trades)
        assert all(
            any(t['energy'] == th['energy'] and t['buyer'] == th['seller'] for th in house_trades)
            for t in grid_trades)
Example #5
0
def load_demands_fulfilled(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    for time_slot, core_stats in context.raw_sim_data.items():
        slot = _str_to_datetime(time_slot, DATE_TIME_FORMAT)
        for child, parent in scenario_representation_traversal(
                context.simulation.area):
            if isinstance(child.strategy, LoadHoursStrategy):
                assert isclose(
                    child.strategy.state.get_energy_requirement_Wh(slot),
                    0.0,
                    rel_tol=1e8)
Example #6
0
def energy_origin(context, producer, consumer):
    trade_count = 0
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)

    for time_slot, core_stats in context.raw_sim_data.items():
        for trade in core_stats[context.name_uuid_map['Grid']]['trades']:
            trade_count += 1
            assert trade['buyer_origin'] == consumer
            assert trade['seller_origin'] == producer

    assert trade_count > 0
Example #7
0
def test_output(context, scenario, sim_duration, slot_length, tick_length):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)

    # (check if simulation successfully finished):
    assert len(context.raw_sim_data.keys()) == 24
    if scenario == "default":
        assert {"Street 1", "S1 House 1", "S1 H1 Load"}.\
            issubset(set(context.name_uuid_map.keys()))
        for time_slot, core_stats in context.raw_sim_data.items():
            assert 'load_profile_kWh' in core_stats[
                context.name_uuid_map['S1 H1 Load']].keys()
Example #8
0
def pv_constant_power(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    load_energies_set = set()
    pv_energies_set = set()

    for time_slot, core_stats in context.raw_sim_data.items():
        for trade in core_stats[context.name_uuid_map['House 1']]['trades']:
            if trade['buyer'] == "H1 General Load":
                load_energies_set.add(trade['energy'])
        for trade in core_stats[context.name_uuid_map['House 2']]['trades']:
            if trade['seller'] == 'H2 PV':
                pv_energies_set.add(trade['energy'])

    assert len(load_energies_set) == 1
    assert len(pv_energies_set) == 1
    assert load_energies_set == pv_energies_set
Example #9
0
def check_user_rate_profile_dict(context):
    house = next(filter(lambda x: x.name == "House 1", context.simulation.area.children))
    load1 = next(filter(lambda x: x.name == "H1 General Load 1", house.children))
    load2 = next(filter(lambda x: x.name == "H1 General Load 2", house.children))
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    for time_slot, core_stats in context.raw_sim_data.items():
        slot = _str_to_datetime(time_slot, DATE_TIME_FORMAT)
        load1_final_rate = load1.strategy.bid_update.final_rate_profile_buffer[slot]
        load2_final_rate = load2.strategy.bid_update.final_rate_profile_buffer[slot]
        load1_trades = \
            list(filter(lambda x:
                        x["energy_rate"] > load1_final_rate,
                        core_stats[context.name_uuid_map["H1 General Load 1"]]["trades"]))
        load2_trades = \
            list(filter(lambda x: x["energy_rate"] > load2_final_rate,
                        core_stats[context.name_uuid_map["H1 General Load 2"]]["trades"]))

        assert len(load1_trades) == 0 and len(load2_trades) == 0
Example #10
0
def check_area_trade_and_bill(context):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)
    count = 0
    mped = MarketPriceEnergyDay(should_export_plots=False)
    for time_slot, core_stats in context.raw_sim_data.items():
        mped.update(context.area_tree_summary_data, core_stats, time_slot)
        count += 1
        area_data = mped.redis_output[context.name_uuid_map['Grid']]
        assert area_data['price-energy-day'][0]['min_price'] == 0.35
        assert area_data['price-energy-day'][0]['max_price'] == 0.35
        assert area_data['price-energy-day'][0]['grid_fee_constant'] == 0.05
    assert count == 24
    cb = CumulativeBills()
    for time_slot, core_stats in context.raw_sim_data.items():
        cb.update(context.area_tree_summary_data, core_stats, time_slot)
    assert isclose(cb.cumulative_bills_results[context.name_uuid_map['Market Maker']]['earned'],
                   0.72)
    assert isclose(cb.cumulative_bills_results[context.name_uuid_map['Load']]['spent_total'], 0.84)
Example #11
0
def device_partially_fulfill_bid(context, device):
    from integration_tests.steps.integration_tests import get_simulation_raw_results
    get_simulation_raw_results(context)

    for time_slot, core_stats in context.raw_sim_data.items():
        grid_trades = core_stats[context.name_uuid_map['Grid']]['trades']
        house1_trades = core_stats[context.name_uuid_map['House 1']]['trades']
        house2_trades = core_stats[context.name_uuid_map['House 2']]['trades']
        if len(house1_trades) == 0:
            continue

        # Assert one trade for each PV
        assert len(house1_trades) == 5
        assert all(trade['buyer'] == device for trade in house1_trades)
        assert all(trade['seller'] == "IAA House 1" for trade in house1_trades)
        assert len(grid_trades) == 5
        assert all(trade['buyer'] == "IAA House 1" for trade in grid_trades)
        assert all(trade['seller'] == "IAA House 2" for trade in grid_trades)

        pv_names = ['H2 PV1', 'H2 PV2', 'H2 PV3', 'H2 PV4', 'H2 PV5']
        assert all(trade['buyer'] == "IAA House 2" for trade in house2_trades)
        assert all(trade['seller'] in pv_names for trade in house2_trades)