Skip to content

Commit

Permalink
move energy components and dto to infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Dec 6, 2024
1 parent 7e44f5d commit 893c27b
Show file tree
Hide file tree
Showing 39 changed files with 105 additions and 85 deletions.
14 changes: 7 additions & 7 deletions src/libecalc/application/energy_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import reduce
from typing import Optional

import libecalc.dto.components
import libecalc.infrastructure.components
from libecalc.application.energy.component_energy_context import ComponentEnergyContext
from libecalc.application.energy.emitter import Emitter
from libecalc.application.energy.energy_model import EnergyModel
Expand All @@ -17,21 +17,21 @@
from libecalc.common.variables import ExpressionEvaluator
from libecalc.core.consumers.consumer_system import ConsumerSystem
from libecalc.core.consumers.factory import create_consumer
from libecalc.core.consumers.generator_set import Genset
from libecalc.core.consumers.legacy_consumer.component import Consumer
from libecalc.core.consumers.legacy_consumer.consumer_function_mapper import EnergyModelMapper
from libecalc.core.models.generator import GeneratorModelSampled
from libecalc.core.result import ComponentResult, EcalcModelResult
from libecalc.core.result.emission import EmissionResult
from libecalc.dto.components import (
from libecalc.infrastructure.components import (
ElectricityConsumer as ElectricityConsumerDTO,
)
from libecalc.dto.components import (
from libecalc.infrastructure.components import (
FuelConsumer as FuelConsumerDTO,
)
from libecalc.dto.components import (
from libecalc.infrastructure.components import (
GeneratorSet as GeneratorSetDTO,
)
from libecalc.infrastructure.energy_components.generator_set.generator_set import Genset
from libecalc.infrastructure.energy_components.legacy_consumer.component import Consumer


class Context(ComponentEnergyContext):
Expand Down Expand Up @@ -133,7 +133,7 @@ def evaluate_energy_usage(self) -> dict[str, EcalcModelResult]:
models=[],
sub_components=[],
)
elif isinstance(energy_component, libecalc.dto.components.ConsumerSystem):
elif isinstance(energy_component, libecalc.infrastructure.components.ConsumerSystem):
evaluated_stream_conditions = energy_component.evaluate_stream_conditions(
expression_evaluator=self._expression_evaluator,
)
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/core/consumers/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .component import BaseConsumer, BaseConsumerWithoutOperationalSettings

2 changes: 1 addition & 1 deletion src/libecalc/core/consumers/compressor/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
TimeSeriesBoolean,
TimeSeriesStreamDayRate,
)
from libecalc.core.consumers.base import BaseConsumerWithoutOperationalSettings
from libecalc.core.models.compressor import CompressorModel
from libecalc.core.result import EcalcModelResult
from libecalc.core.result import results as core_results
from libecalc.domain.stream_conditions import Pressure, StreamConditions
from libecalc.dto.core_specs.compressor.operational_settings import (
CompressorOperationalSettings,
)
from libecalc.infrastructure.energy_components.base import BaseConsumerWithoutOperationalSettings


class Compressor(BaseConsumerWithoutOperationalSettings):
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/core/consumers/consumer_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from libecalc.common.utils.rates import (
TimeSeriesInt,
)
from libecalc.core.consumers.base import BaseConsumerWithoutOperationalSettings
from libecalc.core.result import ComponentResult, ConsumerSystemResult, EcalcModelResult
from libecalc.domain.stream_conditions import Rate, StreamConditions
from libecalc.infrastructure.energy_components.base import BaseConsumerWithoutOperationalSettings

Consumer = TypeVar("Consumer", bound=BaseConsumerWithoutOperationalSettings)

Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/core/consumers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from libecalc.core.consumers.pump import Pump
from libecalc.core.models.compressor import create_compressor_model
from libecalc.core.models.pump import create_pump_model
from libecalc.dto.components import CompressorComponent, PumpComponent
from libecalc.infrastructure.components import CompressorComponent, PumpComponent


@overload
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/core/consumers/pump/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
TimeSeriesFloat,
TimeSeriesStreamDayRate,
)
from libecalc.core.consumers.base import BaseConsumerWithoutOperationalSettings
from libecalc.core.models.pump import PumpModel
from libecalc.core.result import EcalcModelResult
from libecalc.core.result import results as core_results
from libecalc.domain.stream_conditions import Pressure, StreamConditions
from libecalc.dto.core_specs.pump.operational_settings import PumpOperationalSettings
from libecalc.infrastructure.energy_components.base import BaseConsumerWithoutOperationalSettings


class Pump(BaseConsumerWithoutOperationalSettings):
Expand Down
8 changes: 0 additions & 8 deletions src/libecalc/dto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
from libecalc.dto.components import (
Asset,
BaseConsumer,
ElectricityConsumer,
FuelConsumer,
GeneratorSet,
Installation,
)
from libecalc.dto.emission import Emission
from libecalc.dto.fuel_type import FuelType
from libecalc.dto.models import (
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/fixtures/case_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ecalc_cli.infrastructure.file_resource_service import FileResourceService
from libecalc.common.time_utils import Frequency
from libecalc.common.variables import VariablesMap
from libecalc.dto import Asset
from libecalc.infrastructure import Asset
from libecalc.presentation.yaml.file_configuration_service import FileConfigurationService
from libecalc.presentation.yaml.model import YamlModel
from libecalc.presentation.yaml.yaml_entities import MemoryResource
Expand Down
12 changes: 7 additions & 5 deletions src/libecalc/fixtures/cases/consumer_with_time_slots_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
from libecalc.common.time_utils import Period
from libecalc.common.variables import VariablesMap
from libecalc.dto import (
Asset,
CompressorConsumerFunction,
CompressorStage,
CompressorSystemCompressor,
CompressorSystemConsumerFunction,
CompressorSystemOperationalSetting,
DirectConsumerFunction,
ElectricityConsumer,
FuelConsumer,
GeneratorSet,
GeneratorSetSampled,
Installation,
SingleSpeedCompressorTrain,
TabulatedConsumerFunction,
TabulatedData,
Expand All @@ -30,6 +25,13 @@
from libecalc.dto.types import ConsumerUserDefinedCategoryType, InstallationUserDefinedCategoryType
from libecalc.expression import Expression
from libecalc.fixtures.case_types import DTOCase
from libecalc.infrastructure import (
Asset,
ElectricityConsumer,
FuelConsumer,
GeneratorSet,
Installation,
)


def direct_consumer(power: float) -> DirectConsumerFunction:
Expand Down
8 changes: 8 additions & 0 deletions src/libecalc/infrastructure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from libecalc.infrastructure.components import (
Asset,
BaseConsumer,
ElectricityConsumer,
FuelConsumer,
GeneratorSet,
Installation,
)
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .component import BaseConsumer, BaseConsumerWithoutOperationalSettings
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
TimeSeriesStreamDayRate,
)
from libecalc.common.variables import ExpressionEvaluator
from libecalc.core.consumers.base import BaseConsumer
from libecalc.core.consumers.legacy_consumer.consumer_function import (
ConsumerFunction,
ConsumerFunctionResult,
Expand All @@ -40,6 +39,7 @@
PumpResult,
)
from libecalc.expression import Expression
from libecalc.infrastructure.energy_components.base import BaseConsumer


def get_operational_settings_used_from_consumer_result(
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/presentation/exporter/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from libecalc.common.units import Unit
from libecalc.common.utils.rates import TimeSeries, TimeSeriesFloat, TimeSeriesRate, TimeSeriesStreamDayRate
from libecalc.core.result import GeneratorSetResult
from libecalc.dto import FuelConsumer, GeneratorSet
from libecalc.dto.utils.validators import convert_expression
from libecalc.infrastructure.components import FuelConsumer, GeneratorSet
from libecalc.presentation.exporter.domain.exportable import (
Attribute,
AttributeMeta,
Expand Down
3 changes: 2 additions & 1 deletion src/libecalc/presentation/json_result/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from libecalc.core.result.emission import EmissionResult
from libecalc.dto import CompressorSystemConsumerFunction
from libecalc.expression import Expression
from libecalc.infrastructure import components
from libecalc.presentation.json_result.aggregators import (
aggregate_emissions,
aggregate_is_valid,
Expand Down Expand Up @@ -365,7 +366,7 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
asset_id = graph_result.graph.root
asset = graph_result.graph.get_node(asset_id)

if not isinstance(asset, libecalc.dto.Asset):
if not isinstance(asset, components.Asset):
raise ProgrammingError("Need an asset graph to get asset result")

installation_results = _evaluate_installations(
Expand Down
9 changes: 8 additions & 1 deletion src/libecalc/presentation/yaml/mappers/component_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
from libecalc.common.logger import logger
from libecalc.common.time_utils import Period, define_time_model_for_period
from libecalc.dto import ConsumerFunction, FuelType
from libecalc.dto.components import Asset, Consumer, ElectricityConsumer, FuelConsumer, GeneratorSet, Installation
from libecalc.dto.utils.validators import convert_expression
from libecalc.expression import Expression
from libecalc.infrastructure.components import (
Asset,
Consumer,
ElectricityConsumer,
FuelConsumer,
GeneratorSet,
Installation,
)
from libecalc.presentation.yaml.domain.reference_service import InvalidReferenceException, ReferenceService
from libecalc.presentation.yaml.mappers.consumer_function_mapper import (
ConsumerFunctionMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from libecalc.common.consumption_type import ConsumptionType
from libecalc.common.time_utils import Period, define_time_model_for_period
from libecalc.dto import FuelType
from libecalc.dto.components import ConsumerSystem, Crossover, SystemComponentConditions
from libecalc.expression import Expression
from libecalc.infrastructure.components import ConsumerSystem, Crossover, SystemComponentConditions
from libecalc.presentation.yaml.domain.reference_service import ReferenceService
from libecalc.presentation.yaml.yaml_types.components.system.yaml_system_component_conditions import (
YamlSystemComponentConditions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from libecalc.common.component_type import ComponentType
from libecalc.common.consumption_type import ConsumptionType
from libecalc.common.time_utils import Period
from libecalc.dto.components import Stream, TrainComponent
from libecalc.expression import Expression
from libecalc.infrastructure.components import Stream, TrainComponent
from libecalc.presentation.yaml.domain.reference_service import ReferenceService
from libecalc.presentation.yaml.yaml_types.components.yaml_base import YamlConsumerBase
from libecalc.presentation.yaml.yaml_types.components.yaml_compressor import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from libecalc.common.consumption_type import ConsumptionType
from libecalc.common.time_utils import Period, define_time_model_for_period
from libecalc.dto import FuelType
from libecalc.dto.components import CompressorComponent
from libecalc.expression import Expression
from libecalc.infrastructure.components import CompressorComponent
from libecalc.presentation.yaml.domain.reference_service import ReferenceService
from libecalc.presentation.yaml.yaml_types.components.yaml_base import (
YamlConsumerBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from libecalc.common.consumption_type import ConsumptionType
from libecalc.common.time_utils import Period, define_time_model_for_period
from libecalc.dto import FuelType
from libecalc.dto.components import PumpComponent
from libecalc.expression import Expression
from libecalc.infrastructure.components import PumpComponent
from libecalc.presentation.yaml.domain.reference_service import ReferenceService
from libecalc.presentation.yaml.yaml_types.components.yaml_base import (
YamlConsumerBase,
Expand Down
17 changes: 9 additions & 8 deletions tests/libecalc/core/consumers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import libecalc.common.energy_usage_type
from libecalc import dto
from libecalc.infrastructure import components
from libecalc.common.component_type import ComponentType
from libecalc.common.time_utils import Period
from libecalc.common.utils.rates import RateType
Expand All @@ -30,7 +31,7 @@ def variables_map(methane_values):


@pytest.fixture
def tabulated_fuel_consumer(fuel_gas) -> dto.FuelConsumer:
def tabulated_fuel_consumer(fuel_gas) -> components.FuelConsumer:
tabulated = dto.TabulatedConsumerFunction(
model=dto.TabulatedData(
headers=["RATE", "FUEL"],
Expand All @@ -41,7 +42,7 @@ def tabulated_fuel_consumer(fuel_gas) -> dto.FuelConsumer:
variables=[dto.Variables(name="RATE", expression=Expression.setup_from_expression(value="RATE"))],
energy_usage_type=libecalc.common.energy_usage_type.EnergyUsageType.FUEL,
)
return dto.FuelConsumer(
return components.FuelConsumer(
name="fuel_consumer",
component_type=ComponentType.GENERIC,
fuel=fuel_gas,
Expand All @@ -52,8 +53,8 @@ def tabulated_fuel_consumer(fuel_gas) -> dto.FuelConsumer:


@pytest.fixture
def direct_el_consumer() -> dto.ElectricityConsumer:
return dto.ElectricityConsumer(
def direct_el_consumer() -> components.ElectricityConsumer:
return components.ElectricityConsumer(
name="direct_consumer",
component_type=ComponentType.GENERIC,
user_defined_category={Period(datetime(1900, 1, 1)): "FIXED-PRODUCTION-LOAD"},
Expand Down Expand Up @@ -104,8 +105,8 @@ def generator_set_sampled_model_1000mw() -> dto.GeneratorSetSampled:


@pytest.fixture
def genset_2mw_dto(fuel_dto, direct_el_consumer, generator_set_sampled_model_2mw) -> dto.GeneratorSet:
return dto.GeneratorSet(
def genset_2mw_dto(fuel_dto, direct_el_consumer, generator_set_sampled_model_2mw) -> components.GeneratorSet:
return components.GeneratorSet(
name="genset",
user_defined_category={Period(datetime(1900, 1, 1)): "TURBINE-GENERATOR"},
fuel={Period(datetime(1900, 1, 1)): fuel_dto},
Expand All @@ -120,8 +121,8 @@ def genset_2mw_dto(fuel_dto, direct_el_consumer, generator_set_sampled_model_2mw
@pytest.fixture
def genset_1000mw_late_startup_dto(
fuel_dto, direct_el_consumer, generator_set_sampled_model_1000mw
) -> dto.GeneratorSet:
return dto.GeneratorSet(
) -> components.GeneratorSet:
return components.GeneratorSet(
name="genset_late_startup",
user_defined_category={Period(datetime(1900, 1, 1)): "TURBINE-GENERATOR"},
fuel={Period(datetime(1900, 1, 1)): fuel_dto},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from libecalc.common.temporal_model import TemporalModel
from libecalc.common.time_utils import Period
from libecalc.common.variables import VariablesMap
from libecalc.core.consumers.legacy_consumer.component import Consumer
from libecalc.infrastructure.energy_components.legacy_consumer.component import Consumer
from libecalc.core.consumers.legacy_consumer.consumer_function.direct_expression_consumer_function import (
DirectExpressionConsumerFunction,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/libecalc/core/consumers/test_consumer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from libecalc.core.consumers.legacy_consumer.consumer_function.utils import (
apply_condition,
)
from libecalc.dto.components import Crossover
from libecalc.infrastructure.components import Crossover


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion tests/libecalc/core/consumers/test_genset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TimeSeriesStreamDayRate,
)
from libecalc.common.variables import VariablesMap
from libecalc.core.consumers.generator_set import Genset
from libecalc.infrastructure.energy_components.generator_set.generator_set import Genset
from libecalc.core.models.generator import GeneratorModelSampled
from libecalc.core.result.results import GenericComponentResult

Expand Down
2 changes: 1 addition & 1 deletion tests/libecalc/core/consumers/test_legacy_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TimeSeriesStreamDayRate,
)
from libecalc.common.variables import VariablesMap
from libecalc.core.consumers.legacy_consumer.component import Consumer
from libecalc.infrastructure.energy_components.legacy_consumer.component import Consumer
from libecalc.core.consumers.legacy_consumer.consumer_function import (
ConsumerFunctionResult,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/libecalc/core/models/test_fuel_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from libecalc.common.units import Unit
from libecalc.common.utils.rates import RateType, TimeSeriesRate
from libecalc.common.variables import VariablesMap
from libecalc.dto.components import FuelModel
from libecalc.infrastructure.components import FuelModel
from libecalc.expression import Expression


Expand Down
5 changes: 3 additions & 2 deletions tests/libecalc/dto/test_electricity_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pydantic import ValidationError

from libecalc import dto
from libecalc.infrastructure import components
from libecalc.common.component_type import ComponentType
from libecalc.common.energy_usage_type import EnergyUsageType
from libecalc.common.time_utils import Period
Expand All @@ -13,7 +14,7 @@
class TestElectricityConsumer:
def test_invalid_energy_usage(self):
with pytest.raises(ValidationError) as e:
dto.ElectricityConsumer(
components.ElectricityConsumer(
name="Test",
component_type=ComponentType.GENERIC,
user_defined_category={Period(datetime(1900, 1, 1)): "MISCELLANEOUS"},
Expand All @@ -28,7 +29,7 @@ def test_invalid_energy_usage(self):

def test_valid_electricity_consumer(self):
# Should not raise ValidationError
dto.ElectricityConsumer(
components.ElectricityConsumer(
name="Test",
component_type=ComponentType.GENERIC,
user_defined_category={Period(datetime(1900, 1, 1)): "MISCELLANEOUS"},
Expand Down
Loading

0 comments on commit 893c27b

Please sign in to comment.