Ejemplo n.º 1
0
    def test_export_unmatched_loads_reports_cell_tower_areas(self):
        house1 = Area("House1", [self.area1, self.area2])
        ct_strategy = MagicMock(spec=CellTowerLoadHoursStrategy)
        ct_strategy.state = MagicMock(spec=LoadState)
        ct_strategy.state.desired_energy_Wh = {}
        cell_tower = Area("Cell Tower", strategy=ct_strategy)
        self.grid = Area("Grid", [house1, cell_tower])
        for i in range(1, 11):
            timeslot = today(tz=TIME_ZONE).add(hours=12 + i)
            self.strategy1.state.desired_energy_Wh[timeslot] = 100
            self.strategy2.state.desired_energy_Wh[timeslot] = 100

            mock_market = MagicMock(spec=Market)
            mock_market.time_slot = timeslot
            mock_market.traded_energy = {"load1": -0.09, "load2": -0.099}
            house1._markets.past_markets[timeslot] = mock_market

            mock_market_ct = MagicMock(spec=Market)
            mock_market_ct.time_slot = timeslot
            mock_market_ct.traded_energy = {"Cell Tower": -0.4}
            ct_strategy.state.desired_energy_Wh[timeslot] = 1000
            cell_tower._markets.past_markets[timeslot] = mock_market_ct

            self.grid._markets.past_markets[timeslot] = mock_market

        unmatched_loads, unmatched_loads_redis = \
            ExportUnmatchedLoads(self.grid).get_current_market_results(all_past_markets=True)
        assert get_number_of_unmatched_loads(unmatched_loads) == 30
Ejemplo n.º 2
0
def check_buy_behaviour_ib(context):
    grid = context.simulation.area
    bus = list(filter(lambda x: x.name == "Infinite Bus", grid.children))[0]
    house_1 = list(filter(lambda x: x.name == "House 1", grid.children))[0]
    pv = list(filter(lambda x: x.name == "H1 PV", house_1.children))[0]
    load = list(filter(lambda x: x.name == "H1 General Load",
                       house_1.children))[0]

    for market in grid.past_markets:
        for trade in market.trades:
            assert limit_float_precision(trade.offer.price / trade.offer.energy) <= \
                   bus.strategy.energy_rate[market.time_slot] + house_1.transfer_fee_const or \
                   "Infinite Bus" is not trade.seller

            if trade.buyer == load.name:
                assert trade.offer.energy == load.strategy.avg_power_W / 1000.
            elif trade.seller == bus.name:
                assert isclose(
                    trade.offer.energy, load.strategy.avg_power_W / 1000. -
                    pv.strategy.energy_production_forecast_kWh[
                        market.time_slot])

    unmatched, unmatched_redis = \
        ExportUnmatchedLoads(context.simulation.area).get_current_market_results(
            all_past_markets=True)
    assert get_number_of_unmatched_loads(unmatched) == 0
Ejemplo n.º 3
0
def check_user_rate_profile_dict(context):
    house = next(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))

    unmatched, unmatched_redis = \
        ExportUnmatchedLoads(context.simulation.area).get_current_market_results(
            all_past_markets=True)
    number_of_loads = 2
    # There are two loads with the same final_buying_rate profile that should report unmatched
    # energy demand for the first 6 hours of the day:
    assert get_number_of_unmatched_loads(unmatched) == int(
        number_of_loads * 6. * 60 / house.config.slot_length.minutes)
Ejemplo n.º 4
0
 def test_export_unmatched_loads_is_reporting_correctly_the_device_types(self):
     self.area1.display_type = "Area 1 type"
     self.area3.display_type = "Area 3 type"
     house1 = Area("House1", [self.area1, self.area3])
     self.grid = Area("Grid", [house1])
     unmatched_loads, unmatched_loads_redis = \
         ExportUnmatchedLoads(self.grid).get_current_market_results(all_past_markets=True)
     assert get_number_of_unmatched_loads(unmatched_loads) == 0
     assert "type" not in unmatched_loads["House1"]
     assert unmatched_loads["House1"]["load1"]["type"] == "Area 1 type"
     assert unmatched_loads["House1"]["load3"]["type"] == "Area 3 type"
     assert unmatched_loads_redis[house1.uuid]["load1"]["type"] == "Area 1 type"
     assert unmatched_loads_redis[house1.uuid]["load3"]["type"] == "Area 3 type"
     assert "type" not in unmatched_loads["Grid"]
     assert unmatched_loads["Grid"]["House1"]["type"] == "Area"
     assert unmatched_loads_redis[self.grid.uuid]["House1"]["type"] == "Area"
Ejemplo n.º 5
0
 def test_export_unmatched_loads_is_reported_correctly_for_predefined_load_strategy(self):
     house1 = Area("House1", [self.area1, self.area3])
     self.grid = Area("Grid", [house1])
     self.grid._markets.past_markets = {}
     for i in range(1, 11):
         timeslot = today(tz=TIME_ZONE).add(hours=12+i)
         mock_market = MagicMock(spec=Market)
         mock_market.time_slot = timeslot
         self.strategy1.state.desired_energy_Wh[timeslot] = 100
         self.strategy3.state.desired_energy_Wh[timeslot] = 80
         mock_market.traded_energy = {"load1": -0.099, "load3": -0.079}
         house1._markets.past_markets[timeslot] = mock_market
         self.grid._markets.past_markets[timeslot] = mock_market
     unmatched_loads, unmatched_loads_redis = \
         ExportUnmatchedLoads(self.grid).get_current_market_results(all_past_markets=True)
     assert get_number_of_unmatched_loads(unmatched_loads) == 20
Ejemplo n.º 6
0
    def test_export_unmatched_loads_is_reported_correctly_for_all_loads_matched(self):
        house1 = Area("House1", [self.area1, self.area2])
        self.grid = Area("Grid", [house1])
        self.grid._markets.past_markets = {}
        for i in range(1, 11):
            timeslot = today(tz=TIME_ZONE).add(hours=12+i)
            self.strategy1.state.desired_energy_Wh[timeslot] = 100
            self.strategy2.state.desired_energy_Wh[timeslot] = 100
            mock_market = MagicMock(spec=Market)
            mock_market.time_slot = timeslot
            mock_market.traded_energy = {"load1": -0.101, "load2": -0.101}
            house1._markets.past_markets[timeslot] = mock_market
            self.grid._markets.past_markets[timeslot] = mock_market

        unmatched_loads, unmatched_loads_redis = \
            ExportUnmatchedLoads(self.grid).get_current_market_results(all_past_markets=True)

        assert list(unmatched_loads[self.grid.name].keys()) == ['House1']
        assert get_number_of_unmatched_loads(unmatched_loads) == 0
Ejemplo n.º 7
0
def test_output(context, scenario, sim_duration, slot_length, tick_length):

    if scenario in ["default_2a", "default_2b", "default_3"]:
        unmatched_loads, unmatched_loads_redis = \
            ExportUnmatchedLoads(context.simulation.area).get_current_market_results(
                all_past_markets=True)
        assert get_number_of_unmatched_loads(unmatched_loads) == 0
    # (check if number of last slot is the maximal number of slots):
    no_of_slots = int(int(sim_duration) * 60 / int(slot_length))
    assert no_of_slots == context.simulation.area.current_slot
    if scenario == "default":
        street1 = list(
            filter(lambda x: x.name == "Street 1",
                   context.simulation.area.children))[0]
        house1 = list(
            filter(lambda x: x.name == "S1 House 1", street1.children))[0]
        permanent_load = list(
            filter(lambda x: x.name == "S1 H1 Load", house1.children))[0]
        energy_profile = [
            ki
            for ki in permanent_load.strategy.state.desired_energy_Wh.values()
        ]
        assert all(
            [permanent_load.strategy.energy == ei for ei in energy_profile])
Ejemplo n.º 8
0
def no_unmatched_loads(context):
    unmatched, unmatched_redis = \
        ExportUnmatchedLoads(context.simulation.area).get_current_market_results(
            all_past_markets=True)
    assert get_number_of_unmatched_loads(unmatched) == 0