From 80000c15c37a669bf49831f74ee06c8225235e7a Mon Sep 17 00:00:00 2001 From: Simon Steuer Date: Fri, 18 Apr 2025 22:13:07 +0200 Subject: [PATCH] =?UTF-8?q?Die=20St=C3=BCcklistendaten,=20die=20aus=20der?= =?UTF-8?q?=20JSON-Datei=20des=20Programms=20'Sivas2Json'=20erzeugt=20werd?= =?UTF-8?q?en,=20wird=20jetzt=20immer=20die=20Teilenummer=20der=20Hauptbau?= =?UTF-8?q?gruppe=20erg=C3=A4nzt.=20Dadurch=20kann=20die=20Methode=20'=5Fp?= =?UTF-8?q?rint=5Ftree'=20auch=20die=20Nummer=20der=20Hauptbaugruppe=20sch?= =?UTF-8?q?reiben.=20Bisher=20war=20hierf=C3=BCr=20die=20separate=20Method?= =?UTF-8?q?e=20'=5Ftree=5Fheader'=20erforderlich.=20F=C3=BCr=20die=20Aufna?= =?UTF-8?q?hme=20der=20Hauptbaugruppe=20in=20die=20St=C3=BCcklistendaten?= =?UTF-8?q?=20ist=20die=20neue=20Methode=20'=5Fadd=5Fasm=5Fid=5Fto=5Fbom'?= =?UTF-8?q?=20zust=C3=A4ndig.=20Die=20Anpassung=20wurde=20vorbereitend=20f?= =?UTF-8?q?=C3=BCr=20die=20n=C3=A4chste=20Erweiterung=20dieses=20Programms?= =?UTF-8?q?=20erg=C3=A4nzt,=20mit=20der=20es=20m=C3=B6glich=20sein=20soll,?= =?UTF-8?q?=20den=20Migrationsstand=20von=20einzelnen=20Teilenummern,=20d.?= =?UTF-8?q?h.=20Nummern,=20die=20keine=20Baugruppen=20sind,=20anzuzeigen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compare_lists.py | 79 +++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/lib/compare_lists.py b/lib/compare_lists.py index 0c18b85..70ab0fe 100644 --- a/lib/compare_lists.py +++ b/lib/compare_lists.py @@ -75,7 +75,7 @@ class ExcelExport: sorting = self._create_sorting_string() migrated_ids = self.migration_status.ids_in_rd - child_descriptions:dict = self.asm_data.get_bom_property_values("Bezeichnung") + child_descriptions:dict = self.asm_data.get_prop_val_for_all_ids("Bezeichnung") parent_description:str = self.asm_metadata.get_property_values("Bezeichnung1") descriptions = child_descriptions.copy() @@ -212,47 +212,45 @@ class Treeview: + padding_after_id return self._longest_entry - def generate_tree(self): - self._tree_header() - self._tree_body() - self._tree_summary() - def _tree_header(self): + def _add_asm_id_to_bom(self): + """Standardmäßig ist die oberste Baugruppennummer kein Bestandteil der JSON-Datei, in der die Baugruppenstruktur aufgelistet ist und + die über das Programm 'Sivas2Json' von Hr. Jakob generiert wird. Damit der Baum die Bezeichnung der obersten Baugruppennummer im + Baum angezeigt wird ist es jedoch erforderlich, dass die Nummer mitsamt ihrer Bezeichnung in der JSON enthalten ist""" + + metadata = {"Bezeichnung": self.asm_metadata.get_property_values("Bezeichnung1"), + "Position": "10/0"} - """Prints root number (number for which the user wants to see the tree) to the console""" + self.asm_bom_data.extend_asm_bom(self.asm_id, metadata) - id = self.asm_id - color = self._set_text_background_color(id) - text_before_description = f"{color}{id}{Treeview.console_colors['RESET']}".ljust(self.longest_entry) - description = self.asm_metadata.get_property_values("Bezeichnung1") + def generate_tree(self): + self._add_asm_id_to_bom() + self._print_tree() + self._print_summary() - print(f"{text_before_description}{description}") - def _tree_body(self, parent_id=None, prefix=""): + def _print_tree(self, parent_id=None, prefix=""): - """Prints the body (all partnumbers except root/main-partnumber) of the tree to the console""" - - if parent_id is None: - parent_id = self.asm_id + """Gibt die Baugruppenstruktur in Form eines Baumes in der Konsole aus""" parent_children = self.asm_bom_data.parent_children children_ids = parent_children[parent_id] - for index, child_id in enumerate(children_ids): + for i, id in enumerate(children_ids): - is_last_assembly_child = self._last_child_check(index, children_ids) + last_child = self._last_child_check(i, children_ids) + connector_symbol = self._set_connector_symbol(id, last_child) + background_color = self._set_background_color(id) - connector_symbol = self._set_connector_symbol(is_last_assembly_child) - partnumber_background_color = self._set_text_background_color(child_id) + self._print_entry(id, prefix, connector_symbol, background_color) - self._print_entry(child_id, prefix, connector_symbol, partnumber_background_color) + if id in parent_children: + next_prefix = self._set_next_prefix(prefix, id, last_child) + self._print_tree(parent_id=id, prefix=next_prefix) - if child_id in parent_children: - next_prefix = self._prefix(prefix, is_last_assembly_child) - self._tree_body(parent_id=child_id, prefix=next_prefix) - def _tree_summary(self): + def _print_summary(self): amount_in_rd = len(self.migration_status.ids_in_rd) amount_pending = len(self.migration_status.ids_pending) @@ -299,36 +297,44 @@ class Treeview: """Eintrag in die Konsole drucken""" - text_before_description = f"{prefix}{connector}{color}{child_id}{Treeview.console_colors['RESET']}".ljust(self.longest_entry) - description = self.asm_bom_data.get_bom_property_values("Bezeichnung")[child_id] + description = self.asm_bom_data.get_prop_val_for_single_id(child_id, "Bezeichnung") print(f"{text_before_description}{description}") - def _last_child_check(self, child_index, children): + def _last_child_check(self, child_idx, children_ids): """Prüft, ob aktuelle ID das letzte Kind der Baugruppe ist""" - return True if child_index == len(children) - 1 else False + return True if child_idx == len(children_ids) - 1 else False - def _set_connector_symbol(self, child_is_last_child): + def _set_connector_symbol(self, child_id, last_child): """Legt Verbindungssymbol für aktuellen Eintrag im Baum fest""" - return Treeview.connector_symbols["ELBOW"] if child_is_last_child else Treeview.connector_symbols["T"] + if child_id == self.asm_id: # Oberste Baugruppennummer wird immer ohne Verbindersymbol dargestellt + return "" + + if not last_child: + return Treeview.connector_symbols["T"] + + return Treeview.connector_symbols["ELBOW"] - def _prefix(self, prefix, child_is_last_child): + def _set_next_prefix(self, prefix, child_id, last_child): - """Erstellt für jeden Eintrag im Baum einen Präfix (Teil vor dem Verbindersymbol) fest""" + """Legt den Teil VOR dem Verbindersymbol für den nächsten Eintrag im Baum fest""" - prefix += Treeview.prefix_types["EMPTY"] if child_is_last_child else Treeview.prefix_types["PIPE"] + if child_id == self.asm_id: # Erste Stücklistenposition der obersten Baugruppennummer hat nie Präfix + return "" + + prefix += Treeview.prefix_types["EMPTY"] if last_child else Treeview.prefix_types["PIPE"] return prefix - def _set_text_background_color(self, id): + def _set_background_color(self, id): """Legt Hintergrundfarbe der Teilenummer basierend auf ihrem Migrationsstatus fest: @@ -397,7 +403,6 @@ if __name__ == '__main__': load_local_asm_csv=args.asm_csv_local, load_local_rd_dbase=args.rd_ids_local, no_blue_ids=args.no_blue_ids) - treeview_comparison.generate_tree() else: parser.print_help() \ No newline at end of file