Exemplo n.º 1
0
    def __init__(self,
                 name: str = None,
                 children: List["Area"] = None,
                 strategy: BaseStrategy = None,
                 appliance: BaseAppliance = None,
                 config: SimulationConfig = None,
                 budget_keeper=None,
                 balancing_spot_trade_ratio=ConstSettings.BalancingSettings.
                 SPOT_TRADE_RATIO):
        self.balancing_spot_trade_ratio = balancing_spot_trade_ratio
        self.active = False
        self.log = TaggedLogWrapper(log, name)
        self.current_tick = 0
        self.name = name
        self.slug = slugify(name, to_lower=True)
        self.area_id = Area._area_id_counter
        Area._area_id_counter += 1
        self.parent = None
        self.children = children if children is not None else []
        for child in self.children:
            child.parent = self
        self.strategy = strategy
        self.appliance = appliance
        self._config = config

        self.budget_keeper = budget_keeper
        if budget_keeper:
            self.budget_keeper.area = self
        self._bc = None  # type: BlockChainInterface
        self._markets = AreaMarkets(self.log)
        self.stats = AreaStats(self._markets)
        self.dispatcher = AreaDispatcher(self)
Exemplo n.º 2
0
    def setUp(self):
        ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True
        DeviceRegistry.REGISTRY = {
            "H1 General Load": (33, 35),
            "H2 General Load": (33, 35),
            "H1 Storage1": (23, 25),
            "H1 Storage2": (23, 25),
        }

        self.appliance = MagicMock(spec=SimpleAppliance)
        self.strategy = MagicMock(spec=StorageStrategy)
        self.config = MagicMock(spec=SimulationConfig)
        self.config.slot_length = duration(minutes=15)
        self.config.tick_length = duration(seconds=15)
        self.config.start_date = today(tz=TIME_ZONE)
        self.config.sim_duration = duration(days=1)
        self.area = Area("test_area",
                         None,
                         None,
                         self.strategy,
                         self.appliance,
                         self.config,
                         None,
                         transfer_fee_pct=1)
        self.area.parent = self.area
        self.area.children = [self.area]
        self.area.transfer_fee_pct = 1
        self.dispatcher = AreaDispatcher(self.area)
        self.stats = AreaStats(self.area._markets)
Exemplo n.º 3
0
    def __init__(self, name: str = None, children: List["Area"] = None,
                 uuid: str = None,
                 strategy: BaseStrategy = None,
                 config: SimulationConfig = None,
                 budget_keeper=None,
                 balancing_spot_trade_ratio=ConstSettings.BalancingSettings.SPOT_TRADE_RATIO,
                 event_list=[],
                 grid_fee_percentage: float = None,
                 grid_fee_constant: float = None,
                 external_connection_available: bool = False,
                 throughput: ThroughputParameters = ThroughputParameters()
                 ):
        validate_area(grid_fee_constant=grid_fee_constant,
                      grid_fee_percentage=grid_fee_percentage)
        self.balancing_spot_trade_ratio = balancing_spot_trade_ratio
        self.active = False
        self.log = TaggedLogWrapper(log, name)
        self.current_tick = 0
        self.__name = name
        self.throughput = throughput
        self.uuid = uuid if uuid is not None else str(uuid4())
        self.slug = slugify(name, to_lower=True)
        self.parent = None
        self.children = AreaChildrenList(self, children) if children is not None\
            else AreaChildrenList(self)
        for child in self.children:
            child.parent = self

        if (len(self.children) > 0) and (strategy is not None):
            raise AreaException("A leaf area can not have children.")
        self.strategy = strategy
        self._config = config
        self.events = Events(event_list, self)
        self.budget_keeper = budget_keeper
        if budget_keeper:
            self.budget_keeper.area = self
        self._bc = None
        self._markets = None
        self.dispatcher = DispatcherFactory(self)()
        self._set_grid_fees(grid_fee_constant, grid_fee_percentage)
        self.display_type = "Area" if self.strategy is None else self.strategy.__class__.__name__
        self._markets = AreaMarkets(self.log)
        self.stats = AreaStats(self._markets, self)
        log.debug("External connection %s for area %s", external_connection_available, self.name)
        self.redis_ext_conn = RedisMarketExternalConnection(self) \
            if external_connection_available and self.strategy is None else None
        self.should_update_child_strategies = False
        self.external_connection_available = external_connection_available
Exemplo n.º 4
0
Arquivo: __init__.py Projeto: xg86/d3a
    def __init__(self,
                 name: str = None,
                 children: List["Area"] = None,
                 uuid: str = None,
                 strategy: BaseStrategy = None,
                 appliance: BaseAppliance = None,
                 config: SimulationConfig = None,
                 budget_keeper=None,
                 balancing_spot_trade_ratio=ConstSettings.BalancingSettings.
                 SPOT_TRADE_RATIO,
                 event_list=[],
                 grid_fee_percentage: float = None,
                 transfer_fee_const: float = None,
                 external_connection_available=False):
        validate_area(grid_fee_percentage=grid_fee_percentage)
        self.balancing_spot_trade_ratio = balancing_spot_trade_ratio
        self.active = False
        self.log = TaggedLogWrapper(log, name)
        self.current_tick = 0
        self.name = name
        self.uuid = uuid if uuid is not None else str(uuid4())
        self.slug = slugify(name, to_lower=True)
        self.parent = None
        self.children = children if children is not None else []
        for child in self.children:
            child.parent = self

        if (len(self.children) > 0) and (strategy is not None):
            raise AreaException("A leaf area can not have children.")
        self.strategy = strategy
        self.appliance = appliance
        self._config = config
        self.events = Events(event_list, self)
        self.budget_keeper = budget_keeper
        if budget_keeper:
            self.budget_keeper.area = self
        self._bc = None
        self._markets = None
        self.dispatcher = DispatcherFactory(self)()
        self.grid_fee_percentage = grid_fee_percentage
        self.transfer_fee_const = transfer_fee_const
        self.display_type = "Area" if self.strategy is None else self.strategy.__class__.__name__
        self._markets = AreaMarkets(self.log)
        self.stats = AreaStats(self._markets)
        self.redis_ext_conn = RedisAreaExternalConnection(self) \
            if external_connection_available is True else None
Exemplo n.º 5
0
    def setUp(self):
        ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = True
        DeviceRegistry.REGISTRY = {
            "H1 General Load": (33, 35),
            "H2 General Load": (33, 35),
            "H1 Storage1": (23, 25),
            "H1 Storage2": (23, 25),
        }

        self.strategy = MagicMock(spec=StorageStrategy)
        self.config = MagicMock(spec=SimulationConfig)
        self.config.slot_length = duration(minutes=15)
        self.config.tick_length = duration(seconds=15)
        self.config.ticks_per_slot = int(self.config.slot_length.seconds /
                                         self.config.tick_length.seconds)
        self.config.start_date = today(tz=constants.TIME_ZONE)
        GlobalConfig.sim_duration = duration(days=1)
        self.config.sim_duration = duration(days=1)
        self.config.grid_fee_type = 1
        self.config.end_date = self.config.start_date + self.config.sim_duration
        self.area = Area("test_area",
                         None,
                         None,
                         self.strategy,
                         self.config,
                         None,
                         grid_fee_percentage=1)
        self.area_child = Area("test_area_c",
                               None,
                               None,
                               self.strategy,
                               self.config,
                               None,
                               grid_fee_percentage=1)
        self.area_child.parent = self.area
        self.area.children = [self.area_child]
        self.area.grid_fee_percentage = 1
        self.dispatcher = AreaDispatcher(self.area)
        self.stats = AreaStats(self.area._markets, self.area)
Exemplo n.º 6
0
    def __init__(self,
                 name: str = None,
                 children: List["Area"] = None,
                 uuid: str = None,
                 strategy: BaseStrategy = None,
                 appliance: BaseAppliance = None,
                 config: SimulationConfig = None,
                 budget_keeper=None,
                 balancing_spot_trade_ratio=ConstSettings.BalancingSettings.
                 SPOT_TRADE_RATIO,
                 event_list=[],
                 grid_fee_percentage: float = None,
                 transfer_fee_const: float = None,
                 external_connection_available: bool = False,
                 baseline_peak_energy_import_kWh: float = None,
                 baseline_peak_energy_export_kWh: float = None,
                 import_capacity_kVA: float = None,
                 export_capacity_kVA: float = None):
        validate_area(
            grid_fee_constant=transfer_fee_const,
            grid_fee_percentage=grid_fee_percentage,
            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)
        self.balancing_spot_trade_ratio = balancing_spot_trade_ratio
        self.active = False
        self.log = TaggedLogWrapper(log, name)
        self.current_tick = 0
        self.name = name
        self.baseline_peak_energy_import_kWh = baseline_peak_energy_import_kWh
        self.baseline_peak_energy_export_kWh = baseline_peak_energy_export_kWh
        self.uuid = uuid if uuid is not None else str(uuid4())
        self.slug = slugify(name, to_lower=True)
        self.parent = None
        self.children = children if children is not None else []
        for child in self.children:
            child.parent = self

        if (len(self.children) > 0) and (strategy is not None):
            raise AreaException("A leaf area can not have children.")
        self.strategy = strategy
        self.appliance = appliance
        self._config = config
        self.events = Events(event_list, self)
        self.budget_keeper = budget_keeper
        if budget_keeper:
            self.budget_keeper.area = self
        self._bc = None
        self._markets = None
        self.dispatcher = DispatcherFactory(self)()
        self._set_grid_fees(transfer_fee_const, grid_fee_percentage)
        self._convert_area_throughput_kva_to_kwh(import_capacity_kVA,
                                                 export_capacity_kVA)
        self.display_type = "Area" if self.strategy is None else self.strategy.__class__.__name__
        self._markets = AreaMarkets(self.log)
        self.endpoint_stats = {}
        self.stats = AreaStats(self._markets)
        log.debug(
            f"External connection {external_connection_available} for area {self.name}"
        )
        self.redis_ext_conn = RedisMarketExternalConnection(self) \
            if external_connection_available is True else None