Skip to content
Snippets Groups Projects
Commit 70ac6b34 authored by Lamm, Sascha's avatar Lamm, Sascha :cow2:
Browse files

Updated minimal solution to use updated library and datasheets.

parent 63df4362
No related branches found
No related tags found
No related merge requests found
0
0 Name: New Model.ldr
0 Author:
1 71 180 -48 0 1 0 0 0 1 0 0 0 1 56904.dat
1 0 180 -48 0 1 0 0 0 1 0 0 0 1 30699.dat
1 4 260 -57.8657 -50 1 0 0 0 1 0 0 0 1 2730.dat
1 71 180 -48 -30 0 0 1 0 1 0 -1 0 0 32073.dat
1 47 180 -48 -30 1 0 0 0 1 0 0 0 1 3713.dat
1 47 180 -48 -70 1 0 0 0 1 0 0 0 1 3713.dat
1 71 340 -48 0 1 0 0 0 1 0 0 0 1 56904.dat
1 0 340 -48 0 1 0 0 0 1 0 0 0 1 30699.dat
1 71 340 -48 -30 0 0 1 0 1 0 -1 0 0 32073.dat
1 47 340 -48 -30 1 0 0 0 1 0 0 0 1 3713.dat
1 47 340 -48 -70 1 0 0 0 1 0 0 0 1 3713.dat
1 47 220 -128 -70 1 0 0 0 0 1 0 -1 0 40490.dat
1 47 220 -208 -70 0 0 1 0 1 0 -1 0 0 32073.dat
1 47 220 -208 -25 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -35 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -45 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -55 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -85 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -95 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -105 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -208 -115 -1 0 0 0 1 0 0 0 -1 32123.dat
1 47 220 -48 -60 0 0 1 0 -1 0 1 0 0 3673.dat
figures/leocad_screenshot_cut.png

364 KiB | W: | H:

figures/leocad_screenshot_cut.png

220 KiB | W: | H:

figures/leocad_screenshot_cut.png
figures/leocad_screenshot_cut.png
figures/leocad_screenshot_cut.png
figures/leocad_screenshot_cut.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -57,7 +57,7 @@ class LegoComponent: ...@@ -57,7 +57,7 @@ class LegoComponent:
to None. to None.
datasheet (dict[str, Any], optional): Metadata describing the component, datasheet (dict[str, Any], optional): Metadata describing the component,
read from datasheet. Defaults to None. read from datasheet. Defaults to None.
more_properties tuple of dict, dict more_properties (dict[str, Any])
Additional dictionaries representing custom properties. Additional dictionaries representing custom properties.
kwargs kwargs
Arbitrary keyword arguments representing custom properties. Arbitrary keyword arguments representing custom properties.
......
%% Cell type:markdown id:c9328cd1 tags: %% Cell type:markdown id:c9328cd1 tags:
# FAIRe Qualitäts-KPIs # FAIRe Qualitäts-KPIs
%% Cell type:markdown id:2ee8746d tags: %% Cell type:markdown id:2ee8746d tags:
## Einführung ## Einführung
FAIRe Qualitäts-KPIs schaffen eine transparente und nachvollziehbare Entscheidungsgrundlage. In dieser Lerneinheit sollen sie die Methodik erlernen, indem sie LEGO-Autos zusammenbauen, deren Quality KPIs bestimmen und miteinander vergleichen. FAIRe Qualitäts-KPIs schaffen eine transparente und nachvollziehbare Entscheidungsgrundlage. In dieser Lerneinheit sollen sie die Methodik erlernen, indem sie LEGO-Autos zusammenbauen, deren Quality KPIs bestimmen und miteinander vergleichen.
### Werkzeug für den Zusammenbau ### Werkzeug für den Zusammenbau
Der Zusammenbau der Autos erfolgt virtuell. Als Werkzeug steht Ihnen das Modul `classes` zur Verfügung. In diesem sind unterschiedliche Klassen und Methoden implementiert (Objektorientierung). Sie erzeugen jeweils Objekte der Klassen. Ein Objekt ist dabei die virtuelle Abbildung eines realen Bauteiles. Die Eigenschaften des Bauteiles werden über die Eigenschaften des Objektes abgebildet. Der Zusammenbau der Autos erfolgt virtuell. Als Werkzeug steht Ihnen das Modul `classes` zur Verfügung. In diesem sind unterschiedliche Klassen und Methoden implementiert (Objektorientierung). Sie erzeugen jeweils Objekte der Klassen. Ein Objekt ist dabei die virtuelle Abbildung eines realen Bauteiles. Die Eigenschaften des Bauteiles werden über die Eigenschaften des Objektes abgebildet.
### Berechnung der Quality KPIs ### Berechnung der Quality KPIs
KPIs (Key Performance Indikatoren) sind Kenngrößen des Systems. Sie werden über Berechnungsvorschriften bestimmt. Diese Berechnungsvorschriften sind von Ihnen als python-Funktionen im Modul `calculation_rules` zu implementieren. KPIs (Key Performance Indikatoren) sind Kenngrößen des Systems. Sie werden über Berechnungsvorschriften bestimmt. Diese Berechnungsvorschriften sind von Ihnen als python-Funktionen im Modul `calculation_rules` zu implementieren.
### Datenblätter ### Datenblätter
Für den Zusammenbau stehen Ihnen verschiedene Bauteile in unterschiedlichen Ausführungen zur Verfügung. Sie nutzen die Datenblätter, die als `json-Dateien` zur Verfügung gestellt werden, um Ihre Autos zusammenzubauen. Für den Zusammenbau stehen Ihnen verschiedene Bauteile in unterschiedlichen Ausführungen zur Verfügung. Sie nutzen die Datenblätter, die als `json-Dateien` zur Verfügung gestellt werden, um Ihre Autos zusammenzubauen.
%% Cell type:markdown id:1c702114 tags: %% Cell type:markdown id:1c702114 tags:
## Eigene Module und Minimalbeispiel ## Eigene Module und Minimalbeispiel
Für die Ausarbeitung nutzen wir zwei eigene Module (Python-Dateien), die im Ordner `functions` gespeichert sind. Für die Ausarbeitung nutzen wir zwei eigene Module (Python-Dateien), die im Ordner `functions` gespeichert sind.
Das Modul `calculation_rules` erweitern Sie während der Ausarbeitung. Um die Änderungen zu nutzen, müssen Sie das Notebook neu starten. Das Modul `calculation_rules` erweitern Sie während der Ausarbeitung. Um die Änderungen zu nutzen, müssen Sie das Notebook neu starten.
Im Modul `classes` befinden sich die komplette Klassen und Funktionen zur Verwendung. Im Modul `classes` befinden sich die komplette Klassen und Funktionen zur Verwendung.
Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen. Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen.
%% Cell type:markdown id:670118b3 tags: %% Cell type:markdown id:670118b3 tags:
#### Versuchsaufbau: #### Versuchsaufbau:
Die folgende Abbildung zeigt den Versuchsaufbau des Minimalbeispiels in LeoCAD. Die transparenten Bauteile sind dabei nicht Teil des hier erläuterten Zusammenbaus, können aber mit dem zur Verfügung gestellten Baukasten ergänzt werden: Die folgende Abbildung zeigt den Versuchsaufbau des Minimalbeispiels in LeoCAD. Die transparenten Bauteile sind dabei nicht Teil des hier erläuterten Zusammenbaus, können aber mit dem zur Verfügung gestellten Baukasten ergänzt werden:
![Minimalbeispiel aus LeoCAD](figures/leocad_screenshot_cut.png)
%% Cell type:markdown id:2f969ed9 tags:
![Tretroller in LeoCAD](figures/leocad_screenshot_cut.png)
%% Cell type:markdown id:6d3310be tags: %% Cell type:markdown id:6d3310be tags:
### Modul classes ### Modul classes
Enthält `LegoComponent, LegoAssembly, AggregationLayer, KPIEncoder` und die Funktion `print_assembly_tree`. Enthält `LegoComponent, LegoAssembly, AggregationLayer, KPIEncoder` und die Funktion `print_assembly_tree`.
`LegoComponent` bildet einzelne Komponenten ab, während `LegoAssembly` zusammengesetzte Aggregationsebenen abdeckt, also Bauteil, Baugruppe und System. Zur Unterscheidung dient die Klasse `AggregationLayer`, diese ist für `LegoComponent` immer `Component` (Komponente), muss für `LegoAssembly` entsprechend auf `SYSTEM` (System) , `ASSEMBLY` (Baugruppe) oder `SUBASSEMBLY` (Bauteil) gesetzt werden. `LegoComponent` bildet einzelne Komponenten ab, während `LegoAssembly` zusammengesetzte Aggregationsebenen abdeckt, also Bauteil, Baugruppe und System. Zur Unterscheidung dient die Klasse `AggregationLayer`, diese ist für `LegoComponent` immer `Component` (Komponente), muss für `LegoAssembly` entsprechend auf `SYSTEM` (System) , `ASSEMBLY` (Baugruppe) oder `SUBASSEMBLY` (Bauteil) gesetzt werden.
Wir bauen aus Achse, Rahmen und Reifen einen Tretroller zusammen. Wir bauen aus Achse, Rahmen und Reifen einen Tretroller zusammen.
%% Cell type:code id:b2778dee tags: %% Cell type:code id:b2778dee tags:
``` python ``` python
# import modules # import modules
import json import json
import pprint import pprint
from functions import calculation_rules from functions import calculation_rules
# Importing all modules one by one to provide an overview # Importing all modules one by one to provide an overview
# The next commented line would provide the same result in one line # The next commented line would provide the same result in one line
# from functions.classes import * # from functions.classes import *
from functions.classes import LegoComponent from functions.classes import LegoComponent
from functions.classes import LegoAssembly from functions.classes import LegoAssembly
from functions.classes import AggregationLayer from functions.classes import AggregationLayer
from functions.classes import KPIEncoder from functions.classes import KPIEncoder
from functions.classes import print_assembly_tree from functions.classes import print_assembly_tree
# When you are writing code yourself later, you might want to copy # When you are writing code yourself later, you might want to copy
# these imports to avoid rerunning the full notebook after restart # these imports to avoid rerunning the full notebook after restart
``` ```
%% Cell type:code id:0b1f9aff tags: %% Cell type:code id:0b1f9aff tags:
``` python ``` python
# Create the wheels and axles as single components first # Create the wheels and axles as single components first
# Look up the specific item you want from the provided json files, # Look up the specific item you want from the provided json files,
# we can load the full file into a dict # we can load the full file into a dict
with open("datasheets/axles.json") as json_file: with open("datasheets/axles.json") as json_file:
axles = json.load(json_file) axles = json.load(json_file)
# Pick a specific axle via its 'item number' # Pick a specific axle via its 'item number'
print(axles["32073"]) print(axles["32073"])
# Create the component with the dict: # Create the component with the dict:
front_axle = LegoComponent("front axle", axles["32073"]) front_axle = LegoComponent("front axle", axles["32073"])
# Both label and the data dict are optional parameters. # Both label and the data dict are optional parameters.
# You can view, add or edit properties: # You can view, add or edit properties:
print(front_axle.properties["label"]) print(front_axle.properties["label"])
front_axle.properties["color"] = "grey" front_axle.properties["color"] = "light bluish grey"
# Create the second axle # Create the second axle
back_axle = LegoComponent() back_axle = LegoComponent()
back_axle.properties["label"] = "back axle" back_axle.properties["label"] = "back axle"
back_axle.properties.update(axles["32073"]) back_axle.properties.update(axles["32073"])
# Do not use = here, otherwise you'd overwrite existing properties. # Do not use = here, otherwise you'd overwrite existing properties.
# Instead use update to have all entries added to properties # Instead use update to have all entries added to properties
back_axle.properties["color"] = "grey" back_axle.properties["color"] = "light bluish grey"
# Viewing dicts in one line is not easy to read, # Viewing dicts in one line is not easy to read,
# a better output comes with pretty print (pprint): # a better output comes with pretty print (pprint):
pprint.pprint(back_axle.properties) pprint.pprint(back_axle.properties)
``` ```
%% Output %% Output
{'item number': 32073, 'item description': 'Axle 5 studs', 'category': 'axle', 'price [Euro]': 0.001, 'mass [g]': 0.66, 'delivery time [days]': 3, 'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=32073#T=S&O={%22iconly%22:0}', 'dimension [studs]': 5} {'item number': 32073, 'item description': 'Axle 5 studs', 'category': 'axle', 'price [Euro]': 0.001, 'mass [g]': 0.66, 'environmental impact [kg CO2e /kg]': 11.03, 'delivery time [days]': 3, 'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=32073', 'dimension [studs]': 5}
front axle front axle
{'category': 'axle', {'category': 'axle',
'color': 'grey', 'color': 'grey',
'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=32073#T=S&O={%22iconly%22:0}', 'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=32073',
'delivery time [days]': 3, 'delivery time [days]': 3,
'dimension [studs]': 5, 'dimension [studs]': 5,
'environmental impact [kg CO2e /kg]': 11.03,
'item description': 'Axle 5 studs', 'item description': 'Axle 5 studs',
'item number': 32073, 'item number': 32073,
'label': 'back axle', 'label': 'back axle',
'mass [g]': 0.66, 'mass [g]': 0.66,
'price [Euro]': 0.001} 'price [Euro]': 0.001}
%% Cell type:code id:b4a8e8c8 tags: %% Cell type:code id:b4a8e8c8 tags:
``` python ``` python
# Now wheels # Now wheels
with open("datasheets/wheels.json") as json_file: # A wheel consists of a rim (Felge) and a tire (Reifen)
wheels = json.load(json_file) with open("datasheets/rims.json") as json_file:
rims = json.load(json_file)
with open("datasheets/tires.json") as json_file:
tires = json.load(json_file)
# Adding the color here already as dict, and the surface as key-value argument. # Adding the color here already as dict, and the surface as key-value argument.
# Multiple of both parameters are supported, but only in this order. # Multiple of both parameters are supported, but only in this order.
# front_wheel = LegoComponent( # front_wheel = LegoComponent(
# 'front wheel', wheels['2903c02'], {'color':'yellow'},winter='true') # 'front wheel', wheels['2903c02'], {'color':'yellow'},winter='true')
front_wheel = LegoComponent( front_rim = LegoComponent("front rim", rims["56904"], surface="rough", paint="glossy")
"front wheel", wheels["2903c02"], surface="rough", paint="glossy" front_tire = LegoComponent("front tire", tires["30699"], winter=True)
) pprint.pprint(front_rim.properties)
pprint.pprint(front_wheel.properties)
# We included a clone function to both Lego classes, so you can easily # We included a clone function to both Lego classes, so you can easily
# create duplicate objects. Passing the new label is optional # create duplicate objects. Passing the new label is optional
back_wheel = front_wheel.clone("back wheel") back_rim = front_rim.clone("back rim")
back_tire = front_tire.clone("back tire")
``` ```
%% Output %% Output
{'category': 'wheel', {'category': 'rim',
'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=2903c02#T=C', 'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=56904',
'delivery time [days]': 5, 'delivery time [days]': 5,
'diameter [mm]': 81.6, 'diameter [mm]': 30.0,
'item description': 'wheel 81,6', 'environmental impact [kg CO2e /kg]': 32.06,
'item number': '2903c02', 'item description': 'Wheel 30mm D. x 14mm',
'label': 'front wheel', 'item number': 56904,
'mass [g]': 30.0, 'label': 'front rim',
'mass [g]': 4.1,
'paint': 'glossy', 'paint': 'glossy',
'price [Euro]': 1.31, 'price [Euro]': 0.01,
'related items': 2902, 'related items': 30699,
'surface': 'rough'} 'surface': 'rough'}
%% Cell type:code id:25bd06c5 tags: %% Cell type:code id:25bd06c5 tags:
``` python ``` python
# Create subassemblies and add the wheels and axles # Create subassemblies and add the wheels and axles
# The AggregationLayer must be used, passing the label # The AggregationLayer must be used, passing the label
# or additional properties is optional # or additional properties is optional
front_wheel_assembly = LegoAssembly( front_wheel_assembly = LegoAssembly(
AggregationLayer.SUBASSEMBLY, AggregationLayer.SUBASSEMBLY,
"front wheel assembly", "front wheel assembly",
assembly_method="stick together like lego blocks", assembly_method="stick together like lego blocks",
) )
# Add LegoComponents to the LegoAssembly, single or as list # Add LegoComponents to the LegoAssembly, single or as list
front_wheel_assembly.add([front_wheel, front_axle]) front_wheel_assembly.add([front_rim, front_tire])
# You can access the components of an assembly like this: # You can access the components of an assembly like this:
print(front_wheel_assembly.components[1].properties["label"]) print(front_wheel_assembly.components[1].properties["label"])
# Assemblies can be cloned as well (including their children), # Assemblies can be cloned as well (including their children),
# but don't forget to adjust labels or you might be stuck with # but don't forget to adjust labels or you might be stuck with
# a 'front wheel' in your 'back wheel assembly' # a 'front wheel' in your 'back wheel assembly'
# Stick together back wheel parts # Stick together back wheel parts
back_wheel_assembly = LegoAssembly( back_wheel_assembly = LegoAssembly(
AggregationLayer.SUBASSEMBLY, "back wheel assembly" AggregationLayer.SUBASSEMBLY, "back wheel assembly"
) )
back_wheel_assembly.add([back_wheel, back_axle]) back_wheel_assembly.add([back_rim, back_tire])
# Now combine wheels and axles
front_axle_assembly = LegoAssembly(
AggregationLayer.ASSEMBLY, "front axle assembly"
)
front_axle_assembly.add([front_wheel_assembly, front_axle])
back_axle_assembly = LegoAssembly(
AggregationLayer.ASSEMBLY, "back axle assembly"
)
back_axle_assembly.add([back_wheel_assembly, back_axle])
``` ```
%% Output %% Output
front axle front tire
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[6], line 35
30 front_axle_assembly.add([front_wheel_assembly, front_axle])
32 back_axle_assembly = LegoAssembly(
33 AggregationLayer.ASSEMBLY, "back axle assembly"
34 )
---> 35 back_axle_assembly.add([back_axle_assembly, back_axle])
File c:\Users\Lamm\Documents\02_Areas\Praktikum_Digitalisierung\01_quality-kpi_dev\functions\classes.py:374, in LegoAssembly.add(self, part)
372 elif isinstance(part, list):
373 for p in part:
--> 374 self.add(p)
375 else:
376 raise TypeError(
377 f"Argument should be of types {LegoAssembly.__name__}, "
378 f"{LegoComponent.__name__} or a list of them. "
379 f"Got {type(part).__name__} instead."
380 )
File c:\Users\Lamm\Documents\02_Areas\Praktikum_Digitalisierung\01_quality-kpi_dev\functions\classes.py:369, in LegoAssembly.add(self, part)
356 """
357 Adds either a Lego component, a subassembly or a (mixed) list of them to the
358 current assembly. Uses internal functions add_component() and add_assembly().
(...)
366 instance, or a (mixed) list of them.
367 """
368 if isinstance(part, LegoComponent):
--> 369 self.add_component(part)
370 elif isinstance(part, LegoAssembly):
371 self.add_assembly(part)
File c:\Users\Lamm\Documents\02_Areas\Praktikum_Digitalisierung\01_quality-kpi_dev\functions\classes.py:310, in LegoAssembly.add_component(self, component)
304 if not isinstance(component, LegoComponent):
305 raise TypeError(
306 f"Argument should be of type {LegoComponent.__name__}, "
307 f"got {type(component).__name__} instead."
308 )
--> 310 if self.get_root_assembly().contains_uuid(component._uuid):
311 raise AssertionError(
312 f"This assembly or a subassembly already contains "
313 f"the component with ID "
314 f"{component._uuid}."
315 )
316 component._parent = self
File c:\Users\Lamm\Documents\02_Areas\Praktikum_Digitalisierung\01_quality-kpi_dev\functions\classes.py:439, in LegoAssembly.get_root_assembly(self)
431 """
432 Returns the root LegoAssembly of the current assembly by recursively
433 searching up the tree until the top-most parent (the root) is found.
(...)
436 The root LegoAssembly of the current LegoAssembly instance.
437 """
438 current_assembly = self
--> 439 while current_assembly._parent is not None:
440 current_assembly = current_assembly._parent
441 return current_assembly
KeyboardInterrupt:
%% Cell type:code id:2b6648e1 tags: %% Cell type:code id:2b6648e1 tags:
``` python ``` python
# Create frame component and assemble the system # Create frame component and assemble the system
with open("datasheets/frame.json") as json_file: with open("datasheets/frame.json") as json_file:
frame = json.load(json_file) frame = json.load(json_file)
scooter_frame = LegoComponent("scooter frame", frame["3703"], {"color": "red"}) scooter_frame = LegoComponent("scooter frame", frame["3703"], {"color": "red"})
# The scooter is our system level assembly, you can choose the AggregationLayer # The scooter is our system level assembly, you can choose the AggregationLayer
# But the hiercarchy (SYSTEM > ASSEMBLY > SUBASSEMBLY) must be in order. # But the hiercarchy (SYSTEM > ASSEMBLY > SUBASSEMBLY) must be in order.
# Components can be added to all LegoAssembly objects # Components can be added to all LegoAssembly objects
scooter = LegoAssembly( scooter = LegoAssembly(
AggregationLayer.SYSTEM, AggregationLayer.SYSTEM,
"scooter", "scooter",
manufacturer="FST", manufacturer="FST",
comment="Faster! Harder! Scooter!", comment="Faster! Harder! Scooter!",
) )
# add frame and subassemblies # add frame and subassemblies
scooter.add([scooter_frame, front_wheel_assembly, back_wheel_assembly]) scooter.add([scooter_frame, front_wheel_assembly, back_wheel_assembly])
``` ```
%% Cell type:code id:71324895 tags: %% Cell type:code id:71324895 tags:
``` python ``` python
# Look at the assembly # Look at the assembly
# We can get all LegoComponents from this assembly. # We can get all LegoComponents from this assembly.
# If parameter 'max_depth' is set to 0, only direct children will be listed: # If parameter 'max_depth' is set to 0, only direct children will be listed:
print(scooter.get_component_list(max_depth=0)) print(scooter.get_component_list(max_depth=0))
# If it is set to -1 (default), all LegoComponents are listed: # If it is set to -1 (default), all LegoComponents are listed:
print(scooter.get_component_list()) print(scooter.get_component_list())
``` ```
%% Output %% Output
[LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460]] [LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460]]
[LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460], LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b], LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e], LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b], LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b]] [LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460], LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b], LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e], LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b], LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b]]
%% Cell type:markdown id:001f1c77 tags: %% Cell type:markdown id:001f1c77 tags:
### Modul calculation_rules ### Modul calculation_rules
Um für unser System "Tretroller" einen KPI zu erzeugen, wird die Masse des Systems betrachtet. Die Masse der einzelnen Komponenten ist in den Datenblättern unter `mass [g]` enthalten. Um für unser System "Tretroller" einen KPI zu erzeugen, wird die Masse des Systems betrachtet. Die Masse der einzelnen Komponenten ist in den Datenblättern unter `mass [g]` enthalten.
%% Cell type:code id:7b60d0fb tags: %% Cell type:code id:7b60d0fb tags:
``` python ``` python
# test the import # test the import
calculation_rules.test_function() calculation_rules.test_function()
``` ```
%% Output %% Output
You called the test function. You called the test function.
%% Cell type:code id:fe4edad6 tags: %% Cell type:code id:fe4edad6 tags:
``` python ``` python
total_mass = calculation_rules.kpi_mass(scooter) total_mass = calculation_rules.kpi_mass(scooter)
print("Gesamtmasse: ", total_mass, "g") print("Gesamtmasse: ", total_mass, "g")
# Add KPI to system # Add KPI to system
scooter.properties["mass [g]"] = total_mass scooter.properties["mass [g]"] = total_mass
# We can also add the mass to the subassemblies. # We can also add the mass to the subassemblies.
# children() returns a dict with a list of added # children() returns a dict with a list of added
# components and assemblies. # components and assemblies.
for a in scooter.children()["assemblies"]: for a in scooter.children()["assemblies"]:
a_mass = 0 a_mass = 0
for c in a.get_component_list(-1): for c in a.get_component_list(-1):
a_mass += c.properties["mass [g]"] a_mass += c.properties["mass [g]"]
a.properties["mass [g]"] = a_mass a.properties["mass [g]"] = a_mass
``` ```
%% Output %% Output
Gesamtmasse: 67.19 g Gesamtmasse: 67.19 g
%% Cell type:code id:c26b36c8 tags: %% Cell type:code id:c26b36c8 tags:
``` python ``` python
scooter.get_component_list(-1) scooter.get_component_list(-1)
``` ```
%% Output %% Output
[LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460], [LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460],
LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b], LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b],
LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e], LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e],
LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b], LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b],
LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b]] LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b]]
%% Cell type:code id:4d56419f tags: %% Cell type:code id:4d56419f tags:
``` python ``` python
# Look at the full assembly with KPI # Look at the full assembly with KPI
# Print the full assembly with all levels # Print the full assembly with all levels
print_assembly_tree(scooter) print_assembly_tree(scooter)
``` ```
%% Output %% Output
LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662] LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662]
├── LegoAssembly front wheel assembly [e02a87d2-cb0b-4695-b237-9ca17f9611da] ├── LegoAssembly front wheel assembly [e02a87d2-cb0b-4695-b237-9ca17f9611da]
│ ├── LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b] │ ├── LegoComponent front wheel [b03ce5b5-9c6c-4315-a67b-902c729c3d7b]
│ └── LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e] │ └── LegoComponent front axle [64771daf-733a-4a2a-8520-9fa94259e50e]
├── LegoAssembly back wheel assembly [db5db4c5-36c3-4b90-88eb-299c46a30049] ├── LegoAssembly back wheel assembly [db5db4c5-36c3-4b90-88eb-299c46a30049]
│ ├── LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b] │ ├── LegoComponent back wheel [8fcb7db9-6fec-4e70-b274-0c4fe403550b]
│ └── LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b] │ └── LegoComponent back axle [2ce57b96-64b8-48b1-aac8-b0731adaa93b]
└── LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460] └── LegoComponent scooter frame [a90b291e-696c-41c7-b9b8-43d34724b460]
%% Cell type:code id:b31416d3 tags: %% Cell type:code id:b31416d3 tags:
``` python ``` python
# Dump to json file with to_dict() and KPIEncoder # Dump to json file with to_dict() and KPIEncoder
with open("scooter.json", "w") as fp: with open("scooter.json", "w") as fp:
json.dump(scooter.to_dict(), fp, cls=KPIEncoder, indent=4) json.dump(scooter.to_dict(), fp, cls=KPIEncoder, indent=4)
# full view is too big for Juypter (try it) # full view is too big for Juypter (try it)
# pprint.pprint(scooter.to_dict()) # pprint.pprint(scooter.to_dict())
``` ```
%% Cell type:markdown id:53793ae8 tags: %% Cell type:markdown id:53793ae8 tags:
In dieser exportierten json-Datei ('scooter.json') sind die Werte maschinen- und menschenlesbar hinterlegt. In dieser exportierten json-Datei ('scooter.json') sind die Werte maschinen- und menschenlesbar hinterlegt.
Zusammen mit der Berechnungsvorschrift in `calculation_rules` ist auch die Entstehung des KPI nachvollziehbar und wiederverwendbar dokumentiert und damit 'FAIR'. Zusammen mit der Berechnungsvorschrift in `calculation_rules` ist auch die Entstehung des KPI nachvollziehbar und wiederverwendbar dokumentiert und damit 'FAIR'.
%% Cell type:markdown id:92c77051 tags: %% Cell type:markdown id:92c77051 tags:
#### Zusätzliche Details #### Zusätzliche Details
%% Cell type:code id:b91fed73 tags: %% Cell type:code id:b91fed73 tags:
``` python ``` python
# Each child knows its parent # Each child knows its parent
first_child = scooter.children()["assemblies"][0] first_child = scooter.children()["assemblies"][0]
print("Child:", first_child) print("Child:", first_child)
print("Parent:", first_child.parent) print("Parent:", first_child.parent)
# Also we can access the "top" parent # Also we can access the "top" parent
latest_child = first_child.children()["components"][0] latest_child = first_child.children()["components"][0]
print("Top parent: ", latest_child.get_root_assembly()) print("Top parent: ", latest_child.get_root_assembly())
# Each part created has a unique identifier (the long number in []) # Each part created has a unique identifier (the long number in [])
# Don't try to add the identical part again. # Don't try to add the identical part again.
``` ```
%% Output %% Output
Child: LegoAssembly front wheel assembly [e02a87d2-cb0b-4695-b237-9ca17f9611da] Child: LegoAssembly front wheel assembly [e02a87d2-cb0b-4695-b237-9ca17f9611da]
Parent: LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662] Parent: LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662]
Top parent: LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662] Top parent: LegoAssembly scooter [86fdda66-adb2-48c0-b6f8-f6c59d488662]
......
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