{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c9328cd1",
   "metadata": {},
   "source": [
    "# FAIRe Qualitäts-KPIs\n",
    "Name:\n",
    "Datum:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ee8746d",
   "metadata": {},
   "source": [
    "## Einführung\n",
    "FAIRe Qualitäts-KPIs schaffen eine transparente und nachvollziehbare Entscheidungsgrundlage. In dieser Lerneinheit sollen sie die Methodik erlernen, indem sie LEGO-Autos zusammenbauen, deren Qualitäts-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 Qualitäts-KPIs\n",
    "KPIs (Key Performance Indikatoren) sind Kenngrößen des Systems. Sie werden über Berechnungsvorschriften (`calculation_rules`) bestimmt. Diese Berechnungsvorschriften sind von Ihnen als python-Funktionen im Modul `calculation_results` 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  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",
    "\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": 1,
   "id": "b2778dee",
   "metadata": {},
   "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",
    "## ## 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]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b69752c",
   "metadata": {},
   "source": [
    "### Modul calculation_results\n",
    "Sie können die unterschiedlichen Funktionen (Berechnungsvorschriften) aufrufen. Beachten Sie dabei die Übergabe- und Rückgabewerte."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "294c680b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test the import\n",
    "calculation_rules.test_function()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2c87a3c",
   "metadata": {},
   "source": [
    "### Modul classes\n",
    "Wir bauen ein Auto zusammen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8db386db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f2ae9f4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "de070039",
   "metadata": {},
   "source": [
    "## Aufgabe: Aufbau eines ersten Fahrzeugs\n",
    "Bauen Sie ein erstes Fahrzeug aus den gegebenen LEGO-Teilen auf.\n",
    "Das Fahrzeug muss aus Baugruppen, Bauteilen und Komponenten bestehen. Es muss mindestens vier Räder haben und sich durch den elektrischen Antrieb fortbewegen können."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05a8eb21",
   "metadata": {},
   "source": [
    "### Beschreibung des Fahrzeuges\n",
    "Beschreiben Sie kurz und präzise Ihr Fahrzeug. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ccaf3043",
   "metadata": {},
   "outputs": [],
   "source": [
    "# initialize componentens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ea61422",
   "metadata": {},
   "outputs": [],
   "source": [
    "# read out properties from datasheets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36f981df",
   "metadata": {},
   "outputs": [],
   "source": [
    "# set properties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24400d94",
   "metadata": {},
   "outputs": [],
   "source": [
    "# export car and its properties"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1fef7f0",
   "metadata": {},
   "source": [
    "## Aufgabe: Bestimmung der Qualität mittels KPIs\n",
    "Bestimmen Sie die Qualität Ihres Fahrzeugs mittels KPIs. \n",
    "Die Qualität des Fahrzeugs ist mit mindestens einem KPI je Qualitätsdimension (Aufwand, Verfügbarkeit, Akzeptanz) zu bestimmen. Enwickeln Sie zunächst sinnvolle KPIs, welche mit den gegebenen Daten umsetzbar sind. Halten Sie die Berechnungsvorschriften im Jupyter Notebook fest. Implementieren Sie deren Berechnung für das Gesamtsystem \"Fahrzeug\" mittels einzelner Funktionen im Skript `calculation_rules`. Sie können zusätzlich Ihre Methoden auch auf die niedrigeren Aggregationsebenen anwenden."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5f02096",
   "metadata": {},
   "source": [
    "### Beschreibung KPI\n",
    "Beschreiben Sie den jeweiligen KPI und geben Sie seine Berechnungsvorschrift an.\n",
    "$$\n",
    "a = \\frac{b}{c} + d\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59eabafc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# calculate the KPIs for your car"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c774b381",
   "metadata": {},
   "outputs": [],
   "source": [
    "# print your KPIs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89c75440",
   "metadata": {},
   "source": [
    "## Aufgabe: Aufbau eines zweiten Fahrzeugs\n",
    "Setzen Sie sich ein Ziel, welche Qualitätsdimensionen in einem zweiten Fahrzeug verbessert werden sollen und bauen Sie dementsprechend ein zweites Fahrzeug aus den gegebenen LEGO-Teilen auf.\n",
    "\n",
    "Das Fahrzeug muss aus Baugruppen, Bauteilen und Komponenten bestehen. Es muss mindestens vier Räder haben und sich durch den elektrischen Antrieb fortbewegen können. Die Verwendung eines Getriebes zwischen Motor und Antriebsachse(n) ist verpflichtend. Es sind nur die gegebenen LEGO-Teile zu verwenden. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cef0828",
   "metadata": {},
   "source": [
    "### Beschreibung\n",
    "Beschreiben Sie, welche Verbesserung Sie vornehmen.\n",
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73c454f2",
   "metadata": {},
   "source": [
    "### Aufbau des zweiten Fahrzeuges\n",
    "Beschreiben Sie kurz und präzise den Aufbau des zweiten Fahrzeugs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea18e735",
   "metadata": {},
   "outputs": [],
   "source": [
    "# build a second car"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3438fc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# read out properties from datasheets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b7336fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# set properties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "446abbca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# export car and its properties"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89e54480",
   "metadata": {},
   "source": [
    "### KPIs des zweiten Fahrzeuges\n",
    "Bestimmen Sie die KPIs des zweiten Fahrzeuges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "762a1e93",
   "metadata": {},
   "outputs": [],
   "source": [
    "# calculate the KPIs for your car"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ed67328",
   "metadata": {},
   "outputs": [],
   "source": [
    "# print your KPIs"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e413cd84",
   "metadata": {},
   "source": [
    "## Aufgabe: Darstellung und Vergleich der Ergebnisse\n",
    "Stellen Sie die Ergebnisse für beide Fahrzeuge übersichtlich dar. \n",
    "Die entwickelten KPIs müssen dargestellt und die Datengrundlage ersichtlich sein.\n",
    "Eine geeignete grafische Darstellung für die Gegenüberstellung der Ergebnisse für beide Fahrzeuge ist zu wählen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0f93e22",
   "metadata": {},
   "outputs": [],
   "source": [
    "# plot the data, save diagramm as svg-file"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62ff04b2",
   "metadata": {},
   "source": [
    "### Interpretation der Ergebnisse\n",
    "Interpretieren Sie ihre Ergebnisse. Vergleichen Sie die KPIs ihrer Autos. Konnten Sie ihre gewünschte Verbesserung erzielen?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0840fbf",
   "metadata": {},
   "source": [
    "## Aufgabe: Exportieren Sie ihre Daten\n",
    "Exportieren/ Speichern Sie alle relevaten Daten ab."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4bdfc7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# export all relevant data"
   ]
  }
 ],
 "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
}