Skip to content

Commit

Permalink
Add submodel template digital nameplate
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-ifak committed May 6, 2024
1 parent 652f80f commit 681bde4
Show file tree
Hide file tree
Showing 7 changed files with 703 additions and 143 deletions.
4 changes: 0 additions & 4 deletions aas_test_engines/_file/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from fences.json_schema.parse import parse
from fences.core.node import Node as FlowGraph


def generate_graph(schema) -> FlowGraph:
# TODO: remove these after fixing fences.core.exception.InternalException: Decision without valid leaf detected
del schema['$defs']['AssetInformation']['allOf'][1]['properties']['specificAssetIds']['items']['allOf'][0]
del schema['$defs']['Entity']['allOf'][1]
schema_norm = normalize(schema, False)
config = default_config()
config.normalize = False
Expand Down
53 changes: 53 additions & 0 deletions aas_test_engines/_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import Dict, List

def _group(elements: list) -> dict:
assert isinstance(elements, list)
grouped: Dict[str, List[any]] = {}
for item in elements:
assert isinstance(item, dict)
key = item.get('idShort')
assert isinstance(key, str)
try:
grouped[key].append(item)
except KeyError:
grouped[key] = [item]
return grouped

def group(data: any) -> any:
if isinstance(data, list):
data = [group(i) for i in data]
elif isinstance(data, dict):
data: dict = {key: group(value) for key, value in data.items()}
if data.get('modelType') == 'SubmodelElementCollection':
elements = data.get('value')
data['value'] = _group(elements)
elif data.get('modelType') == 'Submodel':
elements = data.get('submodelElements')
data['submodelElements'] = _group(elements)
return data

def _un_group(elements: dict) -> list:
if not isinstance(elements, dict):
return elements
un_grouped: List[str, dict] = []
for item in elements.values():
if isinstance(item, list):
un_grouped.extend(item)
else:
un_grouped.append(item)
return un_grouped

def un_group(data: any) -> any:
if isinstance(data, list):
data = [un_group(i) for i in data]
for idx, value in enumerate(data):
data[idx] = un_group(value)
elif isinstance(data, dict):
data = {key: un_group(value) for key, value in data.items()}
if data.get('modelType') == 'SubmodelElementCollection':
elements = data.get('value')
data['value'] = _un_group(elements)
elif data.get('modelType') == 'Submodel':
elements = data.get('submodelElements')
data['submodelElements'] = _un_group(elements)
return data
Loading

0 comments on commit 681bde4

Please sign in to comment.