From fe302ef9505103e143e1d181ab9cadb7ee7b9fe2 Mon Sep 17 00:00:00 2001 From: Simon Steuer Date: Fri, 18 Apr 2025 22:03:03 +0200 Subject: [PATCH] =?UTF-8?q?In=20der=20Methode=20'child=5Fids'=20war=20es?= =?UTF-8?q?=20unn=C3=B6tig=20f=C3=BCr=20die=20Ermittlung=20aller=20St?= =?UTF-8?q?=C3=BCcklistenpositionen=20das=20'Parent'-Attribut=20der=20aufg?= =?UTF-8?q?elisteten=20Teilenummern=20in=20der=20JSON=20zu=20betrachten,?= =?UTF-8?q?=20da=20die=20Teilenummern=20in=20der=20JSON=20bereits=20alle?= =?UTF-8?q?=20Kinder=20der=20ASM=20darstellen=20/=20Methode=20'extend=5Fas?= =?UTF-8?q?m=5Fbom'=20erg=C3=A4nzt,=20damit=20die=20St=C3=BCckliste=20um?= =?UTF-8?q?=20eine=20Nummer=20erg=C3=A4nzt=20werden=20kann=20(z.B.=20die?= =?UTF-8?q?=20Nummer=20der=20Oberbaugruppe=20selbst,=20da=20diese=20aktuel?= =?UTF-8?q?l=20in=20der=20JSON=20nicht=20ausgegeben=20wird).=20Dies=20wurd?= =?UTF-8?q?e=20erg=C3=A4nzt,=20damit=20zuk=C3=BCnftig=20auch=20der=20Migra?= =?UTF-8?q?tionsstand=20von=20einzelnen=20Teilenummern,=20die=20keine=20Ba?= =?UTF-8?q?ugruppen=20sind,=20angezeigt=20werden=20kann,=20bzw.=20einzelne?= =?UTF-8?q?=20Teilenummern=20migriert=20werden=20k=C3=B6nnen.=20Die=20ents?= =?UTF-8?q?prechende=20Anpassung=20des=20Treeview-=20bzw.=20GUI-Programms?= =?UTF-8?q?=20erfolgt=20in=20einem=20sp=C3=A4teren=20Commit.=20Zudem=20wur?= =?UTF-8?q?de=20die=20Methode=20'get=5Fprop=5Fval=5Ffor=5Fsingle=5Fid'=20e?= =?UTF-8?q?rg=C3=A4nzt,=20da=20im=20Treeview-Programm=20bisher=20bei=20jed?= =?UTF-8?q?em=20Eintrag=20des=20Baums=20die=20Methode=20'get=5Fprop=5Fval?= =?UTF-8?q?=5Ffor=5Fall=5Fids'=20aufgerufen=20wurde,=20in=20der=20jedes=20?= =?UTF-8?q?Mal=20eine=20bestimmte=20Eigenschaft,=20wie=20z.B.=20'Bezeichnu?= =?UTF-8?q?ng'=20f=C3=BCr=20alle=20St=C3=BCcklistenpositionen=20der=20Haup?= =?UTF-8?q?tbaugruppe=20ermittelt=20wurde.=20Das=20war=20sehr=20ineffizien?= =?UTF-8?q?t,=20weil=20die=20Eigenschaft=20nur=20f=C3=BCr=20den=20aktuelle?= =?UTF-8?q?n=20Eintrag,=20d.h.=20die=20aktuelle=20Teilenummer,=20die=20im?= =?UTF-8?q?=20Baum=20dargestellt=20werden=20soll,=20ben=C3=B6tigt=20wird,?= =?UTF-8?q?=20aber=20nicht=20f=C3=BCr=20alle=20St=C3=BCcklistenpositionen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/manage_configs.py | 59 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/manage_configs.py b/lib/manage_configs.py index 81be8f9..6cf0aba 100644 --- a/lib/manage_configs.py +++ b/lib/manage_configs.py @@ -137,12 +137,7 @@ class SivasAssemblyData(JsonBasedConfig): """Gibt alle Teilenummern der Stückliste zurück (auch Teilenummern aus tieferen Baugruppenebenen)""" if self._child_ids is None: - self._child_ids = set() - for child_id, parent_properties in self.asm_data.items(): - self._child_ids.add(child_id) - for parent_property in parent_properties: - parent_id = parent_property["Parent"] - self._child_ids.add(parent_id) + self._child_ids = set(self.asm_data.keys()) return self._child_ids @property @@ -170,6 +165,35 @@ class SivasAssemblyData(JsonBasedConfig): ordered_parent_children[parent].append(child) self._parent_children = ordered_parent_children return self._parent_children + + def extend_asm_bom(self, id, metadata:dict) -> dict: + """Ergänzt die Stückliste um eine weitere Teilenummer unter Berücksichtigung des vorgegebenen Formats der ausgegebenen JSON + des Programms 'Sivas2Json' von Hr. Jakob + Aktuell ist die JSON wie folgt aufgebaut: + { + "Stücklistenposition 1": [{Metadaten aus 1. SIVAS-Stammstückliste, in der die Stücklistenposition verbaut ist}, + {Metadaten aus 2. SIVAS-Stammstückliste, in der die Stücklistenposition verbaut ist (falls die oberste Baugruppe weitere Unterbaugruppen enthält, in denen diese Nummer ebenfalls verbaut ist)}, + ... + ] + "Stücklistenposition 2": [{...}, + {...} + ] + }""" + + + property_names = self.property_names + + asm_data = self.asm_data + + if id not in asm_data: + self._asm_data[id] = [] + + for property_name in property_names: + if property_name not in metadata: + metadata[property_name] = None + + self._asm_data[id].append(metadata) + return self._asm_data @property def longest_child_id(self) -> str: @@ -201,17 +225,28 @@ class SivasAssemblyData(JsonBasedConfig): self._property_names = list(parent_data[0]) return self._property_names - def get_bom_property_values(self, property) -> dict: - """Gibt eine Eigenschaft zu den Teilenummern der Stückliste zurück (z.B. Bezeichnung)""" + def get_prop_val_for_single_id(self, id:str, property_name:str) -> str: + """Gibt eine Eigenschaft von einer einzelnen Teilenummer aus der Stückliste zurück""" + + if id not in self._asm_data: + raise KeyError("Angegebene Teilenummer befindet sich nicht in der Baugruppe!") - if property not in self.property_names: + if property_name not in self._asm_data[id][0]: + raise ValueError(f"Teilenummer besitzt nicht die angegebene Eigenschaft '{property_name}'") + + return self._asm_data[id][0][property_name] + + def get_prop_val_for_all_ids(self, property_name) -> dict: + """Gibt eine Eigenschaft zu allen Teilenummern der Stückliste zurück (z.B. Bezeichnung)""" + + if property_name not in self.property_names: raise ValueError("Angegebener Eigenschaftsname exisitert nicht!") id_property_mapping = {} for child, parent_data in self.asm_data.items(): for properties in parent_data: - if property in properties: - id_property_mapping[child] = properties[property] + if property_name in properties: + id_property_mapping[child] = properties[property_name] return id_property_mapping @property @@ -221,7 +256,7 @@ class SivasAssemblyData(JsonBasedConfig): if self._all_bom_properties is None: self._all_bom_properties = {} for property_name in self.property_names: - self._all_bom_properties[property_name] = self.get_bom_property_values(property_name) + self._all_bom_properties[property_name] = self.get_prop_val_for_all_ids(property_name) return self._all_bom_properties