Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use yaml expression type for installation #412

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from libecalc.common.discriminator_fallback import DiscriminatorWithFallback
from libecalc.dto.base import InstallationUserDefinedCategoryType
from libecalc.dto.utils.validators import ComponentNameStr
from libecalc.expression import Expression
from libecalc.presentation.yaml.yaml_keywords import EcalcYamlKeywords
from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.components.legacy.yaml_fuel_consumer import (
Expand All @@ -18,6 +17,9 @@
from libecalc.presentation.yaml.yaml_types.components.yaml_category_field import (
CategoryField,
)
from libecalc.presentation.yaml.yaml_types.components.yaml_expression_type import (
YamlExpressionType,
)
from libecalc.presentation.yaml.yaml_types.components.yaml_generator_set import (
YamlGeneratorSet,
)
Expand All @@ -36,7 +38,7 @@ class YamlInstallation(YamlBase): # TODO: conditional required, either fuelcons
description="Name of the installation.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
)
category: InstallationUserDefinedCategoryType = CategoryField(None)
hydrocarbon_export: YamlTemporalModel[Expression] = Field(
hydrocarbon_export: YamlTemporalModel[YamlExpressionType] = Field(
None,
title="HCEXPORT",
description="Defines the export of hydrocarbons as number of oil equivalents in Sm3.\n\n$ECALC_DOCS_KEYWORDS_URL/HCEXPORT",
Expand All @@ -47,7 +49,7 @@ class YamlInstallation(YamlBase): # TODO: conditional required, either fuelcons
title="FUEL",
description="Main fuel type for installation." "\n\n$ECALC_DOCS_KEYWORDS_URL/FUEL",
)
regularity: YamlTemporalModel[Expression] = Field(
regularity: YamlTemporalModel[YamlExpressionType] = Field(
None,
title="REGULARITY",
description="Regularity of the installation can be specified by a single number or as an expression. USE WITH CARE.\n\n$ECALC_DOCS_KEYWORDS_URL/REGULARITY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
)
from libecalc.presentation.yaml.yaml_types.yaml_variable import YamlSingleVariable

# from libecalc.presentation.yaml.yaml_types import YamlSingleVariable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YamlVariables still do not use YamlExpressionType, this is because we expect the type to be parsed into an expression. YamlExpressionType only validates. We should look into parsing into an expression in YamlExpressionType I think, if we go that route we probably don't need to implement pydantic specific methods in expression.py (__get_pydantic_core_schema__ etc.). The alternative is to make expression.py validate similar to YamlExpressionType and use that in the Yaml classes.



class TestEvaluateVariables:
def test_unsolvable(self):
Expand Down