From 2d29705d4aa02c89441e226cdab05c528762ab80 Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Tue, 10 Jun 2025 16:05:28 +0200 Subject: [PATCH] =?UTF-8?q?Kabel-Config=20komplett=20mit=20float=20zahlen?= =?UTF-8?q?=20als=20keys=20versehen.=20Fehlermeldungen=20angepasst.=20?= =?UTF-8?q?=C3=9Cbepr=C3=BCfung=20des=20pos-Eintrags=20im=20dict=20vo=20me?= =?UTF-8?q?rge=5Ftwo=5Fdict=20wieder=20einkommentiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/drawdxf.py | 22 ++++++++-------------- lib/getpositions.py | 12 ++++++------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/drawdxf.py b/lib/drawdxf.py index f1afdaf..4c4a79b 100644 --- a/lib/drawdxf.py +++ b/lib/drawdxf.py @@ -115,7 +115,7 @@ def draw_cables(plines, doc): # Polyline für Kabel zeichnen add_polyline(msp, pl, dxfattribs_cable) -def find_close_key(pos2sensors, x, y, tolerance=10): # !!! Toleranz in Config !!! +def find_close_key(pos2sensors, x, y, tolerance=10): # !!! Toleranz nicht in Config !!! ''' Funktion überprüft ob Sensoren nahezu identisch an der gleichen Stelle liegen und legt sie in diesem fall aufeinander Wird benötigt, um zusammengehörige Sensoren gestaffelt auf dxf zu zeichen ''' @@ -267,10 +267,9 @@ def parse_sensors_from_json(positions_json): sensors[name] = sensor return sensors -def export_excel(json_file, out_path): +def export_excel(plines, out_path): # Hier für Excel Export print("creating excel file with cable information ..") - plines = model_from_json(json_file) sens2cable = map_sensor_to_cable(sensors, plines) write_excel_from_json(plines, sens2cable, out_path) print("done") @@ -438,20 +437,14 @@ def get_cable_artnr(section, length): entries = cable_cfg[section] # Alle Einträge der Form: "5" = "123456789" - try: - length_keys = sorted( - [float(k) for k in entries.keys() if k.replace('.', '', 1).isdigit()] - ) - except ValueError: - return None + length_keys = sorted([float(k) for k in entries.keys()]) for l in length_keys: if length <= l: - return entries[str(int(l))] # Annahme: Keys sind ganze Zahlen in Metern + return entries[str(l)] # Annahme: Keys sind ganze Zahlen in Metern return None - def map_sensor_to_cable(sensors, plines): sens2cable = defaultdict() for pl in plines.kabel: @@ -468,6 +461,7 @@ def map_sensor_to_cable(sensors, plines): section = None #Default + # Hier MB ebenfalls als Motor gezählt. Motoren in Fortna-Layout nicht angebunden! if name_prefix == "MA" or name_prefix == "MB": section = "MA" @@ -483,11 +477,11 @@ def map_sensor_to_cable(sensors, plines): section = "WD_I" if section is None: - cable_artnr = "KEIN KABEL" + cable_artnr = "Kein Kabeltyp zu Sensor-Artikelnummer zugewiesen" else: cable_artnr = get_cable_artnr(section, cable_length) if cable_artnr is None: - cable_artnr = "KEIN KABEL" + cable_artnr = "Kabel länger als max. Kabellänge" sens2cable[pl.id] = cable_artnr @@ -573,7 +567,7 @@ if __name__ == '__main__': if args.excel: excel_path = os.path.join(work_dir, args.excel) - export_excel(json_path, excel_path) + export_excel(plines, excel_path) diff --git a/lib/getpositions.py b/lib/getpositions.py index 6259fd2..cb0f439 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -160,11 +160,11 @@ def get_input_positions_iter(dxf_path) -> tuple: # Nur wenn eine ID vorhanden ist, und eine gültige Position existiert if typ == "Sensor": - #if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: - if id in allSensors: - allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" - else: - allSensors[id] = ld + if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: + if id in allSensors: + allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" + else: + allSensors[id] = ld elif typ == "Kabel": allCables[id] = ld elif typ == "Schaltschrankelement": @@ -464,7 +464,7 @@ if __name__ == '__main__': msp = doc.modelspace() use_iter = False else: - print("Given .dxf-file is ASCII-dxf. Proceeding to user iterative functions. Process may take longer.") + print("Given .dxf-file is ASCII-dxf. Proceeding to use iterative functions. Process may take longer.") use_iter = True res_sens = dict()