Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quality-kpi
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quiring, Ole
quality-kpi
Commits
dd8d99a0
Commit
dd8d99a0
authored
2 years ago
by
Hock, Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
fix bug in print_assembly_tree()
parent
6f74024a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
functions/classes.py
+14
-19
14 additions, 19 deletions
functions/classes.py
with
14 additions
and
19 deletions
functions/classes.py
+
14
−
19
View file @
dd8d99a0
...
@@ -428,41 +428,36 @@ class LegoAssembly:
...
@@ -428,41 +428,36 @@ class LegoAssembly:
return
clone
return
clone
def
print_assembly_tree
(
root
,
level
=
0
,
is_last
=
Fals
e
):
def
print_assembly_tree
(
root
,
level
s
=
Non
e
):
"""
"""
Prints the assembly tree starting from root with a visualization
Prints the assembly tree starting from root with a visualization
implemented with text characters.
implemented with text characters.
Args:
Args:
root (LegoAssembly): The root of the assembly tree to print.
root (LegoAssembly): The root of the assembly tree to print.
level (int): The indentation level. Defaults to 0.
levels (List[bool]): Internally used by recursion to know where to print vertical connection.
is_last (bool): Determines whether the current node is the last in level.
Defaults to an empty list.
Defaults to False.
"""
"""
if
not
isinstance
(
root
,
LegoAssembly
):
if
not
isinstance
(
root
,
LegoAssembly
):
raise
TypeError
(
raise
TypeError
(
f
"
Argument should be of type
{
LegoAssembly
.
__name__
}
,
"
f
"
Argument should be of type
{
LegoAssembly
.
__name__
}
,
"
f
"
got
{
type
(
root
).
__name__
}
instead.
"
f
"
got
{
type
(
root
).
__name__
}
instead.
"
)
)
"""
Print the items.
"""
if
levels
is
None
:
levels
=
[]
connection_padding
=
""
.
join
(
map
(
lambda
draw
:
"
│
"
if
draw
else
"
"
,
levels
))
assembly_padding
=
""
assembly_padding
=
""
if
level
>
0
:
if
len
(
levels
)
>
0
:
assembly_padding
+=
"
│
"
*
(
level
-
1
)
assembly_padding
=
"
├──
"
if
levels
[
-
1
]
else
"
└──
"
if
is_last
:
print
(
f
"
{
connection_padding
[
:
-
4
]
}{
assembly_padding
}{
root
}
"
)
assembly_padding
+=
"
└──
"
else
:
assembly_padding
+=
"
├──
"
print
(
f
"
{
assembly_padding
}{
root
}
"
)
"""
Recursively print child components.
"""
"""
Recursively print child components.
"""
for
i
,
assembly
in
enumerate
(
root
.
assemblies
):
for
i
,
assembly
in
enumerate
(
root
.
assemblies
):
is_last
_
=
i
==
len
(
root
.
assemblies
)
-
1
and
len
(
root
.
components
)
==
0
is_last
=
i
==
len
(
root
.
assemblies
)
-
1
and
len
(
root
.
components
)
==
0
print_assembly_tree
(
assembly
,
level
+
1
,
is_last
_
)
print_assembly_tree
(
assembly
,
[
*
level
s
,
not
is_last
]
)
"""
Print the components.
"""
"""
Print the components.
"""
for
i
,
item
in
enumerate
(
root
.
components
):
for
i
,
component
in
enumerate
(
root
.
components
):
component_padding
=
"
│
"
*
level
if
not
is_last
else
"
"
component_padding
=
"
├──
"
if
i
<
len
(
root
.
components
)
-
1
else
"
└──
"
component_padding
+=
"
├──
"
if
i
<
len
(
root
.
components
)
-
1
else
"
└──
"
print
(
f
"
{
connection_padding
}{
component_padding
}{
component
}
"
)
print
(
f
"
{
component_padding
}{
item
}
"
)
def
correct_aggregation_hierarchy
(
root
:
LegoAssembly
,
strict
:
bool
=
False
):
def
correct_aggregation_hierarchy
(
root
:
LegoAssembly
,
strict
:
bool
=
False
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment