def update_stats(self, area, simulation_status): self.status = simulation_status self.unmatched_loads_redis = { "unmatched_loads": export_unmatched_loads(area) } self.unmatched_loads = { "unmatched_loads": export_unmatched_loads(area, all_devices=True) } self.cumulative_loads = { "price-currency": "Euros", "load-unit": "kWh", "cumulative-load-price": export_cumulative_loads(area) } self.price_energy_day = { "price-currency": "Euros", "load-unit": "kWh", "price-energy-day": export_price_energy_day(area) } self.cumulative_grid_trades_redis = export_cumulative_grid_trades( area, "past_markets") self.cumulative_grid_trades = export_cumulative_grid_trades( area, "past_markets", all_devices=True) self.cumulative_grid_balancing_trades = \ export_cumulative_grid_trades(area, "past_balancing_markets") self.bills = self._update_bills(area, "past_markets") self.balancing_energy_bills = self._update_bills( area, "past_balancing_markets") self._update_tree_summary(area)
def test_export_unmatched_loads_support_the_all_devices_parameter(self): house1 = Area("House1", [self.area1, self.area2]) self.grid = Area("Grid", [house1, self.area3]) self.grid._markets.past_markets = {} for i in range(1, 11): timeslot = DateTime(2018, 1, 1, 12 + i, 0, 0) self.strategy1.state.desired_energy_Wh[timeslot] = 100 self.strategy2.state.desired_energy_Wh[timeslot] = 100 self.strategy3.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, "load3": -0.07 } house1._markets.past_markets[timeslot] = mock_market self.grid._markets.past_markets[timeslot] = mock_market unmatched_loads = export_unmatched_loads(self.grid, all_devices=True) print(unmatched_loads) assert self.area3.name in unmatched_loads["areas"] assert unmatched_loads["areas"][ self.area3.name]["unmatched_load_count"] == 10 assert unmatched_loads["unmatched_load_count"] == 10 assert not unmatched_loads["all_loads_met"]
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 = DateTime(2018, 1, 1, 12 + i, 0, 0) 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 = export_unmatched_loads(self.grid) assert unmatched_loads["unmatched_load_count"] == 30 assert not unmatched_loads["all_loads_met"]
def check_user_rate_profile_dict(context): house = next( filter(lambda x: x.name == "House 1", context.simulation.area.children)) unmatched = export_unmatched_loads(context.simulation.area) number_of_loads = 2 # There are two loads with the same max_energy_rate profile that should report unmatched # energy demand for the first 6 hours of the day: assert unmatched["unmatched_load_count"] == int( number_of_loads * 6. * 60 / house.config.slot_length.minutes)
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 = DateTime(2018, 1, 1, 12 + i, 0, 0) 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 = export_unmatched_loads(self.grid) assert unmatched_loads["unmatched_load_count"] == 20 assert not unmatched_loads["all_loads_met"]
def test_output(context, scenario, duration, slot_length, tick_length): if scenario in ["default_2a", "default_2b", "default_3"]: unmatched = export_unmatched_loads(context.simulation.area) assert unmatched["unmatched_load_count"] == 0 # (check if number of last slot is the maximal number of slots): no_of_slots = (int(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])
def has_unmatched_loads(context): unmatched = export_unmatched_loads(context.simulation.area) assert unmatched["unmatched_load_count"] > 0