Skip to content
Snippets Groups Projects
Commit b4cf14b2 authored by Meck, Tobias's avatar Meck, Tobias :speech_balloon:
Browse files

Add markdown ĺine to put screenshot in example notebook

in the last commit only the image was pushed but not the necessary code snippet
parent 8ade60c5
No related branches found
No related tags found
No related merge requests found
Pipeline #1085763 passed
%% Cell type:markdown id:c9328cd1 tags:
# FAIRe Qualitäts-KPI
%% Cell type:markdown id:2ee8746d tags:
## Einführung
FAIR Quality 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
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
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
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:
## Eigene Module und Minimalbeispiel
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.
Im Modul `classes` befinden sich die komplette Klassen und Funktionen zur Verwendung.
Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen.
%% Cell type:markdown id:670118b3 tags:
#### Versuchsaufbau:
Die folgende Abbildung zeugt den Versuchsaufbau für das Tretrollerbeispiel 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:
%% Cell type:markdown id:2f969ed9 tags:
![Tretroller in LeoCAD](figures/leocad_screenshot_cut.png)
%% Cell type:markdown id:6d3310be tags:
### Modul classes
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.
Wir bauen aus Achse, Rahmen und Reifen einen Tretroller zusammen.
%% Cell type:code id:b2778dee tags:
``` python
# import modules
import json
import pprint
from functions import calculation_rules
# Importing all modules one by one to provide an overview
# The next commented line would provide the same result in one line
# from functions.classes import *
from functions.classes import LegoComponent
from functions.classes import LegoAssembly
from functions.classes import AggregationLayer
from functions.classes import KPIEncoder
from functions.classes import print_assembly_tree
# When you are writing code yourself later, you might want to copy
# these imports to avoid rerunning the full notebook after restart
```
%% Cell type:code id:0b1f9aff tags:
``` python
# Create the wheels and axles as single components first
# Look up the specific item you want from the provided json files,
# we can load the full file into a dict
with open("datasheets/axles.json") as json_file:
axles = json.load(json_file)
# Pick a specific axle via its 'item number'
print(axles["32073"])
# Create the component with the dict:
front_axle = LegoComponent("front axle", axles["32073"])
# Both label and the data dict are optional parameters.
# You can view, add or edit the properties just any dict:
print(front_axle.properties["label"])
front_axle.properties["color"] = "grey"
# Create the second axle
back_axle = LegoComponent()
back_axle.properties["label"] = "back axle"
back_axle.properties.update(axles["32073"])
# Do not use = here, otherwise you'd overwrite existing properties.
# Instead use update to have all entries added to properties
back_axle.properties["color"] = "grey"
# Viewing dicts in one line is not easy to read,
# a better output comes with pretty print (pprint):
pprint.pprint(back_axle.properties)
```
%% Cell type:code id:b4a8e8c8 tags:
``` python
# Now wheels
with open("datasheets/wheels.json") as json_file:
wheels = json.load(json_file)
# 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.
# front_wheel = LegoComponent(
# 'front wheel', wheels['2903c02'], {'color':'yellow'},winter='true')
front_wheel = LegoComponent(
"front wheel", wheels["2903c02"], surface="rough", paint="glossy"
)
pprint.pprint(front_wheel.properties)
# We included a clone function to both Lego classes, so you can easily
# create duplicate objects. Passing the new label is optional
back_wheel = front_wheel.clone("back wheel")
```
%% Cell type:code id:25bd06c5 tags:
``` python
# Create subassemblies and add the wheels and axles
# The AggregationLayer must be used, passing the label
# or additional properties is optional
front_wheel_assembly = LegoAssembly(
AggregationLayer.SUBASSEMBLY,
"front wheel assembly",
assembly_method="stick together like lego blocks",
)
# Add LegoComponents to the LegoAssembly, single or as list
front_wheel_assembly.add([front_wheel, front_axle])
# You can access the components of an assembly like this:
print(front_wheel_assembly.components[1].properties["label"])
# Assemblies can be cloned as well (including their children),
# but don't forget to adjust labels or you might be stuck with
# a 'front wheel' in your 'back wheel assembly'
# Stick together back wheel parts
back_wheel_assembly = LegoAssembly(
AggregationLayer.SUBASSEMBLY, "back wheel assembly"
)
back_wheel_assembly.add([back_wheel, back_axle])
```
%% Cell type:code id:2b6648e1 tags:
``` python
# Create frame component and assemble the system
with open("datasheets/frame.json") as json_file:
frame = json.load(json_file)
scooter_frame = LegoComponent("scooter frame", frame["3703"], {"color": "red"})
# The scooter is our system level assembly, you can choose the AggregationLayer
# But the hiercarchy (SYSTEM > ASSEMBLY > SUBASSEMBLY) must be in order.
# Components can be added to all LegoAssembly objects
scooter = LegoAssembly(
AggregationLayer.SYSTEM,
"scooter",
manufacturer="FST",
comment="Faster! Harder! Scooter!",
)
# add frame and subassemblies
scooter.add([scooter_frame, front_wheel_assembly, back_wheel_assembly])
```
%% Cell type:code id:71324895 tags:
``` python
# Look at the assembly
# We can get all LegoComponents from this assembly.
# Without parameter 'max_depth' only direct children will be listed.
scooter.get_component_list(5)
```
%% Cell type:markdown id:001f1c77 tags:
### Modul calculation_rules
Um für unser System "Tretroller" ein KPI für das Gesamtgewicht zu erzeugen, wurde in `functions.calculation_rules` die Funktion `kpi_sum` definiert. Zusammen mit den Hilfsfunktionen der Klasse können wir nun das KPI Gewicht für das System hinzufügen. Die Massen der einzelnen Komponenten sind in den Datenblättern unter `mass [g]` enthalten.
%% Cell type:code id:7b60d0fb tags:
``` python
# test the import
calculation_rules.test_function()
```
%% Cell type:code id:fe4edad6 tags:
``` python
# Add mass to assemblies
# List all components' mass
combined_weight = 0
for c in scooter.get_component_list(-1):
combined_weight += c.properties["mass [g]"]
print("Gesamtgewicht: ", combined_weight, "g")
# Add KPI to system
scooter.properties["mass [g]"] = combined_weight
# We can also add the mass to the subassemblies.
# children() returns a dict with a list of added
# components and assemblies.
for a in scooter.children()["assemblies"]:
a_mass = 0
for c in a.get_component_list(-1):
a_mass += c.properties["mass [g]"]
a.properties["mass [g]"] = a_mass
```
%% Cell type:code id:c26b36c8 tags:
``` python
scooter.get_component_list(-1)
```
%% Cell type:code id:4d56419f tags:
``` python
# Look at the full assembly with KPI
# Print the full assembly with all levels
print_assembly_tree(scooter)
```
%% Cell type:code id:b31416d3 tags:
``` python
# Dump to json file with to_dict() and KPIEncoder
with open("scooter.json", "w") as fp:
json.dump(scooter.to_dict(), fp, cls=KPIEncoder)
# full view is too big for Juypter (try it)
# pprint.pprint(scooter.to_dict())
```
%% Cell type:markdown id:53793ae8 tags:
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'.
%% Cell type:markdown id:92c77051 tags:
#### Zusätzliche Details
%% Cell type:code id:b91fed73 tags:
``` python
# Each child knows its parent
first_child = scooter.children()["assemblies"][0]
print("Child:", first_child)
print("Parent:", first_child.parent)
# Also we can access the "top" parent
latest_child = first_child.children()["components"][0]
print("Top parent: ", latest_child.get_root_assembly())
# Each part created has a unique identifier (the long number in [])
# Don't try add the identical part again.
```
......
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