diff --git a/src/libecalc/application/energy_calculator.py b/src/libecalc/application/energy_calculator.py index 0302db4296..1e33504316 100644 --- a/src/libecalc/application/energy_calculator.py +++ b/src/libecalc/application/energy_calculator.py @@ -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 @@ -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): @@ -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, ) diff --git a/src/libecalc/core/consumers/base/__init__.py b/src/libecalc/core/consumers/base/__init__.py index 41e4f9a886..8b13789179 100644 --- a/src/libecalc/core/consumers/base/__init__.py +++ b/src/libecalc/core/consumers/base/__init__.py @@ -1 +1 @@ -from .component import BaseConsumer, BaseConsumerWithoutOperationalSettings + diff --git a/src/libecalc/core/consumers/compressor/component.py b/src/libecalc/core/consumers/compressor/component.py index 4e66567dab..d56179e3ec 100644 --- a/src/libecalc/core/consumers/compressor/component.py +++ b/src/libecalc/core/consumers/compressor/component.py @@ -11,7 +11,6 @@ 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 @@ -19,6 +18,7 @@ from libecalc.dto.core_specs.compressor.operational_settings import ( CompressorOperationalSettings, ) +from libecalc.infrastructure.energy_components.base import BaseConsumerWithoutOperationalSettings class Compressor(BaseConsumerWithoutOperationalSettings): diff --git a/src/libecalc/core/consumers/consumer_system.py b/src/libecalc/core/consumers/consumer_system.py index 8cc5ed5f64..23905d14ee 100644 --- a/src/libecalc/core/consumers/consumer_system.py +++ b/src/libecalc/core/consumers/consumer_system.py @@ -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) diff --git a/src/libecalc/core/consumers/factory.py b/src/libecalc/core/consumers/factory.py index 036ae9ccb8..36c3bbdd5a 100644 --- a/src/libecalc/core/consumers/factory.py +++ b/src/libecalc/core/consumers/factory.py @@ -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 diff --git a/src/libecalc/core/consumers/pump/component.py b/src/libecalc/core/consumers/pump/component.py index e64e1f4296..eca10a8ff7 100644 --- a/src/libecalc/core/consumers/pump/component.py +++ b/src/libecalc/core/consumers/pump/component.py @@ -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): diff --git a/src/libecalc/dto/__init__.py b/src/libecalc/dto/__init__.py index c35778cce7..d845d38131 100644 --- a/src/libecalc/dto/__init__.py +++ b/src/libecalc/dto/__init__.py @@ -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 ( diff --git a/src/libecalc/fixtures/case_types.py b/src/libecalc/fixtures/case_types.py index f72075f48b..7edff6081d 100644 --- a/src/libecalc/fixtures/case_types.py +++ b/src/libecalc/fixtures/case_types.py @@ -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 diff --git a/src/libecalc/fixtures/cases/consumer_with_time_slots_models.py b/src/libecalc/fixtures/cases/consumer_with_time_slots_models.py index d972959d4d..1acf33af92 100644 --- a/src/libecalc/fixtures/cases/consumer_with_time_slots_models.py +++ b/src/libecalc/fixtures/cases/consumer_with_time_slots_models.py @@ -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, @@ -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: diff --git a/src/libecalc/infrastructure/__init__.py b/src/libecalc/infrastructure/__init__.py index e69de29bb2..a751d83a1e 100644 --- a/src/libecalc/infrastructure/__init__.py +++ b/src/libecalc/infrastructure/__init__.py @@ -0,0 +1,8 @@ +from libecalc.infrastructure.components import ( + Asset, + BaseConsumer, + ElectricityConsumer, + FuelConsumer, + GeneratorSet, + Installation, +) diff --git a/src/libecalc/dto/components.py b/src/libecalc/infrastructure/components.py similarity index 100% rename from src/libecalc/dto/components.py rename to src/libecalc/infrastructure/components.py diff --git a/src/libecalc/infrastructure/energy_components/__init__.py b/src/libecalc/infrastructure/energy_components/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/libecalc/infrastructure/energy_components/base/__init__.py b/src/libecalc/infrastructure/energy_components/base/__init__.py new file mode 100644 index 0000000000..41e4f9a886 --- /dev/null +++ b/src/libecalc/infrastructure/energy_components/base/__init__.py @@ -0,0 +1 @@ +from .component import BaseConsumer, BaseConsumerWithoutOperationalSettings diff --git a/src/libecalc/core/consumers/base/component.py b/src/libecalc/infrastructure/energy_components/base/component.py similarity index 100% rename from src/libecalc/core/consumers/base/component.py rename to src/libecalc/infrastructure/energy_components/base/component.py diff --git a/src/libecalc/infrastructure/energy_components/generator_set/__init__.py b/src/libecalc/infrastructure/energy_components/generator_set/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/libecalc/core/consumers/generator_set.py b/src/libecalc/infrastructure/energy_components/generator_set/generator_set.py similarity index 100% rename from src/libecalc/core/consumers/generator_set.py rename to src/libecalc/infrastructure/energy_components/generator_set/generator_set.py diff --git a/src/libecalc/infrastructure/energy_components/legacy_consumer/__init__.py b/src/libecalc/infrastructure/energy_components/legacy_consumer/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/libecalc/core/consumers/legacy_consumer/component.py b/src/libecalc/infrastructure/energy_components/legacy_consumer/component.py similarity index 99% rename from src/libecalc/core/consumers/legacy_consumer/component.py rename to src/libecalc/infrastructure/energy_components/legacy_consumer/component.py index 0f3cc63f72..ad899c3513 100644 --- a/src/libecalc/core/consumers/legacy_consumer/component.py +++ b/src/libecalc/infrastructure/energy_components/legacy_consumer/component.py @@ -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, @@ -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( diff --git a/src/libecalc/presentation/exporter/infrastructure.py b/src/libecalc/presentation/exporter/infrastructure.py index bd03c48bea..5ca627866a 100644 --- a/src/libecalc/presentation/exporter/infrastructure.py +++ b/src/libecalc/presentation/exporter/infrastructure.py @@ -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, diff --git a/src/libecalc/presentation/json_result/mapper.py b/src/libecalc/presentation/json_result/mapper.py index 06f8ea0099..ee67a622e7 100644 --- a/src/libecalc/presentation/json_result/mapper.py +++ b/src/libecalc/presentation/json_result/mapper.py @@ -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, @@ -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( diff --git a/src/libecalc/presentation/yaml/mappers/component_mapper.py b/src/libecalc/presentation/yaml/mappers/component_mapper.py index 57fe12426e..7efbf91b53 100644 --- a/src/libecalc/presentation/yaml/mappers/component_mapper.py +++ b/src/libecalc/presentation/yaml/mappers/component_mapper.py @@ -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, diff --git a/src/libecalc/presentation/yaml/yaml_types/components/system/yaml_consumer_system.py b/src/libecalc/presentation/yaml/yaml_types/components/system/yaml_consumer_system.py index a4b318ec1b..c0d375f19f 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/system/yaml_consumer_system.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/system/yaml_consumer_system.py @@ -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, diff --git a/src/libecalc/presentation/yaml/yaml_types/components/train/yaml_train.py b/src/libecalc/presentation/yaml/yaml_types/components/train/yaml_train.py index 75b9f6fe2d..30db832232 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/train/yaml_train.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/train/yaml_train.py @@ -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 ( diff --git a/src/libecalc/presentation/yaml/yaml_types/components/yaml_compressor.py b/src/libecalc/presentation/yaml/yaml_types/components/yaml_compressor.py index 54f2b9c1e4..67347d7282 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/yaml_compressor.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/yaml_compressor.py @@ -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, diff --git a/src/libecalc/presentation/yaml/yaml_types/components/yaml_pump.py b/src/libecalc/presentation/yaml/yaml_types/components/yaml_pump.py index f25a730de0..8855b4b792 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/yaml_pump.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/yaml_pump.py @@ -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, diff --git a/tests/libecalc/core/consumers/conftest.py b/tests/libecalc/core/consumers/conftest.py index 8e92d6a0fc..c678db6d49 100644 --- a/tests/libecalc/core/consumers/conftest.py +++ b/tests/libecalc/core/consumers/conftest.py @@ -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 @@ -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"], @@ -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, @@ -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"}, @@ -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}, @@ -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}, diff --git a/tests/libecalc/core/consumers/consumer_function/test_direct_expression_consumer_function.py b/tests/libecalc/core/consumers/consumer_function/test_direct_expression_consumer_function.py index 3e8459a1ee..d0ec33441c 100644 --- a/tests/libecalc/core/consumers/consumer_function/test_direct_expression_consumer_function.py +++ b/tests/libecalc/core/consumers/consumer_function/test_direct_expression_consumer_function.py @@ -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, ) diff --git a/tests/libecalc/core/consumers/test_consumer_utils.py b/tests/libecalc/core/consumers/test_consumer_utils.py index 7083ffa74c..8d29579e84 100644 --- a/tests/libecalc/core/consumers/test_consumer_utils.py +++ b/tests/libecalc/core/consumers/test_consumer_utils.py @@ -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 diff --git a/tests/libecalc/core/consumers/test_genset.py b/tests/libecalc/core/consumers/test_genset.py index c9f60f88b9..bdc29c9917 100644 --- a/tests/libecalc/core/consumers/test_genset.py +++ b/tests/libecalc/core/consumers/test_genset.py @@ -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 diff --git a/tests/libecalc/core/consumers/test_legacy_consumer.py b/tests/libecalc/core/consumers/test_legacy_consumer.py index 27c2467405..a6bfe9cdf8 100644 --- a/tests/libecalc/core/consumers/test_legacy_consumer.py +++ b/tests/libecalc/core/consumers/test_legacy_consumer.py @@ -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, ) diff --git a/tests/libecalc/core/models/test_fuel_model.py b/tests/libecalc/core/models/test_fuel_model.py index 167c7ea4eb..8ca9f4d6c0 100644 --- a/tests/libecalc/core/models/test_fuel_model.py +++ b/tests/libecalc/core/models/test_fuel_model.py @@ -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 diff --git a/tests/libecalc/dto/test_electricity_consumer.py b/tests/libecalc/dto/test_electricity_consumer.py index b5c9ab7e9d..eea5869517 100644 --- a/tests/libecalc/dto/test_electricity_consumer.py +++ b/tests/libecalc/dto/test_electricity_consumer.py @@ -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 @@ -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"}, @@ -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"}, diff --git a/tests/libecalc/dto/test_fuel_consumer.py b/tests/libecalc/dto/test_fuel_consumer.py index fed16853b5..fce3e600d6 100644 --- a/tests/libecalc/dto/test_fuel_consumer.py +++ b/tests/libecalc/dto/test_fuel_consumer.py @@ -6,6 +6,7 @@ import libecalc.dto.fuel_type import libecalc.dto.types 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 @@ -39,7 +40,7 @@ def get_fuel(fuel_name: str, emission_name: str) -> dict[Period, libecalc.dto.fu } -def get_installation(installation_name: str, fuel_consumer: dto.FuelConsumer) -> dto.Installation: +def get_installation(installation_name: str, fuel_consumer: components.FuelConsumer) -> components.Installation: """ Generates an installation dto for use in testing @@ -48,9 +49,9 @@ def get_installation(installation_name: str, fuel_consumer: dto.FuelConsumer) -> fuel_consumer: a fuel consumer object, e.g. a generator, compressor or boiler Returns: - dto.Installation + components.Installation """ - return dto.Installation( + return components.Installation( name=installation_name, regularity=regularity, hydrocarbon_export={Period(datetime(1900, 1, 1)): Expression.setup_from_expression("sim1;var1")}, @@ -63,7 +64,7 @@ def get_fuel_consumer( consumer_name: str, fuel_type: dict[Period, libecalc.dto.fuel_type.FuelType], category: dict[Period, libecalc.dto.types.ConsumerUserDefinedCategoryType], -) -> dto.FuelConsumer: +) -> components.FuelConsumer: """ Generates a fuel consumer dto for use in testing @@ -75,7 +76,7 @@ def get_fuel_consumer( Returns: dto.FuelConsumer """ - return dto.FuelConsumer( + return components.FuelConsumer( name=consumer_name, fuel=fuel_type, component_type=ComponentType.GENERIC, @@ -93,7 +94,7 @@ def get_fuel_consumer( class TestFuelConsumer: def test_missing_fuel(self): with pytest.raises(ValidationError) as exc_info: - dto.FuelConsumer( + components.FuelConsumer( name="test", fuel={}, component_type=ComponentType.GENERIC, @@ -133,7 +134,7 @@ def test_duplicate_fuel_names(self): installation2 = get_installation("INST2", fuel_consumer2) with pytest.raises(ValidationError) as exc_info: - dto.Asset( + components.Asset( name="multiple_installations_asset", installations=[ installation1, @@ -168,7 +169,7 @@ def test_same_fuel(self): installation1 = get_installation("INST1", fuel_consumer1) installation2 = get_installation("INST2", fuel_consumer2) - asset = dto.Asset( + asset = components.Asset( name="multiple_installations_asset", installations=[ installation1, diff --git a/tests/libecalc/dto/test_generator_set.py b/tests/libecalc/dto/test_generator_set.py index 306d1db2f5..c2764dcc57 100644 --- a/tests/libecalc/dto/test_generator_set.py +++ b/tests/libecalc/dto/test_generator_set.py @@ -5,6 +5,7 @@ import libecalc.dto.fuel_type from libecalc import dto +from libecalc.infrastructure import components from libecalc.common.component_type import ComponentType from libecalc.common.consumption_type import ConsumptionType from libecalc.common.energy_model_type import EnergyModelType @@ -39,11 +40,11 @@ def test_invalid_headers(self): class TestGeneratorSet: def test_valid(self): - generator_set_dto = dto.GeneratorSet( + generator_set_dto = components.GeneratorSet( name="Test", user_defined_category={Period(datetime(1900, 1, 1)): "MISCELLANEOUS"}, generator_set_model={ - Period(datetime(1900, 1, 1)): dto.GeneratorSetSampled( + Period(datetime(1900, 1, 1)): components.GeneratorSetSampled( headers=["FUEL", "POWER"], data=[[0, 0], [1, 2], [2, 4], [3, 6]], energy_usage_adjustment_constant=0.0, @@ -73,7 +74,7 @@ def test_genset_should_fail_with_fuel_consumer(self): name="fuel", emissions=[], ) - fuel_consumer = dto.FuelConsumer( + fuel_consumer = components.FuelConsumer( name="test", fuel={Period(datetime(2000, 1, 1)): fuel}, consumes=ConsumptionType.FUEL, @@ -88,7 +89,7 @@ def test_genset_should_fail_with_fuel_consumer(self): user_defined_category={Period(datetime(2000, 1, 1)): ConsumerUserDefinedCategoryType.MISCELLANEOUS}, ) with pytest.raises(ValidationError): - dto.GeneratorSet( + components.GeneratorSet( name="Test", user_defined_category={Period(datetime(1900, 1, 1)): ConsumerUserDefinedCategoryType.MISCELLANEOUS}, generator_set_model={}, @@ -104,7 +105,7 @@ def test_power_from_shore_wrong_category(self): # Check for CABLE_LOSS with pytest.raises(ValueError) as exc_info: - dto.GeneratorSet( + components.GeneratorSet( name="Test", user_defined_category={Period(datetime(1900, 1, 1)): ConsumerUserDefinedCategoryType.BOILER}, generator_set_model={}, @@ -118,7 +119,7 @@ def test_power_from_shore_wrong_category(self): # Check for MAX_USAGE_FROM_SHORE with pytest.raises(ValueError) as exc_info: - dto.GeneratorSet( + components.GeneratorSet( name="Test", user_defined_category={Period(datetime(1900, 1, 1)): ConsumerUserDefinedCategoryType.BOILER}, generator_set_model={}, @@ -133,7 +134,7 @@ def test_power_from_shore_wrong_category(self): ) with pytest.raises(ValueError) as exc_info: - dto.GeneratorSet( + components.GeneratorSet( name="Test", user_defined_category={Period(datetime(1900, 1, 1)): ConsumerUserDefinedCategoryType.BOILER}, generator_set_model={}, diff --git a/tests/libecalc/input/mappers/test_model_mapper.py b/tests/libecalc/input/mappers/test_model_mapper.py index 7585c05d4d..2cd9ffe963 100644 --- a/tests/libecalc/input/mappers/test_model_mapper.py +++ b/tests/libecalc/input/mappers/test_model_mapper.py @@ -5,6 +5,7 @@ from pydantic import TypeAdapter from libecalc import dto +from libecalc.infrastructure import components from libecalc.common.time_utils import Frequency, Period from libecalc.presentation.yaml.mappers.model import ModelMapper from libecalc.presentation.yaml.model import YamlModel @@ -294,7 +295,7 @@ def temporal_model_stream(temporal_model_source: str) -> ResourceStream: @pytest.fixture def temporal_yaml_model_factory(temporal_model_stream, resource_service_factory, configuration_service_factory): - def create_temporal_yaml_model(start: datetime, end: datetime) -> dto.Asset: + def create_temporal_yaml_model(start: datetime, end: datetime) -> components.Asset: period = Period( start=start, end=end, diff --git a/tests/libecalc/integration/test_all_consumer_with_time_slots_models.py b/tests/libecalc/integration/test_all_consumer_with_time_slots_models.py index ae7f4cdb46..3cca4a61b7 100644 --- a/tests/libecalc/integration/test_all_consumer_with_time_slots_models.py +++ b/tests/libecalc/integration/test_all_consumer_with_time_slots_models.py @@ -9,7 +9,7 @@ from libecalc.common.temporal_model import TemporalModel from libecalc.common.time_utils import Period, Periods 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_mapper import EnergyModelMapper from libecalc.core.result import CompressorModelResult, GenericModelResult diff --git a/tests/libecalc/output/flow_diagram/conftest.py b/tests/libecalc/output/flow_diagram/conftest.py index 9cd36e0f95..17d85a6670 100644 --- a/tests/libecalc/output/flow_diagram/conftest.py +++ b/tests/libecalc/output/flow_diagram/conftest.py @@ -5,6 +5,7 @@ import libecalc.common.energy_usage_type import libecalc.dto.fuel_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.expression import Expression @@ -58,8 +59,8 @@ def fuel_type_fd() -> libecalc.dto.fuel_type.FuelType: @pytest.fixture -def compressor_system_consumer_dto_fd(fuel_type_fd) -> dto.FuelConsumer: - return dto.FuelConsumer( +def compressor_system_consumer_dto_fd(fuel_type_fd) -> components.FuelConsumer: + return components.FuelConsumer( name="Compressor system 1", component_type=ComponentType.COMPRESSOR_SYSTEM, user_defined_category={Period(datetime.datetime(1900, 1, 1), datetime.datetime(2021, 1, 1)): "COMPRESSOR"}, @@ -142,8 +143,8 @@ def compressor_system_consumer_dto_fd(fuel_type_fd) -> dto.FuelConsumer: @pytest.fixture -def compressor_consumer_dto_fd(fuel_type_fd) -> dto.FuelConsumer: - return dto.FuelConsumer( +def compressor_consumer_dto_fd(fuel_type_fd) -> components.FuelConsumer: + return components.FuelConsumer( name="Compressor 1", component_type=ComponentType.GENERIC, user_defined_category={Period(datetime.datetime(1900, 1, 1), datetime.datetime(2021, 1, 1)): "COMPRESSOR"}, @@ -162,13 +163,13 @@ def compressor_consumer_dto_fd(fuel_type_fd) -> dto.FuelConsumer: @pytest.fixture def installation_with_dates_dto_fd( - compressor_system_consumer_dto_fd: dto.FuelConsumer, - compressor_consumer_dto_fd: dto.FuelConsumer, -) -> dto.Asset: - return dto.Asset( + compressor_system_consumer_dto_fd: components.FuelConsumer, + compressor_consumer_dto_fd: components.FuelConsumer, +) -> components.Asset: + return components.Asset( name="installation_with_dates", installations=[ - dto.Installation( + components.Installation( name="Installation1", fuel_consumers=[compressor_system_consumer_dto_fd, compressor_consumer_dto_fd], regularity={ diff --git a/tests/libecalc/output/flow_diagram/test_ecalc_model_mapper.py b/tests/libecalc/output/flow_diagram/test_ecalc_model_mapper.py index ee67cce600..d45b78757b 100644 --- a/tests/libecalc/output/flow_diagram/test_ecalc_model_mapper.py +++ b/tests/libecalc/output/flow_diagram/test_ecalc_model_mapper.py @@ -3,7 +3,7 @@ import pytest -from libecalc import dto +from libecalc.infrastructure import components from libecalc.fixtures import YamlCase from libecalc.presentation.flow_diagram.energy_model_flow_diagram import ( EnergyModelFlowDiagram, @@ -32,7 +32,9 @@ def test_all_energy_usage_models(self, all_energy_usage_models_yaml: YamlCase, s assert first_subdiagram.end_date == datetime(2021, 1, 1) @pytest.mark.snapshot - def test_case_with_dates(self, installation_with_dates_dto_fd: dto.Asset, snapshot, energy_model_from_dto_factory): + def test_case_with_dates( + self, installation_with_dates_dto_fd: components.Asset, snapshot, energy_model_from_dto_factory + ): model = energy_model_from_dto_factory(installation_with_dates_dto_fd) actual_fd = EnergyModelFlowDiagram( energy_model=model, model_period=list(installation_with_dates_dto_fd.installations[0].regularity.keys())[0] diff --git a/tests/libecalc/presentation/json_result/test_aggregators.py b/tests/libecalc/presentation/json_result/test_aggregators.py index 45b7ebfc33..8dd1874c9f 100644 --- a/tests/libecalc/presentation/json_result/test_aggregators.py +++ b/tests/libecalc/presentation/json_result/test_aggregators.py @@ -6,6 +6,7 @@ import libecalc.dto.fuel_type import libecalc.dto.types from libecalc import dto +from libecalc.infrastructure import components from libecalc.application.energy_calculator import EnergyCalculator from libecalc.application.graph_result import GraphResult from libecalc.common.time_utils import Period, Periods @@ -24,7 +25,7 @@ def get_installation( name_inst: str, name_consumer: str, name_fuel: str, co2_factor: float, fuel_rate: float -) -> dto.Installation: +) -> components.Installation: """Creates a simple installation object for use in asset setup Args: name_inst (str): Name of installation @@ -34,10 +35,10 @@ def get_installation( fuel_rate (float): Rate of fuel (Sm3/d) Returns: - dto.Installation + components.Installation """ - inst = dto.Installation( + inst = components.Installation( name=name_inst, regularity={Period(datetime(1900, 1, 1)): Expression.setup_from_expression(1)}, hydrocarbon_export={Period(datetime(1900, 1, 1)): Expression.setup_from_expression(1)}, @@ -70,7 +71,7 @@ def fuel(name: str, co2_factor: float) -> libecalc.dto.fuel_type.FuelType: ) -def direct_fuel_consumer(name: str, name_fuel: str, co2_factor: float, fuel_rate: float) -> dto.FuelConsumer: +def direct_fuel_consumer(name: str, name_fuel: str, co2_factor: float, fuel_rate: float) -> components.FuelConsumer: """Creates a simple direct fuel consumer object for use in installation setup Args: name (str): Name of direct fuel consumer @@ -79,12 +80,12 @@ def direct_fuel_consumer(name: str, name_fuel: str, co2_factor: float, fuel_rate fuel_rate (float): Rate of fuel (Sm3/d) Returns: - dto.FuelConsumer + components.FuelConsumer """ - return dto.FuelConsumer( + return components.FuelConsumer( name=name, - component_type=dto.components.ComponentType.GENERIC, + component_type=components.ComponentType.GENERIC, fuel={Period(datetime(2024, 1, 1)): fuel(name=name_fuel, co2_factor=co2_factor)}, regularity={Period(datetime(1900, 1, 1)): Expression.setup_from_expression(1)}, user_defined_category={ @@ -174,7 +175,7 @@ def test_aggregate_emissions_installations(self, energy_model_from_dto_factory): name_inst="INSTB", name_consumer="cons2", name_fuel="fuel2", co2_factor=10, fuel_rate=100 ) - asset = dto.Asset( + asset = components.Asset( name="Main asset", installations=[inst_a, inst_b], )