-
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.
refactor: generate generator set schema (#165)
- Loading branch information
Showing
12 changed files
with
392 additions
and
533 deletions.
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
...calc/libraries/libecalc/common/libecalc/input/validation/json_schemas/fuel-consumers.json
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
...calc/libraries/libecalc/common/libecalc/input/validation/json_schemas/generator-sets.json
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
...ecalc/libraries/libecalc/common/libecalc/input/validation/json_schemas/installations.json
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/ecalc/libraries/libecalc/common/libecalc/input/yaml_types/components/generator_set.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,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", | ||
) |
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
37 changes: 37 additions & 0 deletions
37
.../libecalc/common/libecalc/input/yaml_types/components/legacy/yaml_electricity_consumer.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,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", | ||
) |
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.