def test_get_market_maker_rate_from_config(self): assert get_market_maker_rate_from_config(None, 2) == 2 market = MagicMock() market.time_slot = datetime(year=2019, month=2, day=3) GlobalConfig.market_maker_rate = { datetime(year=2019, month=2, day=3): 321 } assert get_market_maker_rate_from_config(market, None) == 321 GlobalConfig.market_maker_rate = 4321 assert get_market_maker_rate_from_config(market, None) == 4321
def event_market_cycle(self): self._reject_all_pending_requests() self.register_on_market_cycle() if not self.should_use_default_strategy: self.add_entry_in_hrs_per_day() self._calculate_active_markets() self._update_energy_requirement_future_markets() if not self.is_aggregator_controlled: market_event_channel = f"{self.channel_prefix}/events/market" market_info = self.next_market.info if self.is_aggregator_controlled: market_info.update(default_market_info) market_info["device_info"] = self._device_info_dict market_info["event"] = "market" market_info["area_uuid"] = self.device.uuid market_info["device_bill"] = self.device.stats.aggregated_stats["bills"] \ if "bills" in self.device.stats.aggregated_stats else None market_info["last_market_maker_rate"] = \ get_market_maker_rate_from_config(self.area.current_market) market_info["last_market_stats"] = \ self.market_area.stats.get_price_stats_current_market() self.redis.publish_json(market_event_channel, market_info) self._delete_past_state() else: super().event_market_cycle()
def event_market_cycle(self): self._reject_all_pending_requests() self.register_on_market_cycle() if not self.should_use_default_strategy: self.state.market_cycle( self.market_area.current_market.time_slot if self.market_area.current_market else None, self.next_market.time_slot, self.future_markets_time_slots ) self.state.clamp_energy_to_sell_kWh([self.next_market.time_slot]) self.state.clamp_energy_to_buy_kWh([self.next_market.time_slot]) if not self.is_aggregator_controlled: market_event_channel = f"{self.channel_prefix}/events/market" market_info = self.next_market.info if self.is_aggregator_controlled: market_info.update(default_market_info) market_info["device_info"] = self._device_info_dict market_info["event"] = "market" market_info["device_bill"] = self.device.stats.aggregated_stats["bills"] \ if "bills" in self.device.stats.aggregated_stats else None market_info["area_uuid"] = self.device.uuid market_info["last_market_maker_rate"] = ( get_market_maker_rate_from_config(self.area.current_market)) market_info["last_market_stats"] = ( self.market_area.stats.get_price_stats_current_market()) self.redis.publish_json(market_event_channel, market_info) self._delete_past_state() else: super().event_market_cycle()
def event_activate_price(self): # If use_market_maker_rate is true, overwrite initial_selling_rate to market maker rate if self.use_market_maker_rate: self._area_reconfigure_prices( initial_selling_rate=get_market_maker_rate_from_config( self.area.next_market, 0) - self.owner.get_path_to_root_fees(), validate=False) self._validate_rates( self.offer_update.initial_rate_profile_buffer, self.offer_update.final_rate_profile_buffer, self.offer_update.energy_rate_change_per_update_profile_buffer, self.offer_update.fit_to_limit)
def event_market_cycle(self): if self.use_market_maker_rate: self._area_reconfigure_prices( final_buying_rate=get_market_maker_rate_from_config( self.area.next_market, 0) + self.owner.get_path_to_root_fees(), validate=False) super().event_market_cycle() self.add_entry_in_hrs_per_day() self.bid_update.update_and_populate_price_settings(self.area) if ConstSettings.IAASettings.MARKET_TYPE == 1: self.bid_update.reset(self) self._calculate_active_markets() self._update_energy_requirement_future_markets() self._set_alternative_pricing_scheme() self.update_state()
def buffer_market_maker_rate(self): if self.root_area.current_market: self.current_market_maker_rate = get_market_maker_rate_from_config( self.root_area.current_market)
def _populate_core_stats_and_sim_state(self, area): if area.uuid not in self.flattened_area_core_stats_dict: self.flattened_area_core_stats_dict[area.uuid] = {} if self.current_market_time_slot_str == "": return core_stats_dict = { "bids": [], "offers": [], "trades": [], "market_fee": 0.0 } if area.current_market is not None: for offer in area.current_market.offer_history: core_stats_dict["offers"].append(offer.serializable_dict()) for bid in area.current_market.bid_history: core_stats_dict["bids"].append(bid.serializable_dict()) for trade in area.current_market.trades: core_stats_dict["trades"].append(trade.serializable_dict()) core_stats_dict["market_fee"] = area.current_market.market_fee core_stats_dict["const_fee_rate"] = ( area.current_market.const_fee_rate if area.current_market.const_fee_rate is not None else 0.) core_stats_dict["feed_in_tariff"] = GlobalConfig.FEED_IN_TARIFF core_stats_dict[ "market_maker_rate"] = get_market_maker_rate_from_config( area.current_market) if area.strategy is None: core_stats_dict["area_throughput"] = { "baseline_peak_energy_import_kWh": area.throughput.baseline_peak_energy_import_kWh, "baseline_peak_energy_export_kWh": area.throughput.baseline_peak_energy_export_kWh, "import_capacity_kWh": area.throughput.import_capacity_kWh, "export_capacity_kWh": area.throughput.export_capacity_kWh, "imported_energy_kWh": area.stats.imported_traded_energy_kwh.get( area.current_market.time_slot, 0.) if area.current_market is not None else 0., "exported_energy_kWh": area.stats.exported_traded_energy_kwh.get( area.current_market.time_slot, 0.) if area.current_market is not None else 0., } core_stats_dict["grid_fee_constant"] = ( area.current_market.const_fee_rate if area.current_market is not None else 0.) if isinstance(area.strategy, HomeMeterStrategy): core_stats_dict["home_meter_profile_kWh"] = ( area.strategy.state.get_energy_at_market_slot( self.current_market_time_slot)) if area.parent.current_market is not None: for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) elif isinstance(area.strategy, PVStrategy): core_stats_dict["pv_production_kWh"] = ( area.strategy.state.get_energy_production_forecast_kWh( self.current_market_time_slot, 0.0)) core_stats_dict["available_energy_kWh"] = ( area.strategy.state.get_available_energy_kWh( self.current_market_time_slot)) if area.parent.current_market is not None: for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) elif isinstance(area.strategy, StorageStrategy): core_stats_dict["soc_history_%"] = ( area.strategy.state.charge_history.get( self.current_market_time_slot, 0)) if area.parent.current_market is not None: for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) elif isinstance(area.strategy, LoadHoursStrategy): core_stats_dict["load_profile_kWh"] = ( area.strategy.state.get_desired_energy_Wh( self.current_market_time_slot) / 1000.0) core_stats_dict["total_energy_demanded_wh"] = ( area.strategy.state.total_energy_demanded_Wh) core_stats_dict["energy_requirement_kWh"] = ( area.strategy.state.get_energy_requirement_Wh( self.current_market_time_slot) / 1000.0) if area.parent.current_market is not None: for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) elif type(area.strategy) == FinitePowerPlant: core_stats_dict[ "production_kWh"] = area.strategy.energy_per_slot_kWh if area.parent.current_market is not None: for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) elif type(area.strategy) in [ InfiniteBusStrategy, MarketMakerStrategy, CommercialStrategy ]: if area.parent.current_market is not None: core_stats_dict["energy_rate"] = ( area.strategy.energy_rate.get( area.parent.current_market.time_slot, None)) for trade in area.strategy.trades[area.parent.current_market]: core_stats_dict["trades"].append(trade.serializable_dict()) self.flattened_area_core_stats_dict[area.uuid] = core_stats_dict self.simulation_state["areas"][area.uuid] = area.get_state() for child in area.children: self._populate_core_stats_and_sim_state(child)