Skip to content

Commit

Permalink
refactor: generate facility type schema (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Sep 18, 2023
1 parent 924526a commit 9428979
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 316 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.yaml_installation import YamlInstallation
from libecalc.input.yaml_types.facility_type.yaml_facility_type import YamlFacilityType
from libecalc.input.yaml_types.fuel_type.yaml_fuel_type import YamlFuelType
from libecalc.input.yaml_types.time_series.yaml_time_series import (
YamlTimeSeriesCollection,
Expand All @@ -22,11 +23,6 @@ class Config:

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlAsset"]) -> None:
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="FACILITY_INPUTS",
property_ref="$SERVER_NAME/api/v1/schema-validation/facility-files.json#properties/FACILITY_INPUTS",
)
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="MODELS",
Expand All @@ -39,7 +35,7 @@ def schema_extra(schema: Dict[str, Any], model: Type["YamlAsset"]) -> None:
description="Defines the inputs for time dependent variables, or 'reservoir variables'."
"\n\n$ECALC_DOCS_KEYWORDS_URL/TIME_SERIES",
)
facility_inputs: YamlPlaceholderType = Field(
facility_inputs: List[YamlFacilityType] = Field(
None,
title="FACILITY_INPUTS",
description="Defines input files which characterize various facility elements."
Expand Down
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"),
]
Loading

0 comments on commit 9428979

Please sign in to comment.