-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
364 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/libecalc/presentation/yaml/yaml_types/components/train/yaml_train.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from datetime import datetime | ||
from typing import Dict, Generic, List, Literal, Optional, TypeVar | ||
|
||
from libecalc import dto | ||
from libecalc.common.time_utils import Period | ||
from libecalc.dto.base import ComponentType | ||
from libecalc.dto.components import Stream, TrainComponent | ||
from libecalc.dto.types import ConsumptionType | ||
from libecalc.expression import Expression | ||
from libecalc.presentation.yaml.yaml_entities import References | ||
from libecalc.presentation.yaml.yaml_types.components.yaml_base import YamlConsumerBase | ||
from libecalc.presentation.yaml.yaml_types.yaml_stream import YamlStream | ||
from pydantic import Field | ||
from pydantic.generics import GenericModel | ||
|
||
TYamlConsumer = TypeVar("TYamlConsumer") | ||
|
||
|
||
class YamlTrain(YamlConsumerBase, GenericModel, Generic[TYamlConsumer]): | ||
component_type: Literal[ComponentType.TRAIN_V2] = Field( | ||
ComponentType.TRAIN_V2, | ||
title="Type", | ||
description="The type of the component", | ||
alias="TYPE", | ||
) | ||
stages: List[TYamlConsumer] | ||
streams: List[YamlStream] = Field(default_factory=list, title="Streams", description="List of streams") | ||
|
||
def to_dto( | ||
self, | ||
consumes: ConsumptionType, | ||
regularity: Dict[datetime, Expression], | ||
target_period: Period, | ||
references: References, | ||
category: str, | ||
fuel: Optional[Dict[datetime, dto.types.FuelType]], | ||
): | ||
stages = [ | ||
consumer.to_dto( | ||
references=references, | ||
consumes=consumes, | ||
regularity=regularity, | ||
target_period=target_period, | ||
fuel=fuel, | ||
category=self.category or category, | ||
) | ||
for consumer in self.stages | ||
] | ||
|
||
stage_name_to_id_map = {stage.name: stage.id for stage in stages} | ||
|
||
return TrainComponent( | ||
component_type=self.component_type, | ||
consumes=consumes, | ||
fuel=fuel, | ||
category=self.category or category, | ||
name=self.name, | ||
stages=stages, | ||
streams=[ | ||
Stream( | ||
stream_name=stream.name, | ||
from_component_id=stage_name_to_id_map[stream.from_], | ||
to_component_id=stage_name_to_id_map[stream.to], | ||
) | ||
for stream in self.streams | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.