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
Stumpe, Marius
quality-kpi
Commits
27b06a89
Commit
27b06a89
authored
2 years ago
by
Hock, Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
remove parameters and make properties mandatory
parent
05e99772
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
functions/classes.py
+16
-33
16 additions, 33 deletions
functions/classes.py
test-classes.py
+1
-1
1 addition, 1 deletion
test-classes.py
with
17 additions
and
34 deletions
functions/classes.py
+
16
−
33
View file @
27b06a89
...
...
@@ -6,11 +6,11 @@ from enum import Enum, auto
import
uuid
from
typing
import
List
,
Dict
import
json
import
copy
# TODO
# - Docstrings
# - Beschreibung von Teilen (-> properties) -> Raus aus dem Konstruktor rein in ein dict. (Deep-Copy)
# - Minimalbeispiel für KPIs -> halb umgesetzt -> mit get_components veranschaulichen
# - Erlaube Clone bei Assembly (jedes child muss durch durch Klon ersetzt werden)
# - Änderungen an Beispiel umsetzen
...
...
@@ -39,38 +39,21 @@ class AggregationLayer(Enum):
class
LegoComponent
:
def
__init__
(
self
,
name
:
str
,
category
:
ComponentCategory
,
lego_id
:
str
,
cost
:
float
,
mass
:
float
,
delivery_time
:
int
,
layer
:
AggregationLayer
=
AggregationLayer
.
COMPONENT
,
**
properties
,
self
,
label
:
str
,
properties
:
dict
,
layer
:
AggregationLayer
=
AggregationLayer
.
COMPONENT
,
)
->
None
:
self
.
uuid
:
uuid
.
UUID
=
uuid
.
uuid4
()
self
.
parent
:
None
|
LegoAssembly
=
None
self
.
name
:
str
=
name
self
.
category
:
ComponentCategory
=
category
self
.
lego_id
:
str
=
lego_id
self
.
cost
:
float
=
cost
self
.
mass
:
float
=
mass
self
.
delivery_time
:
int
=
delivery_time
self
.
layer
:
AggregationLayer
=
layer
self
.
label
:
str
=
label
self
.
properties
:
dict
=
properties
self
.
layer
:
AggregationLayer
=
layer
def
clone
(
self
)
->
LegoComponent
:
clone
=
LegoComponent
(
self
.
name
,
self
.
category
,
self
.
lego_id
,
self
.
cost
,
self
.
mass
,
self
.
delivery_time
,
self
.
layer
,
**
self
.
properties
,
)
def
clone
(
self
,
new_description
:
str
=
None
)
->
LegoComponent
:
if
new_description
is
None
:
new_description
=
self
.
label
clone
=
LegoComponent
(
new_description
,
copy
.
deepcopy
(
self
.
properties
),
self
.
layer
)
return
clone
def
get_root_assembly
(
self
):
...
...
@@ -112,16 +95,16 @@ class LegoComponent:
# TODO good repr representation
def
__repr__
(
self
):
return
f
"
LegoComponent
{
self
.
name
}
[
{
self
.
uuid
}
]
"
return
f
"
LegoComponent
{
self
.
label
}
[
{
self
.
uuid
}
]
"
class
LegoAssembly
:
def
__init__
(
self
,
name
:
str
,
layer
:
AggregationLayer
,
**
properties
)
->
None
:
def
__init__
(
self
,
label
:
str
,
properties
:
dict
,
layer
:
AggregationLayer
)
->
None
:
self
.
uuid
:
uuid
.
UUID
=
uuid
.
uuid4
()
self
.
parent
:
None
|
LegoAssembly
=
None
self
.
name
:
str
=
name
self
.
layer
:
AggregationLayer
=
layer
self
.
label
:
str
=
label
self
.
properties
:
dict
=
properties
self
.
layer
:
AggregationLayer
=
layer
self
.
components
:
List
[
LegoComponent
]
=
[]
self
.
assemblies
:
List
[
LegoAssembly
]
=
[]
...
...
@@ -199,7 +182,7 @@ class LegoAssembly:
# TODO find good string representation
def
__repr__
(
self
):
return
f
"
LegoAssembly
{
self
.
name
}
[
{
self
.
uuid
}
]
"
return
f
"
LegoAssembly
{
self
.
label
}
[
{
self
.
uuid
}
]
"
def
print_assembly_tree
(
root
,
level
=
0
,
is_last
=
False
):
...
...
This diff is collapsed.
Click to expand it.
test-classes.py
+
1
−
1
View file @
27b06a89
...
...
@@ -110,7 +110,7 @@ scooterwheel = LegoComponent("Vorderrad", ComponentCategory.WHEEL,
# TODO component with copy of dict from json
# Cloning is necessary because each lego object gets a unique id so you can't use the same part twice
scooterwheel2
=
scooterwheel
.
clone
()
scooterwheel2
.
name
=
"
Hinterrad
"
scooterwheel2
.
description
=
"
Hinterrad
"
print
([
scooterwheel
.
uuid
,
scooterwheel2
.
uuid
])
...
...
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