Skip to content

Commit

Permalink
Merge pull request #1793 from gridsingularity/bug/GSYE-771
Browse files Browse the repository at this point in the history
GSYE-771: Adapt SCMManager to read MMR, FIT and coefficent_percentage…
  • Loading branch information
hannesdiedrich authored Sep 17, 2024
2 parents 2519765 + f725b0e commit 30c1680
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 346 deletions.
70 changes: 40 additions & 30 deletions src/gsy_e/gsy_e_core/area_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@
import json
from logging import getLogger

from gsy_framework.constants_limits import ConstSettings, SpotMarketTypeEnum
from gsy_framework.utils import convert_pendulum_to_str_in_dict, key_in_dict_and_not_none
from gsy_framework.constants_limits import ConstSettings, SpotMarketTypeEnum, GlobalConfig
from pendulum import Duration

from gsy_e.models.area import CoefficientArea, Area, Market, Asset # NOQA
from gsy_e.models.area import CoefficientArea, Area, Market, Asset # NOQA
from gsy_e.models.strategy import BaseStrategy
from gsy_e.models.area.throughput_parameters import ThroughputParameters

from gsy_e.models.strategy.market_maker_strategy import MarketMakerStrategy # NOQA
from gsy_e.models.strategy.commercial_producer import CommercialStrategy # NOQA
from gsy_e.models.strategy.pv import PVStrategy # NOQA
from gsy_e.models.strategy.storage import StorageStrategy # NOQA
from gsy_e.models.strategy.load_hours import LoadHoursStrategy # NOQA
from gsy_e.models.strategy.predefined_load import DefinedLoadStrategy # NOQA
from gsy_e.models.strategy.load_hours import LoadHoursStrategy # NOQA
from gsy_e.models.strategy.predefined_load import DefinedLoadStrategy # NOQA
from gsy_e.models.strategy.predefined_pv import PVPredefinedStrategy, PVUserProfileStrategy # NOQA
from gsy_e.models.strategy.finite_power_plant import FinitePowerPlant # NOQA
from gsy_e.models.strategy.finite_power_plant import FinitePowerPlant # NOQA
from gsy_e.models.strategy.scm import SCMStrategy

from gsy_e.models.leaves import (
Leaf, scm_leaf_mapping, CoefficientLeaf, forward_leaf_mapping) # NOQA
from gsy_e.models.leaves import ( # NOQA
Leaf,
scm_leaf_mapping,
CoefficientLeaf,
forward_leaf_mapping,
)
from gsy_e.models.leaves import * # NOQA # pylint: disable=wildcard-import
from gsy_e.models.strategy.trading_strategy_base import TradingStrategyBase

Expand All @@ -47,6 +51,7 @@

class AreaEncoder(json.JSONEncoder):
"""Convert the Area class hierarchy to json dict."""

def default(self, o):
# Leaf classes are Areas too, therefore the Area/AreaBase classes need to be handled
# separately.
Expand Down Expand Up @@ -86,9 +91,11 @@ def _encode_subobject(obj):

@staticmethod
def _encode_leaf(obj):
description = {"name": obj.name,
"type": obj.__class__.__name__,
"display_type": obj.display_type}
description = {
"name": obj.name,
"type": obj.__class__.__name__,
"display_type": obj.display_type,
}
description.update(obj.parameters)
description = _convert_member_dt_to_string(description)
return description
Expand Down Expand Up @@ -155,8 +162,10 @@ def _leaf_from_dict(description, config):

def area_from_dict(description, config):
"""Create Area tree from JSON dict."""

def optional(attr):
return _instance_from_dict(description[attr]) if attr in description else None

try:
if "type" in description:
return _leaf_from_dict(description, config) # Area is a Leaf
Expand All @@ -174,33 +183,34 @@ def optional(attr):

if ConstSettings.MASettings.MARKET_TYPE == SpotMarketTypeEnum.COEFFICIENTS.value:
# For the SCM only use the CoefficientArea strategy.
area = CoefficientArea(
name, children, uuid, optional("strategy"), config,
coefficient_percentage=description.get("coefficient_percentage", 0.0),
market_maker_rate=description.get(
"market_maker_rate",
ConstSettings.GeneralSettings.DEFAULT_MARKET_MAKER_RATE / 100.),
feed_in_tariff=description.get(
"feed_in_tariff", GlobalConfig.FEED_IN_TARIFF / 100.,))
area = CoefficientArea(name, children, uuid, optional("strategy"), config)
else:
grid_fee_percentage = description.get("grid_fee_percentage", None)
grid_fee_constant = description.get("grid_fee_constant", None)
area = Area(name, children, uuid, optional("strategy"), config,
grid_fee_percentage=grid_fee_percentage,
grid_fee_constant=grid_fee_constant,
external_connection_available=external_connection_available and
config.external_connection_enabled,
throughput=ThroughputParameters(
baseline_peak_energy_import_kWh=baseline_peak_energy_import_kWh,
baseline_peak_energy_export_kWh=baseline_peak_energy_export_kWh,
import_capacity_kVA=import_capacity_kVA,
export_capacity_kVA=export_capacity_kVA))
area = Area(
name,
children,
uuid,
optional("strategy"),
config,
grid_fee_percentage=grid_fee_percentage,
grid_fee_constant=grid_fee_constant,
external_connection_available=external_connection_available
and config.external_connection_enabled,
throughput=ThroughputParameters(
baseline_peak_energy_import_kWh=baseline_peak_energy_import_kWh,
baseline_peak_energy_export_kWh=baseline_peak_energy_export_kWh,
import_capacity_kVA=import_capacity_kVA,
export_capacity_kVA=export_capacity_kVA,
),
)
if "display_type" in description:
area.display_type = description["display_type"]
return area
except (json.JSONDecodeError, KeyError, TypeError, ValueError) as error:
raise ValueError(f"Input is not a valid area description "
f"({error} {description})") from error
raise ValueError(
f"Input is not a valid area description " f"({error} {description})"
) from error


def area_from_string(string, config):
Expand Down
Loading

0 comments on commit 30c1680

Please sign in to comment.