Skip to content

Commit 443851e

Browse files
authored
refactor: track yaml hierarchy context and info in YamlModel (#1005)
1 parent eb6fbe2 commit 443851e

22 files changed

Lines changed: 272 additions & 82 deletions

File tree

src/libecalc/application/graph_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
self.emission_results = emission_results
1818
self.variables_map = variables_map
1919

20-
def get_subgraph(self, node_id: str) -> "GraphResult":
20+
def get_installation(self, node_id: str) -> "GraphResult":
2121
subgraph = self.graph.get_node(node_id).get_graph()
2222

2323
return GraphResult(

src/libecalc/domain/energy/emitter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
from uuid import UUID
23

34
from libecalc.core.result.emission import EmissionResult
45
from libecalc.domain.energy.component_energy_context import ComponentEnergyContext
@@ -14,6 +15,9 @@ class Emitter(abc.ABC):
1415
@abc.abstractmethod
1516
def id(self) -> str: ...
1617

18+
@abc.abstractmethod
19+
def get_id(self) -> UUID: ...
20+
1721
@abc.abstractmethod
1822
def evaluate_emissions(
1923
self,

src/libecalc/domain/energy/energy_component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
from uuid import UUID
23

34
from libecalc.common.component_type import ComponentType
45

@@ -12,6 +13,9 @@ class EnergyComponent(abc.ABC):
1213
@abc.abstractmethod
1314
def id(self) -> str: ...
1415

16+
@abc.abstractmethod
17+
def get_id(self) -> UUID: ...
18+
1519
@abc.abstractmethod
1620
def get_component_process_type(self) -> ComponentType: ...
1721

src/libecalc/domain/infrastructure/emitters/venting_emitter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
from uuid import UUID
23

34
import numpy as np
45

@@ -71,13 +72,15 @@ def __init__(self, oil_volume_rate: OilVolumeRate, emissions: list[VentingVolume
7172
class VentingEmitter(Emitter, EnergyComponent, abc.ABC):
7273
def __init__(
7374
self,
75+
id: UUID,
7476
path_id: PathID,
7577
expression_evaluator: ExpressionEvaluator,
7678
component_type: ComponentType,
7779
user_defined_category: dict[Period, ConsumerUserDefinedCategoryType],
7880
emitter_type: VentingType,
7981
regularity: Regularity,
8082
):
83+
self._uuid = id
8184
self._path_id = path_id
8285
self.expression_evaluator = expression_evaluator
8386
self.component_type = component_type
@@ -86,6 +89,9 @@ def __init__(
8689
self.regularity = regularity
8790
self.emission_results: dict[str, EmissionResult] | None = None
8891

92+
def get_id(self) -> UUID:
93+
return self._uuid
94+
8995
@property
9096
def name(self) -> str:
9197
return self._path_id.get_name()

src/libecalc/domain/infrastructure/energy_components/asset/asset.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from uuid import UUID
2+
13
from libecalc.common.component_type import ComponentType
24
from libecalc.domain.energy import EnergyComponent
35
from libecalc.domain.infrastructure.energy_components.installation.installation import Installation
@@ -8,13 +10,18 @@
810
class Asset(EnergyComponent):
911
def __init__(
1012
self,
13+
id: UUID,
1114
path_id: PathID,
1215
installations: list[Installation],
1316
):
17+
self._uuid = id
1418
self._path_id = path_id
1519
self.installations = installations
1620
self.component_type = ComponentType.ASSET
1721

22+
def get_id(self) -> UUID:
23+
return self._uuid
24+
1825
@property
1926
def id(self):
2027
return self._path_id.get_name()

src/libecalc/domain/infrastructure/energy_components/electricity_consumer/electricity_consumer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Literal
2+
from uuid import UUID
23

34
from libecalc.common.component_type import ComponentType
45
from libecalc.common.consumption_type import ConsumptionType
@@ -35,6 +36,7 @@ def get_process_system(self, event: ProcessChangedEvent) -> ProcessSystem | None
3536

3637
def __init__(
3738
self,
39+
id: UUID,
3840
path_id: PathID,
3941
regularity: Regularity,
4042
user_defined_category: dict[Period, ConsumerUserDefinedCategoryType],
@@ -43,6 +45,7 @@ def __init__(
4345
expression_evaluator: ExpressionEvaluator,
4446
consumes: Literal[ConsumptionType.ELECTRICITY] = ConsumptionType.ELECTRICITY,
4547
):
48+
self._uuid = id
4649
self._path_id = path_id
4750
self.regularity = regularity
4851
self.user_defined_category = user_defined_category
@@ -52,6 +55,9 @@ def __init__(
5255
self.component_type = component_type
5356
self.consumer_results: dict[str, EcalcModelResult] = {}
5457

58+
def get_id(self) -> UUID:
59+
return self._uuid
60+
5561
@property
5662
def id(self) -> str:
5763
return self._path_id.get_name()

src/libecalc/domain/infrastructure/energy_components/fuel_consumer/fuel_consumer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from uuid import UUID
2+
13
from libecalc.common.component_type import ComponentType
24
from libecalc.common.consumption_type import ConsumptionType
35
from libecalc.common.temporal_model import TemporalModel
@@ -36,6 +38,7 @@ def get_process_system(self, event: ProcessChangedEvent) -> ProcessSystem | None
3638

3739
def __init__(
3840
self,
41+
id: UUID,
3942
path_id: PathID,
4043
regularity: Regularity,
4144
user_defined_category: dict[Period, ConsumerUserDefinedCategoryType],
@@ -44,6 +47,7 @@ def __init__(
4447
energy_usage_model: TemporalModel[ConsumerFunction],
4548
expression_evaluator: ExpressionEvaluator,
4649
):
50+
self._uuid = id
4751
assert fuel is not None
4852
self._path_id = path_id
4953
self.regularity = regularity
@@ -55,6 +59,9 @@ def __init__(
5559
self.consumer_results: dict[str, EcalcModelResult] = {}
5660
self.emission_results: dict[str, EmissionResult] | None = None
5761

62+
def get_id(self) -> UUID:
63+
return self._uuid
64+
5865
@property
5966
def name(self):
6067
return self._path_id.get_name()

src/libecalc/domain/infrastructure/energy_components/generator_set/generator_set_component.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Literal
2+
from uuid import UUID
23

34
import numpy as np
45
from numpy.typing import NDArray
@@ -39,6 +40,7 @@ class GeneratorSetEnergyComponent(Emitter, EnergyComponent):
3940

4041
def __init__(
4142
self,
43+
id: UUID,
4244
path_id: PathID,
4345
user_defined_category: dict[Period, ConsumerUserDefinedCategoryType],
4446
generator_set_model: TemporalModel[GeneratorSetModel],
@@ -50,6 +52,7 @@ def __init__(
5052
max_usage_from_shore: ExpressionType | None = None,
5153
component_type: Literal[ComponentType.GENERATOR_SET] = ComponentType.GENERATOR_SET,
5254
):
55+
self._uuid = id
5356
self._path_id = path_id
5457
self.user_defined_category = user_defined_category
5558
self.regularity = regularity
@@ -63,6 +66,9 @@ def __init__(
6366
self.consumer_results: dict[str, EcalcModelResult] = {}
6467
self.emission_results: dict[str, EmissionResult] | None = None
6568

69+
def get_id(self) -> UUID:
70+
return self._uuid
71+
6672
@property
6773
def id(self) -> str:
6874
return self._path_id.get_name()

src/libecalc/domain/infrastructure/energy_components/installation/installation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from uuid import UUID
2+
13
from libecalc.common.component_type import ComponentType
24
from libecalc.common.variables import ExpressionEvaluator
35
from libecalc.domain.energy import EnergyComponent
@@ -27,6 +29,7 @@ class Installation(EnergyComponent):
2729

2830
def __init__(
2931
self,
32+
id: UUID,
3033
path_id: PathID,
3134
regularity: Regularity,
3235
hydrocarbon_export: HydrocarbonExport,
@@ -35,6 +38,7 @@ def __init__(
3538
venting_emitters: list[VentingEmitter] | None = None,
3639
user_defined_category: InstallationUserDefinedCategoryType | None = None,
3740
):
41+
self._uuid = id
3842
self._path_id = path_id
3943
self.hydrocarbon_export = hydrocarbon_export
4044
self.regularity = regularity
@@ -49,6 +53,9 @@ def __init__(
4953
venting_emitters = []
5054
self.venting_emitters = venting_emitters
5155

56+
def get_id(self) -> UUID:
57+
return self._uuid
58+
5259
@property
5360
def name(self) -> str:
5461
return self._path_id.get_name()

src/libecalc/presentation/exporter/infrastructure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,6 @@ def get_from_type(self, exportable_type: ExportableType) -> list[Exportable]:
403403
assert_never(exportable_type)
404404

405405
return [
406-
InstallationExportable(self._graph_result.get_subgraph(installation_id))
406+
InstallationExportable(self._graph_result.get_installation(installation_id))
407407
for installation_id in self._graph_result.graph.get_nodes_of_type(component_type)
408408
]

0 commit comments

Comments
 (0)