Skip to content
Snippets Groups Projects
Commit cb0147fe authored by Hock, Benedikt's avatar Hock, Benedikt
Browse files

add check for correct hierarchy

parent d7745e50
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import uuid ...@@ -7,6 +7,7 @@ import uuid
from typing import List, Dict from typing import List, Dict
import json import json
import copy import copy
import operator
# TODO # TODO
...@@ -184,6 +185,11 @@ class LegoAssembly: ...@@ -184,6 +185,11 @@ class LegoAssembly:
return clone return clone
def print_assembly_tree(root, level=0, is_last=False): def print_assembly_tree(root, level=0, is_last=False):
if not isinstance(root, LegoAssembly):
raise TypeError(
f"Argument should be of type {LegoAssembly.__name__}, "
f"got {type(root).__name__} instead."
)
# print component # print component
assembly_padding = "" assembly_padding = ""
if level > 0: if level > 0:
...@@ -204,8 +210,24 @@ def print_assembly_tree(root, level=0, is_last=False): ...@@ -204,8 +210,24 @@ def print_assembly_tree(root, level=0, is_last=False):
print(f"{component_padding}{item}") print(f"{component_padding}{item}")
def check_aggregation_hierarchy(root): def correct_aggregation_hierarchy(root: LegoAssembly, strict: bool = False):
pass if not isinstance(root, LegoAssembly):
raise TypeError(
f"Argument should be of type {LegoAssembly.__name__}, "
f"got {type(root).__name__} instead."
)
higher_level = operator.le
if strict:
higher_level = operator.lt
for component in root.components:
if not higher_level(root.layer.value, component.layer.value):
return False
for assembly in root.assemblies:
if not higher_level(root.layer.value, assembly.layer.value):
return False
if not correct_aggregation_hierarchy(assembly, strict):
return False
return True
class KPIEncoder(json.JSONEncoder): class KPIEncoder(json.JSONEncoder):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment