Skip to content

Commit

Permalink
refactor: generate generator set schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Sep 12, 2023
1 parent 71a07f5 commit d652173
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 533 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Any, Dict, List, Type

from libecalc.dto.base import ConsumerUserDefinedCategoryType
from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.category import CategoryField
from libecalc.input.yaml_types.components.legacy.yaml_electricity_consumer import (
YamlElectricityConsumer,
)
from libecalc.input.yaml_types.placeholder_type import PlaceholderType
from libecalc.input.yaml_types.schema_helpers import (
replace_temporal_placeholder_property_with_legacy_ref,
)
from libecalc.input.yaml_types.temporal_model import TemporalModel
from pydantic import Field


class YamlGeneratorSet(YamlBase):
class Config:
title = "GENERATORSET"

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlGeneratorSet"]) -> None:
replace_temporal_placeholder_property_with_legacy_ref(
schema=schema,
property_key="ELECTRICITY2FUEL",
property_ref="$SERVER_NAME/api/v1/schema-validation/energy-usage-model-common.json#definitions/number_or_string",
)

name: str = Field(
...,
title="NAME",
description="Name of the generator set.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
)
category: ConsumerUserDefinedCategoryType = CategoryField(...)
fuel: TemporalModel[str] = Field(
None,
title="FUEL",
description="The fuel used by the generator set." "\n\n$ECALC_DOCS_KEYWORDS_URL/FUEL",
)
electricity2fuel: TemporalModel[PlaceholderType] = Field(
...,
title="ELECTRICITY2FUEL",
description="Specifies the correlation between the electric power delivered and the fuel burned by a "
"generator set.\n\n$ECALC_DOCS_KEYWORDS_URL/ELECTRICITY2FUEL",
)
consumers: List[YamlElectricityConsumer] = Field(
...,
title="CONSUMERS",
description="Consumers getting electrical power from the generator set.\n\n$ECALC_DOCS_KEYWORDS_URL/CONSUMERS",
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.category import CategoryField
from libecalc.input.yaml_types.components.compressor_system import CompressorSystem
from libecalc.input.yaml_types.components.generator_set import YamlGeneratorSet
from libecalc.input.yaml_types.components.legacy.yaml_fuel_consumer import (
YamlFuelConsumer,
)
Expand All @@ -23,11 +24,6 @@ class Config:

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlInstallation"]) -> None:
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="GENERATORSETS",
property_ref="$SERVER_NAME/api/v1/schema-validation/generator-sets.json#properties/GENERATORSETS",
)
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="DIRECTEMITTERS",
Expand Down Expand Up @@ -55,7 +51,7 @@ def schema_extra(schema: Dict[str, Any], model: Type["YamlInstallation"]) -> Non
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",
)
generatorsets: PlaceholderType = Field(
generatorsets: List[YamlGeneratorSet] = Field(
None,
title="GENERATORSETS",
description="Defines one or more generator sets.\n\n$ECALC_DOCS_KEYWORDS_URL/GENERATORSETS",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Any, Dict, Type

from libecalc.dto.base import ConsumerUserDefinedCategoryType
from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.category import CategoryField
from libecalc.input.yaml_types.placeholder_type import PlaceholderType
from libecalc.input.yaml_types.schema_helpers import (
replace_temporal_placeholder_property_with_legacy_ref,
)
from libecalc.input.yaml_types.temporal_model import TemporalModel
from pydantic import Field


class YamlElectricityConsumer(YamlBase):
class Config:
title = "ELECTRICITY_CONSUMER"

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlElectricityConsumer"]) -> None:
replace_temporal_placeholder_property_with_legacy_ref(
schema=schema,
property_key="ENERGY_USAGE_MODEL",
property_ref="$SERVER_NAME/api/v1/schema-validation/energy-usage-model.json#properties/ENERGY_USAGE_MODEL",
)

name: str = Field(
...,
title="NAME",
description="Name of the consumer.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
)
category: ConsumerUserDefinedCategoryType = CategoryField(...)
energy_usage_model: TemporalModel[PlaceholderType] = Field(
...,
title="ENERGY_USAGE_MODEL",
description="Definition of the energy usage model for the consumer."
"\n\n$ECALC_DOCS_KEYWORDS_URL/ENERGY_USAGE_MODEL",
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.category import CategoryField
from libecalc.input.yaml_types.placeholder_type import PlaceholderType
from libecalc.input.yaml_types.schema_helpers import (
replace_temporal_placeholder_property_with_legacy_ref,
)
from libecalc.input.yaml_types.temporal_model import TemporalModel
from pydantic import Field

Expand All @@ -14,16 +17,16 @@ class Config:

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlFuelConsumer"]) -> None:
for energy_usage_model in schema["properties"]["ENERGY_USAGE_MODEL"]["anyOf"]:
del energy_usage_model["type"]
energy_usage_model[
"$ref"
] = "$SERVER_NAME/api/v1/schema-validation/energy-usage-model.json#properties/ENERGY_USAGE_MODEL"
replace_temporal_placeholder_property_with_legacy_ref(
schema=schema,
property_key="ENERGY_USAGE_MODEL",
property_ref="$SERVER_NAME/api/v1/schema-validation/energy-usage-model.json#properties/ENERGY_USAGE_MODEL",
)

name: str = Field(
...,
title="NAME",
description="Name of the fuel consumer.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
description="Name of the consumer.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
)
category: ConsumerUserDefinedCategoryType = CategoryField(...)
energy_usage_model: TemporalModel[PlaceholderType] = Field(
Expand All @@ -32,6 +35,7 @@ def schema_extra(schema: Dict[str, Any], model: Type["YamlFuelConsumer"]) -> Non
description="Definition of the energy usage model for the consumer."
"\n\n$ECALC_DOCS_KEYWORDS_URL/ENERGY_USAGE_MODEL",
)

fuel: TemporalModel[str] = Field(
None,
title="FUEL",
Expand Down
Loading

0 comments on commit d652173

Please sign in to comment.