-
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
- Loading branch information
Showing
9 changed files
with
386 additions
and
43 deletions.
There are no files selected for viewing
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", | ||
) |
31 changes: 4 additions & 27 deletions
31
...braries/libecalc/common/libecalc/input/yaml_types/components/legacy/yaml_fuel_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
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
12 changes: 9 additions & 3 deletions
12
src/ecalc/libraries/libecalc/common/libecalc/input/yaml_types/temporal_model.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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
from datetime import datetime | ||
from typing import MutableMapping, TypeVar, Union | ||
from typing import Dict, TypeVar, Union | ||
|
||
from pydantic import ConstrainedStr | ||
|
||
|
||
class DatetimeString(ConstrainedStr): | ||
regex = "^\\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])$" | ||
|
||
|
||
TModel = TypeVar("TModel") | ||
TemporalModel = Union[TModel, MutableMapping[datetime, TModel]] | ||
TemporalModel = Union[TModel, Dict[DatetimeString, TModel]] |
Oops, something went wrong.