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
84927c3a
Commit
84927c3a
authored
2 years ago
by
Hock, Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
minimal example for a car
parent
41cbe8fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test-legoclasses.py
+33
-18
33 additions, 18 deletions
test-legoclasses.py
with
33 additions
and
18 deletions
test-legoclasses.py
+
33
−
18
View file @
84927c3a
# import functions.lego_classes as lego_classes
from
functions.lego_classes
import
LegoItem
from
functions.lego_classes
import
LegoComponent
from
functions.lego_classes
import
*
import
json
import
pprint
# Test manually creating some item and components
item1
=
LegoItem
(
1
,
0.10
,
10
)
item2
=
LegoItem
(
3
,
0.30
,
30
)
item3
=
LegoItem
(
2
,
0.2
,
20
)
battery
=
LegoComponent
(
"
nice battery
"
,
ComponentCategory
.
BATTERY
,
"
bat42
"
,
1
,
2
,
3
)
motor
=
LegoComponent
(
"
motor goes brrr
"
,
ComponentCategory
.
MOTOR
,
"
motor
"
,
1
,
2
,
3
)
wheel
=
LegoComponent
(
"
much round wheel
"
,
ComponentCategory
.
WHEEL
,
"
round
"
,
1
,
2
,
3
)
car
=
LegoAssembly
(
"
Car
"
,
AggregationLayer
.
SYSTEM
)
chassis
=
LegoAssembly
(
"
Chassis
"
,
AggregationLayer
.
ASSEMBLY
)
door1
=
LegoAssembly
(
"
Door 1
"
,
AggregationLayer
.
SUBASSEMBLY
)
door2
=
LegoAssembly
(
"
Door 2
"
,
AggregationLayer
.
SUBASSEMBLY
)
chassis
.
add_assembly
(
door1
)
chassis
.
add_assembly
(
door2
)
engine
=
LegoAssembly
(
"
Engine
"
,
AggregationLayer
.
ASSEMBLY
)
engine
.
add_component
(
motor
.
clone
())
fuel_tank
=
LegoAssembly
(
"
Fuel Tank
"
,
AggregationLayer
.
ASSEMBLY
)
fuel_tank
.
add_component
(
battery
.
clone
())
wheels
=
LegoAssembly
(
"
Wheels
"
,
AggregationLayer
.
ASSEMBLY
)
for
_
in
range
(
4
):
wheels
.
add_component
(
wheel
.
clone
())
car
.
add_assembly
(
chassis
)
car
.
add_assembly
(
engine
)
car
.
add_assembly
(
fuel_tank
)
car
.
add_assembly
(
wheels
)
component1
=
LegoComponent
()
# component1.add_item(item1)
component2
=
LegoComponent
(
item2
)
print_assembly_tree
(
car
)
componentall
=
LegoComponent
([
item1
,
item2
],[])
# Some combinations might result in errors
# component3 = LegoComponent(item3,component1)
# component3.add(item2) # Can't really use an item twice
# component3.add(component2)
print
(
componentall
.
items
)
x
=
componentall
.
children
()
print
(
x
)
# Dump to json file
with
open
(
"
car.json
"
,
"
w
"
)
as
fp
:
json
.
dump
(
car
.
to_dict
(),
fp
,
cls
=
KPIEncoder
)
p
rint
(
type
(
x
))
alist
=
[
"
abc
"
,
"
def
"
]
p
print
.
pprint
(
car
.
to_dict
(
))
pass
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