-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generate facility type schema (#182)
- Loading branch information
Showing
4 changed files
with
421 additions
and
316 deletions.
There are no files selected for viewing
132 changes: 0 additions & 132 deletions
132
...calc/libraries/libecalc/common/libecalc/input/validation/json_schemas/facility-files.json
This file was deleted.
Oops, something went wrong.
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
105 changes: 105 additions & 0 deletions
105
...c/libraries/libecalc/common/libecalc/input/yaml_types/facility_type/yaml_facility_type.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,105 @@ | ||
from typing import Literal, Union | ||
|
||
from libecalc.input.yaml_types import YamlBase | ||
from pydantic import Field | ||
from typing_extensions import Annotated | ||
|
||
|
||
def FacilityTypeField(): | ||
return Field( | ||
..., | ||
title="TYPE", | ||
description="Defines the type of model applied on the data in the file.\n\n$ECALC_DOCS_KEYWORDS_URL/TYPE", | ||
) | ||
|
||
|
||
class YamlFacilityAdjustment(YamlBase): | ||
constant: float = Field( | ||
0, | ||
title="CONSTANT", | ||
description="Adjust input data with a constant value.\n\n$ECALC_DOCS_KEYWORDS_URL/CONSTANT", | ||
) | ||
factor: float = Field( | ||
1, | ||
title="FACTOR", | ||
description="Adjust input data with a constant multiplier.\n\n$ECALC_DOCS_KEYWORDS_URL/FACTOR", | ||
) | ||
|
||
|
||
class YamlFacilityTypeBase(YamlBase): | ||
name: str = Field( | ||
..., | ||
title="NAME", | ||
description="Name of the facility input.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME", | ||
) | ||
file: str = Field( | ||
..., | ||
title="FILE", | ||
description="Specifies the name of an input file.\n\n$ECALC_DOCS_KEYWORDS_URL/FILE", | ||
) | ||
adjustment: YamlFacilityAdjustment = Field( | ||
None, | ||
title="ADJUSTMENT", | ||
description="Definition of adjustments to correct for mismatches in facility energy usage.\n\n$ECALC_DOCS_KEYWORDS_URL/ADJUSTMENT", | ||
) | ||
|
||
|
||
class YamlGeneratorSetModel(YamlFacilityTypeBase): | ||
type: Literal["ELECTRICITY2FUEL"] = FacilityTypeField() | ||
|
||
|
||
class YamlTabularModel(YamlFacilityTypeBase): | ||
type: Literal["TABULAR"] = FacilityTypeField() | ||
|
||
|
||
class YamlCompressorTabularModel(YamlFacilityTypeBase): | ||
type: Literal["COMPRESSOR_TABULAR"] = FacilityTypeField() | ||
|
||
|
||
class YamlPumpChartUnits(YamlBase): | ||
rate: Literal["AM3_PER_HOUR"] = Field( | ||
..., | ||
title="RATE", | ||
description="Unit for rate in pump chart. Currently only AM3_PER_HOUR is supported", | ||
) | ||
head: Literal["M", "KJ_PER_KG", "JOULE_PER_KG"] = Field( | ||
..., | ||
title="HEAD", | ||
description="Unit for head in pump chart. Supported units are M (default), KJ_PER_KG and JOULE_PER_KG", | ||
) | ||
efficiency: Literal["PERCENTAGE", "FRACTION"] = Field( | ||
..., | ||
title="EFFICIENCY", | ||
description="Unit of efficiency in pump chart. Supported units are PERCENTAGE (default) and FRACTION.", | ||
) | ||
|
||
|
||
class YamlPumpChartBase(YamlFacilityTypeBase): | ||
head_margin: float = Field( | ||
None, | ||
title="HEAD_MARGIN", | ||
description="Adjustment of the head margin for power calibration.\n\n$ECALC_DOCS_KEYWORDS_URL/HEAD_MARGIN", | ||
) | ||
units: YamlPumpChartUnits = Field( | ||
..., title="UNITS", description="Units for pump charts: RATE, HEAD and EFFICIENCY." | ||
) | ||
|
||
|
||
class YamlPumpChartSingleSpeed(YamlPumpChartBase): | ||
type: Literal["PUMP_CHART_SINGLE_SPEED"] = FacilityTypeField() | ||
|
||
|
||
class YamlPumpChartVariableSpeed(YamlPumpChartBase): | ||
type: Literal["PUMP_CHART_VARIABLE_SPEED"] = FacilityTypeField() | ||
|
||
|
||
YamlFacilityType = Annotated[ | ||
Union[ | ||
YamlGeneratorSetModel, | ||
YamlTabularModel, | ||
YamlCompressorTabularModel, | ||
YamlPumpChartSingleSpeed, | ||
YamlPumpChartVariableSpeed, | ||
], | ||
Field(discriminator="type"), | ||
] |
Oops, something went wrong.