Skip to content

Commit

Permalink
Merge pull request #1338 from gridsingularity/bug/GSYE-73
Browse files Browse the repository at this point in the history
GSYE-73: Use energy buy rate of InfiniteBus as feed-in tariff.
  • Loading branch information
faizan2590 authored Dec 15, 2021
2 parents 8f51e80 + dad5e08 commit d31969d
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 125 deletions.
46 changes: 24 additions & 22 deletions src/gsy_e/gsy_e_core/sim_results/endpoint_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
from pendulum import DateTime

from gsy_e.gsy_e_core.sim_results.offer_bids_trades_hr_stats import OfferBidTradeGraphStats
from gsy_e.gsy_e_core.util import get_market_maker_rate_from_config
from gsy_e.gsy_e_core.util import (
get_market_maker_rate_from_config, get_feed_in_tariff_rate_from_config)
from gsy_e.models.strategy.commercial_producer import CommercialStrategy
from gsy_e.models.strategy.finite_power_plant import FinitePowerPlant
from gsy_e.models.strategy.infinite_bus import InfiniteBusStrategy
from gsy_e.models.strategy.load_hours import LoadHoursStrategy
from gsy_e.models.strategy.market_maker_strategy import MarketMakerStrategy
from gsy_e.models.strategy.pv import PVStrategy
from gsy_e.models.strategy.smart_meter import SmartMeterStrategy
from gsy_e.models.strategy.storage import StorageStrategy
Expand All @@ -48,6 +47,8 @@
}


# pylint: disable=too-many-instance-attributes
# pylint: disable=logging-too-many-args
class SimulationEndpointBuffer:
"""Handles collecting and buffering of all results for all areas."""

Expand Down Expand Up @@ -84,16 +85,16 @@ def prepare_results_for_publish(self) -> Dict:

message_size = get_json_dict_memory_allocation_size(result_report)
if message_size > 64000:
logging.error(f"Do not publish message bigger than 64 MB, "
f"current message size {message_size / 1000.0} MB.")
logging.error("Do not publish message bigger than 64 MB, "
"current message size %s MB.", (message_size / 1000.0))
return {}
logging.debug(f"Publishing {message_size} KB of data via Redis.")
logging.debug("Publishing %s KB of data via Redis.", message_size)
return result_report

@staticmethod
def _structure_results_from_area_object(target_area: "Area") -> Dict:
"""Add basic information about the area in the area_tree_dict."""
area_dict = dict()
area_dict = {}
area_dict["name"] = target_area.name
area_dict["uuid"] = target_area.uuid
area_dict["parent_uuid"] = (target_area.parent.uuid
Expand Down Expand Up @@ -121,7 +122,6 @@ def update_results_area_uuids(self, area: "Area") -> None:

def generate_result_report(self) -> Dict:
"""Create dict that contains all statistics that are sent to the gsy-web."""
# TODO: In D3ASIM-2288, add unix_time=True to convert_pendulum_to_str_in_dict
return {
"job_id": self.job_id,
"current_market": self.current_market_time_slot_str,
Expand Down Expand Up @@ -182,7 +182,8 @@ def _read_future_markets_stats_to_dict(self, area: "Area") -> Dict[str, Dict]:
"market_fee": area.future_markets.market_fee,
"const_fee_rate": (area.future_markets.const_fee_rate
if area.future_markets.const_fee_rate is not None else 0.),
"feed_in_tariff": GlobalConfig.FEED_IN_TARIFF,
"feed_in_tariff": get_feed_in_tariff_rate_from_config(area.future_markets,
time_slot=time_slot),
"market_maker_rate": get_market_maker_rate_from_config(
area.future_markets, time_slot=time_slot)
}
Expand All @@ -203,10 +204,11 @@ def _read_market_stats_to_dict(market: "MarketBase") -> Dict:
stats_dict["market_fee"] = market.market_fee
stats_dict["const_fee_rate"] = (market.const_fee_rate
if market.const_fee_rate is not None else 0.)
stats_dict["feed_in_tariff"] = GlobalConfig.FEED_IN_TARIFF
stats_dict["feed_in_tariff"] = get_feed_in_tariff_rate_from_config(market)
stats_dict["market_maker_rate"] = get_market_maker_rate_from_config(market)
return stats_dict

# pylint: disable=too-many-branches
def _populate_core_stats_and_sim_state(self, area: "Area") -> None:
"""Populate all area statistics and state into self.flattened_area_core_stats_dict and
self.simulation_state."""
Expand Down Expand Up @@ -278,18 +280,18 @@ def _populate_core_stats_and_sim_state(self, area: "Area") -> 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())
elif isinstance(area.strategy, CommercialStrategy):
if isinstance(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())
else:
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

Expand Down
Loading

0 comments on commit d31969d

Please sign in to comment.