Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{
"cells": [
{
"cell_type": "markdown",
"id": "c9328cd1",
"metadata": {},
"source": [
"# FAIRe Qualitäts-KPI"
]
},
{
"cell_type": "markdown",
"id": "2ee8746d",
"metadata": {},
"source": [
"## Einführung\n",
"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.\n",
"\n",
"### Werkzeug für den Zusammenbau\n",
"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.\n",
"\n",
"### Berechnung der Quality KPIs\n",
"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.\n",
"\n",
"### Datenblätter\n",
"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."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1c702114",
"metadata": {},
"source": [
"## Eigene Module und Minimalbeispiel\n",
"Für die Ausarbeitung nutzen wir zwei eigene Module (Python-Dateien), die im Ordner `functions` gespeichert sind.\n",
"Das Modul `calculation_rules` erweitern Sie während der Ausarbeitung. Um die Änderungen zu nutzen, müssen Sie das Notebook neu starten.\n",
"Im Modul `classes` befinden sich die komplette Klassen und Funktionen zur Verwendung.\n",
"\n",
"Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen. "
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "6d3310be",
"metadata": {},
"source": [
"### Modul classes\n",
"Enthält `LegoComponent, LegoAssembly, AggregationLayer, KPIEncoder` und die Funktion `print_assembly_tree`. \n",
"`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.\n",
"\n",
"Wir bauen aus Achse, Rahmen und Reifen einen Tretroller zusammen."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2778dee",
"metadata": {},
"outputs": [],
"source": [
"# import modules\n",
"import json\n",
"import pprint\n",
"from functions import calculation_rules\n",
"\n",
"# Importing all modules one by one to provide an overview\n",
"# The next commented line would provide the same result in one line\n",
"# from functions.classes import *\n",
"from functions.classes import LegoComponent\n",
"from functions.classes import LegoAssembly\n",
"from functions.classes import AggregationLayer\n",
"from functions.classes import KPIEncoder\n",
"from functions.classes import print_assembly_tree\n",
"\n",
"# When you are writing code yourself later, you might want to copy\n",
"# these imports to avoid rerunning the full notebook after restart"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b1f9aff",
"metadata": {},
"outputs": [],
"source": [
"# Create the wheels and axles as single components first\n",
"# Look up the specific item you want from the provided json files,\n",
"# we can load the full file into a dict\n",
"with open(\"datasheets/axles.json\") as json_file:\n",
" axles = json.load(json_file)\n",
"# Pick a specific axle via its 'item number'\n",
"print(axles[\"32073\"])\n",
"\n",
"# Create the component with the dict:\n",
"front_axle = LegoComponent(\"front axle\", axles[\"32073\"])\n",
"# Both label and the data dict are optional parameters.\n",
"# You can view, add or edit the properties just any dict:\n",
"print(front_axle.properties[\"label\"])\n",
"front_axle.properties[\"color\"] = \"grey\"\n",
"\n",
"\n",
"# Create the second axle\n",
"back_axle = LegoComponent()\n",
"back_axle.properties[\"label\"] = \"back axle\"\n",
"back_axle.properties.update(axles[\"32073\"])\n",
"# Do not use = here, otherwise you'd overwrite existing properties.\n",
"# Instead use update to have all entries added to properties\n",
"back_axle.properties[\"color\"] = \"grey\"\n",
"# Viewing dicts in one line is not easy to read,\n",
"# a better output comes with pretty print (pprint):\n",
"pprint.pprint(back_axle.properties)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4a8e8c8",
"metadata": {},
"outputs": [],
"source": [
"# Now wheels\n",
"with open(\"datasheets/wheels.json\") as json_file:\n",
" wheels = json.load(json_file)\n",
"# Adding the color here already as dict, and the surface as key-value argument.\n",
"# Multiple of both parameters are supported, but only in this order.\n",
"# front_wheel = LegoComponent(\n",
"# 'front wheel', wheels['2903c02'], {'color':'yellow'},winter='true')\n",
"\n",
"front_wheel = LegoComponent(\n",
" \"front wheel\", wheels[\"2903c02\"], surface=\"rough\", paint=\"glossy\"\n",
")\n",
"pprint.pprint(front_wheel.properties)\n",
"\n",
"# We included a clone function to both Lego classes, so you can easily\n",
"# create duplicate objects. Passing the new label is optional\n",
"back_wheel = front_wheel.clone(\"back wheel\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25bd06c5",
"metadata": {},
"outputs": [],
"source": [
"# Create subassemblies and add the wheels and axles\n",
"\n",
"# The AggregationLayer must be used, passing the label\n",
"# or additional properties is optional\n",
"front_wheel_assembly = LegoAssembly(\n",
" AggregationLayer.SUBASSEMBLY,\n",
" \"front wheel assembly\",\n",
" assembly_method=\"stick together like lego blocks\",\n",
")\n",
"# Add LegoComponents to the LegoAssembly, single or as list\n",
"front_wheel_assembly.add([front_wheel, front_axle])\n",
"# You can access the components of an assembly like this:\n",
"print(front_wheel_assembly.components[1].properties[\"label\"])\n",
"\n",
"# Assemblies can be cloned as well (including their children),\n",
"# but don't forget to adjust labels or you might be stuck with\n",
"# a 'front wheel' in your 'back wheel assembly'\n",
"\n",
"# Stick together back wheel parts\n",
"back_wheel_assembly = LegoAssembly(\n",
" AggregationLayer.SUBASSEMBLY, \"back wheel assembly\"\n",
" )\n",
"back_wheel_assembly.add([back_wheel, back_axle])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b6648e1",
"metadata": {},
"outputs": [],
"source": [
"# Create frame component and assemble the system\n",
"\n",
"with open(\"datasheets/frame.json\") as json_file:\n",
" frame = json.load(json_file)\n",
"scooter_frame = LegoComponent(\"scooter frame\", frame[\"3703\"], {\"color\": \"red\"})\n",
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
"\n",
"# The scooter is our system level assembly, you can choose the AggregationLayer\n",
"# But the hiercarchy (SYSTEM > ASSEMBLY > SUBASSEMBLY) must be in order.\n",
"# Components can be added to all LegoAssembly objects\n",
"\n",
"scooter = LegoAssembly(\n",
" AggregationLayer.SYSTEM,\n",
" \"scooter\",\n",
" manufacturer=\"FST\",\n",
" comment=\"Faster! Harder! Scooter!\",\n",
")\n",
"# add frame and subassemblies\n",
"scooter.add([scooter_frame, front_wheel_assembly, back_wheel_assembly])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71324895",
"metadata": {},
"outputs": [],
"source": [
"# Look at the assembly\n",
"\n",
"# We can get all LegoComponents from this assembly.\n",
"# Without parameter 'max_depth' only direct children will be listed.\n",
"scooter.get_component_list(5)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "001f1c77",
"metadata": {},
"source": [
"### Modul calculation_rules\n",
"\n",
"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",
"execution_count": null,
"id": "7b60d0fb",
"metadata": {},
"outputs": [],
"source": [
"# test the import\n",
"calculation_rules.test_function()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe4edad6",
"metadata": {},
"outputs": [],
"source": [
"# Add mass to assemblies\n",
"\n",
"# List all components' mass\n",
"combined_weight = 0\n",
"for c in scooter.get_component_list(-1):\n",
" combined_weight += c.properties[\"mass [g]\"]\n",
"print(\"Gesamtgewicht: \", combined_weight, \"g\")\n",
"# Add KPI to system\n",
"scooter.properties[\"mass [g]\"] = combined_weight\n",
"\n",
"# We can also add the mass to the subassemblies.\n",
"# children() returns a dict with a list of added\n",
"# components and assemblies.\n",
"for a in scooter.children()[\"assemblies\"]:\n",
" a_mass = 0\n",
" for c in a.get_component_list(-1):\n",
" a_mass += c.properties[\"mass [g]\"]\n",
" a.properties[\"mass [g]\"] = a_mass"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c26b36c8",
"metadata": {},
"outputs": [],
"source": [
"scooter.get_component_list(-1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d56419f",
"metadata": {},
"outputs": [],
"source": [
"# Look at the full assembly with KPI\n",
"\n",
"# Print the full assembly with all levels\n",
"print_assembly_tree(scooter)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b31416d3",
"metadata": {},
"outputs": [],
"source": [
"# Dump to json file with to_dict() and KPIEncoder\n",
"with open(\"scooter.json\", \"w\") as fp:\n",
" json.dump(scooter.to_dict(), fp, cls=KPIEncoder)\n",
"# full view is too big for Juypter (try it)\n",
"# pprint.pprint(scooter.to_dict())"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "53793ae8",
"metadata": {},
"source": [
"In dieser exportierten json-Datei ('scooter.json') sind die Werte maschinen- und menschenlesbar hinterlegt.\n",
"Zusammen mit der Berechnungsvorschrift in `calculation_rules` ist auch die Entstehung des KPI nachvollziehbar und wiederverwendbar dokumentiert und damit 'FAIR'."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "92c77051",
"metadata": {},
"source": [
"#### Zusätzliche Details"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b91fed73",
"metadata": {},
"outputs": [],
"source": [
"# Each child knows its parent\n",
"first_child = scooter.children()[\"assemblies\"][0]\n",
"print(\"Child:\", first_child)\n",
"print(\"Parent:\", first_child.parent)\n",
"# Also we can access the \"top\" parent\n",
"latest_child = first_child.children()[\"components\"][0]\n",
"print(\"Top parent: \", latest_child.get_root_assembly())\n",
"\n",
"# Each part created has a unique identifier (the long number in [])\n",
"# Don't try add the identical part again."
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "386d359a8531ffdc4805ead3a16e7983e89a5ab7bba0cbec0e7ad9597b7a2b64"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}