From acd86242ac6f6057cd611b23a03a34ae3a2ec926 Mon Sep 17 00:00:00 2001 From: "Hock, Martin" <martin.hock@fst.tu-darmstadt.de> Date: Wed, 1 Mar 2023 19:09:34 +0100 Subject: [PATCH] Changes in ausarbeitung until now --- ausarbeitung.ipynb | 130 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 7 deletions(-) diff --git a/ausarbeitung.ipynb b/ausarbeitung.ipynb index 8543414..51ae5a0 100644 --- a/ausarbeitung.ipynb +++ b/ausarbeitung.ipynb @@ -29,29 +29,140 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "1c702114", "metadata": {}, "source": [ "## Eigene Module und Minimalbeispiel\n", - "Für die Ausarbeitung nutzen wir zwei eigene Module (Python-Skripte), die im Ordner `functions` gespeichert sind.\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 Klassen `LegoComponent, LegoAssembly, AggergationLayer, 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 Aggregationslayer, diese ist für `LegoComponent` immer `Component`, muss für `LegoAssembly` aber entsprechend auf `SYSTEM, ASSEMBLY` oder `SUBASSEMBLY` gesetzt werden.\n", "\n", - "Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen." + "\n", + "Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen. Dabei wird nur aus Achse, Rahmen und Reifen ein Tretroller gebaut." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "b2778dee", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'item description': 'Axle 5 studs', 'category': 'axle', 'price [Euro]': 0.001, 'mass [g]': 0.66, 'delivery time [days]': 3, 'Abmessung [studs]': 5}\n", + "front axle\n", + "{'Abmessung [studs]': 5,\n", + " 'category': 'axle',\n", + " 'color': 'grey',\n", + " 'delivery time [days]': 3,\n", + " 'item description': 'Axle 5 studs',\n", + " 'mass [g]': 0.66,\n", + " 'name': 'front axle',\n", + " 'price [Euro]': 0.001}\n" + ] + } + ], "source": [ "# import modules\n", + "import json\n", + "import pprint\n", "from functions import calculation_rules\n", "from functions import classes\n", "\n", - "# TO DO import further modules if necessary\n" + "## ## Create the wheels and axles as single components first\n", + "# Look up the specific item you want from the provided json files, 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", + "\n", + "# Create the component with the dict:\n", + "front_axle = classes.LegoComponent('front axle',axles['32073'])\n", + "# Both name and the data dict are optional parameters. You can view, add or edit the properties just any dict:\n", + "print(front_axle.properties['name'])\n", + "front_axle.properties['color']= 'grey'\n", + "# Viewing dicts in one line is not easy to read, a better output comes with pretty print (pprint): \n", + "pprint.pprint(front_axle.properties)\n", + "\n", + "# Create the second axle\n", + "back_axle = classes.LegoComponent()\n", + "back_axle.properties['name'] = 'back axle'\n", + "back_axle.properties.update(axles['32073']) \n", + "# Do not use = here, otherwise you'd overwrite existing properties.\n", + "back_axle.properties['color'] = 'grey'\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b4a8e8c8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'category': 'wheel',\n", + " 'color': 'yellow',\n", + " 'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=2903c02#T=C',\n", + " 'delivery time [days]': 5,\n", + " 'diameter [mm]': 81.6,\n", + " 'item description': 'wheel 81,6',\n", + " 'mass [g]': 30.0,\n", + " 'name': 'front wheel',\n", + " 'paint': 'glossy',\n", + " 'price [Euro]': 1.31,\n", + " 'related items': 2902,\n", + " 'surface': 'rough'}\n" + ] + } + ], + "source": [ + "\n", + "# 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 are supported, but only in this \n", + "#front_wheel = classes.LegoComponent('front wheel', wheels['2903'],{'color':'yellow'},winter='true')\n", + "\n", + "front_wheel = classes.LegoComponent('front wheel', wheels['2903'],surface='rough', paint = 'glossy')\n", + "# front_\n", + "pprint.pprint(front_wheel.properties)\n", + "\n", + "# We included a clone function, so you can easily create multiple items:\n", + "back_wheel = front_wheel.clone()\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bd3c7a6b", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "# Also need a frame\n", + "with open('datasheets/Gestell.json') as json_file:\n", + " Gestelle = json.load(json_file)\n", + "Gestellbeschreibung = \"Technic, Brick 1 x 8 with Holes\"\n", + "Gestell = Gestelle[Gestellbeschreibung]" ] }, { @@ -352,7 +463,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -366,7 +477,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.0" + "version": "3.11.0" }, "varInspector": { "cols": { @@ -396,6 +507,11 @@ "_Feature" ], "window_display": false + }, + "vscode": { + "interpreter": { + "hash": "386d359a8531ffdc4805ead3a16e7983e89a5ab7bba0cbec0e7ad9597b7a2b64" + } } }, "nbformat": 4, -- GitLab