Skip to content
Snippets Groups Projects
Commit 5254dc43 authored by Hock, Martin's avatar Hock, Martin
Browse files

Tried to merge changes.

Main difference are:
- deepcopy vs dict.update
- optional arguments
- label as dict entry or direct attribute
parents 0dea0640 7f9ef658
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:c9328cd1 tags:
# FAIRe Qualitäts-KPIs
Name:
Datum:
%% Cell type:markdown id:2ee8746d tags:
## 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 Qualitäts-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 Qualitäts-KPIs
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.
### 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-Skripte), 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.
Im Modul `classes` befinden sich die Klassen `LegoComponent, LegoAssembly, AggergationLayer, 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 Aggregationslayer, diese ist für `LegoComponent` immer `Component`, muss für `LegoAssembly` aber entsprechend auf `SYSTEM, ASSEMBLY` oder `SUBASSEMBLY` gesetzt werden.
Mit einem Minimalbeispiel wird Ihnen gezeigt, wie sie die Module nutzen.
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 id:b2778dee tags:
``` python
# import modules
import json
import pprint
from functions import calculation_rules
from functions import classes
# TO DO import further modules if necessary
## ## 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 = classes.LegoComponent('front axle',axles['32073'])
# Both name and the data dict are optional parameters. You can view, add or edit the properties just any dict:
print(front_axle.properties['name'])
front_axle.properties['color']= 'grey'
# Viewing dicts in one line is not easy to read, a better output comes with pretty print (pprint):
pprint.pprint(front_axle.properties)
# Create the second axle
back_axle = classes.LegoComponent()
back_axle.properties['name'] = 'back axle'
back_axle.properties.update(axles['32073'])
# Do not use = here, otherwise you'd overwrite existing properties.
back_axle.properties['color'] = 'grey'
```
%% Output
{'item description': 'Axle 5 studs', 'category': 'axle', 'price [Euro]': 0.001, 'mass [g]': 0.66, 'delivery time [days]': 3, 'Abmessung [studs]': 5}
front axle
{'Abmessung [studs]': 5,
'category': 'axle',
'color': 'grey',
'delivery time [days]': 3,
'item description': 'Axle 5 studs',
'mass [g]': 0.66,
'name': 'front axle',
'price [Euro]': 0.001}
%% 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 are supported, but only in this
#front_wheel = classes.LegoComponent('front wheel', wheels['2903'],{'color':'yellow'},winter='true')
front_wheel = classes.LegoComponent('front wheel', wheels['2903'],surface='rough', paint = 'glossy')
# front_
pprint.pprint(front_wheel.properties)
# We included a clone function, so you can easily create multiple items:
back_wheel = front_wheel.clone()
```
%% Output
{'category': 'wheel',
'color': 'yellow',
'data source': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P=2903c02#T=C',
'delivery time [days]': 5,
'diameter [mm]': 81.6,
'item description': 'wheel 81,6',
'mass [g]': 30.0,
'name': 'front wheel',
'paint': 'glossy',
'price [Euro]': 1.31,
'related items': 2902,
'surface': 'rough'}
%% Cell type:code id:bd3c7a6b tags:
``` python
# Also need a frame
with open('datasheets/Gestell.json') as json_file:
Gestelle = json.load(json_file)
Gestellbeschreibung = "Technic, Brick 1 x 8 with Holes"
Gestell = Gestelle[Gestellbeschreibung]
```
%% Cell type:markdown id:3b69752c tags:
### Modul calculation_results
Sie können die unterschiedlichen Funktionen (Berechnungsvorschriften) aufrufen. Beachten Sie dabei die Übergabe- und Rückgabewerte.
%% Cell type:code id:294c680b tags:
``` python
# test the import
calculation_rules.test_function()
```
%% Cell type:markdown id:a2c87a3c tags:
### Modul classes
Wir bauen ein Auto zusammen.
%% Cell type:code id:8db386db tags:
``` python
```
%% Cell type:code id:8f2ae9f4 tags:
``` python
```
%% Cell type:markdown id:de070039 tags:
## Aufgabe: Aufbau eines ersten Fahrzeugs
Bauen Sie ein erstes Fahrzeug aus den gegebenen LEGO-Teilen auf.
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 tags:
### Beschreibung des Fahrzeuges
Beschreiben Sie kurz und präzise Ihr Fahrzeug.
%% Cell type:code id:ccaf3043 tags:
``` python
# initialize componentens
```
%% Cell type:code id:1ea61422 tags:
``` python
# read out properties from datasheets
```
%% Cell type:code id:36f981df tags:
``` python
# set properties
```
%% Cell type:code id:24400d94 tags:
``` python
# export car and its properties
```
%% Cell type:markdown id:c1fef7f0 tags:
## Aufgabe: Bestimmung der Qualität mittels KPIs
Bestimmen Sie die Qualität Ihres Fahrzeugs mittels KPIs.
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 tags:
### Beschreibung KPI
Beschreiben Sie den jeweiligen KPI und geben Sie seine Berechnungsvorschrift an.
$$
a = \frac{b}{c} + d
$$
%% Cell type:code id:59eabafc tags:
``` python
# calculate the KPIs for your car
```
%% Cell type:code id:c774b381 tags:
``` python
# print your KPIs
```
%% Cell type:markdown id:89c75440 tags:
## Aufgabe: Aufbau eines zweiten Fahrzeugs
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.
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 tags:
### Beschreibung
Beschreiben Sie, welche Verbesserung Sie vornehmen.
...
%% Cell type:markdown id:73c454f2 tags:
### Aufbau des zweiten Fahrzeuges
Beschreiben Sie kurz und präzise den Aufbau des zweiten Fahrzeugs
%% Cell type:code id:ea18e735 tags:
``` python
# build a second car
```
%% Cell type:code id:b3438fc4 tags:
``` python
# read out properties from datasheets
```
%% Cell type:code id:0b7336fb tags:
``` python
# set properties
```
%% Cell type:code id:446abbca tags:
``` python
# export car and its properties
```
%% Cell type:markdown id:89e54480 tags:
### KPIs des zweiten Fahrzeuges
Bestimmen Sie die KPIs des zweiten Fahrzeuges
%% Cell type:code id:762a1e93 tags:
``` python
# calculate the KPIs for your car
```
%% Cell type:code id:1ed67328 tags:
``` python
# print your KPIs
```
%% Cell type:markdown id:e413cd84 tags:
## Aufgabe: Darstellung und Vergleich der Ergebnisse
Stellen Sie die Ergebnisse für beide Fahrzeuge übersichtlich dar.
Die entwickelten KPIs müssen dargestellt und die Datengrundlage ersichtlich sein.
Eine geeignete grafische Darstellung für die Gegenüberstellung der Ergebnisse für beide Fahrzeuge ist zu wählen.
%% Cell type:code id:b0f93e22 tags:
``` python
# plot the data, save diagramm as svg-file
```
%% Cell type:markdown id:62ff04b2 tags:
### Interpretation der Ergebnisse
Interpretieren Sie ihre Ergebnisse. Vergleichen Sie die KPIs ihrer Autos. Konnten Sie ihre gewünschte Verbesserung erzielen?
%% Cell type:markdown id:a0840fbf tags:
## Aufgabe: Exportieren Sie ihre Daten
Exportieren/ Speichern Sie alle relevaten Daten ab.
%% Cell type:code id:a4bdfc7a tags:
``` python
# export all relevant data
```
......
......@@ -4,7 +4,7 @@ File consists of several classes for the different elements of a device.
from __future__ import annotations
from enum import Enum, auto
import uuid
from typing import List, Dict
from typing import List, Dict, Optional
import json
import copy
import operator
......@@ -12,13 +12,27 @@ import operator
# TODO
# - Docstrings
# - Beschreibung von Teilen (-> properties) -> Raus aus dem Konstruktor rein in ein dict. (Deep-Copy)
# - Erstmal als Shallow Copy umgesetzt, wir verwenden momentan keine nested dicts
# - Minimalbeispiel für KPIs -> halb umgesetzt -> mit get_components veranschaulichen
# - Änderungen an Beispiel umsetzen
# -> Integriere AggregationLayer und die Funktionen in die Klassen (evtl. per Vererbung?) -> Nä Semester
# - Erlaube Listen bei add_component und add_assembly (-> Nä Semester)
# - Gute String Darstellung -> Ist so schon ok bisher? -> Nä Semester
# - Export als GraphViz -> Nä Semeseter
class ComponentCategory(Enum):
BATTERY = auto()
MOTOR = auto()
FRAME = auto()
WHEEL = auto()
AXLE = auto()
GEAR = auto()
class AggregationLayer(Enum):
SYSTEM = auto()
ASSEMBLY = auto()
......@@ -27,22 +41,31 @@ class AggregationLayer(Enum):
class LegoComponent:
def __init__(
self,
label: str,
properties: dict,
layer: AggregationLayer = AggregationLayer.COMPONENT,
) -> None:
def __init__(self, label: Optional[str] = None, datasheet: Optional[dict] = None, *more_properties: dict, **kwargs) -> None:
self.uuid: uuid.UUID = uuid.uuid4()
self.parent: None | LegoAssembly = None
self.label: str = label
self.properties: dict = properties
self.layer: AggregationLayer = layer
def clone(self, new_description: str = None) -> LegoComponent:
if new_description is None:
new_description = self.label
clone = LegoComponent(new_description, copy.deepcopy(self.properties), self.layer)
self.layer: AggregationLayer = AggregationLayer.COMPONENT
self.properties: dict = {}
if label is not None:
self.properties['label'] = label
if datasheet is not None:
self.properties.update(datasheet)
self.properties[]
for prop in more_properties:
if isinstance(prop, dict):
self.properties.update(prop)
else:
raise ValueError(f"Unexpected argument type: {type(more_properties)}")
for key, value in kwargs.items():
self.properties[key] = value
def clone(self, new_label: str = None) -> LegoComponent:
if new_label is None:
new_label = self.properties.label
clone = LegoComponent(None, self.properties, label=new_label)
return clone
def get_root_assembly(self):
......@@ -73,16 +96,18 @@ class LegoComponent:
# TODO good repr representation
def __repr__(self):
return f"LegoComponent {self.label} [{self.uuid}]"
return f"LegoComponent {self.properties['label']} [{self.uuid}]"
class LegoAssembly:
def __init__(self, label: str, properties: dict, layer: AggregationLayer) -> None:
def __init__(self, layer: AggregationLayer, label: Optional[str] = None, *properties: dict , **kwargs) -> None:
self.uuid: uuid.UUID = uuid.uuid4()
self.parent: None | LegoAssembly = None
self.label: str = label
self.properties: dict = properties
self.properties: dict = {}
if label is not None:
self.properties['label'] = label
self.layer: AggregationLayer = layer
self.properties.update(properties)
self.components: List[LegoComponent] = []
self.assemblies: List[LegoAssembly] = []
......@@ -161,7 +186,6 @@ class LegoAssembly:
def to_dict(self) -> Dict:
dict_ = {
"uuid": self.uuid,
"label": self.label,
"properties": self.properties,
"layer": self.layer,
}
......@@ -172,7 +196,7 @@ class LegoAssembly:
# TODO find good string representation
def __repr__(self):
return f"LegoAssembly {self.label} [{self.uuid}]"
return f"LegoAssembly {self.properties['label']} [{self.uuid}]"
def clone(self, label: str = None) -> LegoAssembly:
if label is None:
......@@ -234,8 +258,8 @@ class KPIEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, uuid.UUID):
return "kpi-" + str(o)
if isinstance(o, AggregationLayer):
return "kpi-" + o.name
if isinstance(o, (AggregationLayer)):
return "kpi-" + o.properties.label
return super().default(o)
pass
\ No newline at end of file
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