-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #648 from figueroa1395/feature/metadata-enum
Feature/metadata datatypes
- Loading branch information
Showing
39 changed files
with
1,230 additions
and
709 deletions.
There are no files selected for viewing
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 +1 @@ | ||
1.8 | ||
1.9 |
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
89 changes: 89 additions & 0 deletions
89
code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja
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,89 @@ | ||
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org> | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
"""Data types for power grid model dataset and component types.""" | ||
|
||
# This file is automatically generated. DO NOT modify it manually! | ||
|
||
{%- set dataset_types = all_map.keys() %} | ||
{%- set components = all_map['input'].keys() %} | ||
|
||
from enum import Enum, EnumMeta | ||
from typing import Any, Dict, Mapping | ||
|
||
# pylint: disable=invalid-name | ||
|
||
# fmt: off | ||
|
||
class _MetaEnum(EnumMeta): | ||
def __contains__(cls, member): | ||
""" | ||
Check if member is part of the Enum. | ||
|
||
Args: | ||
member: Member to check. | ||
|
||
Returns: | ||
bool: True if the member is part of the Enum, False otherwise. | ||
""" | ||
return member in cls.__members__.keys() | ||
|
||
|
||
class DatasetType(str, Enum, metaclass=_MetaEnum): | ||
""" | ||
A DatasetType is the type of a :class:`Dataset` in power grid model. | ||
|
||
- Examples: | ||
|
||
- DatasetType.input = "input" | ||
- DatasetType.update = "update" | ||
""" | ||
{% for dataset_type in dataset_types %} | ||
{{ dataset_type }} = "{{ dataset_type }}" | ||
{%- endfor %} | ||
|
||
|
||
class ComponentType(str, Enum): | ||
""" | ||
A ComponentType is the type of a grid component. | ||
|
||
- Examples: | ||
|
||
- ComponentType.node = "node" | ||
- ComponentType.line = "line" | ||
""" | ||
{% for component in components %} | ||
{{ component }} = "{{ component }}" | ||
{%- endfor %} | ||
|
||
|
||
# pylint: enable=invalid-name | ||
|
||
|
||
def _str_to_datatype(data_type: Any) -> DatasetType: | ||
"""Helper function to transform data_type str to DatasetType.""" | ||
if isinstance(data_type, str): | ||
return DatasetType[data_type] | ||
return data_type | ||
|
||
|
||
def _map_to_datatypes(data: Mapping[Any, Any]) -> Dict[DatasetType, Any]: | ||
"""Helper function to map datatype str keys to DatasetType.""" | ||
return {_str_to_datatype(key): value for key, value in data.items()} | ||
|
||
|
||
def _str_to_component_type(component: Any) -> ComponentType: | ||
"""Helper function to transform component str to ComponentType.""" | ||
if isinstance(component, str): | ||
return ComponentType[component] | ||
return component | ||
|
||
|
||
def _map_to_component_types(data: Mapping[Any, Any]) -> Dict[ComponentType, Any]: | ||
"""Helper function to map componenttype str keys to ComponentType.""" | ||
return {_str_to_component_type(key): value for key, value in data.items()} | ||
|
||
|
||
# fmt: on | ||
|
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
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.