From c0f8025a921393293a137ff833ea079524cfd820 Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Wed, 4 Jun 2025 14:17:29 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fehlermeldungen,=20Hinweise,=20etc...=20auf?= =?UTF-8?q?=20englisch=20=C3=BCbersetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/drawdxf.py | 41 +++++++++++++++++++---------------------- lib/routing.py | 10 +++++----- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/drawdxf.py b/lib/drawdxf.py index 6a2d990..97838c1 100644 --- a/lib/drawdxf.py +++ b/lib/drawdxf.py @@ -12,9 +12,6 @@ from collections import defaultdict import configparser - - - @dataclass class Point: x: float @@ -60,7 +57,7 @@ def add_polyline(msp, points:Polyline, dxf_attribs): def new_dxf(plines, out_path): """ creates a new dxf file with a polyline inside which is created by the given json file """ - print("creating dxf ..") + print("creating new .dxf ..") doc = ezdxf.new('R2018', setup=True) create_cables(plines, doc) @@ -72,7 +69,7 @@ def new_dxf(plines, out_path): def modify_original_dxf(plines, originaldxf): """ adds new layer to original .dxf-file that contains cables """ - print("adding cables to original .dxf ..") + print("adding cables into original .dxf ..") doc = ezdxf.readfile(originaldxf) create_cables(plines, doc) @@ -84,7 +81,7 @@ def modify_original_dxf(plines, originaldxf): def copy_layers_into_new(originaldxf, outpath, plines): """ creates a new dxf file with a racks, sensors, subdists from original file including cable paths """ - print("copying layers from original .dxf into new .dxf ..") + print("copying layers (Racks, Subdistributors, ...) from original .dxf into new .dxf ..") quelle = ezdxf.readfile(originaldxf) ziel = ezdxf.new('R2018', setup=True) @@ -123,7 +120,7 @@ def model_from_json(json_file): def export_excel(json_file, out_path): # Hier für Excel Export - print("creating excel file ..") + print("creating excel file with cable information ..") plines = model_from_json(json_file) write_excel_from_json(plines, out_path) print("done") @@ -135,8 +132,8 @@ def write_excel_from_json(plines:Polylines, outpath:str): #Worksheet 1 - Kabellängen ws1 = wb.active - ws1.title = "Kabellängen" - ws1.append(["Kabel-ID", "Länge aus Json (m)", "Gerundete Länge (m)"]) + ws1.title = "Length by ID" + ws1.append(["Cable-ID", "True Length (m)", "Rounded Length (m)"]) for pl in plines.kabel: length = pl.length /1000 # Umrechnung von mm in m @@ -145,24 +142,24 @@ def write_excel_from_json(plines:Polylines, outpath:str): ws1.append([pl.id, length, int(rounded_len)]) # Worksheet 2 - Zusammengefasste Längen - ws2 = wb.create_sheet("Längenübersicht") - ws2.append(["Gerundete Länge (m)", "Anzahl Kabel"]) + ws2 = wb.create_sheet("Length Summary") + ws2.append(["Rounded Length (m)", "Number of Cables"]) for rlength in sorted(length_summary): ws2.append([int(rlength), length_summary[rlength]]) # Worksheet 3 - Nicht an Racks gekoppeltes Equipment - ws3 = wb.create_sheet("Equipment nicht angebunden") - ws3.append(["Typ", "Name", "x", "y"]) + ws3 = wb.create_sheet("Not connected Equipment") + ws3.append(["Type", "ID", "x", "y"]) for error in plines.errors_sensors: - ws3.append(["Sensor / Aktor", error.name, error.coords.x, error.coords.y]) + ws3.append(["Sensor / Actuator", error.name, error.coords.x, error.coords.y]) for error in plines.errors_dists: - ws3.append(["Unterverteiler", error.name, error.coords.x, error.coords.y]) + ws3.append(["Subistributor", error.name, error.coords.x, error.coords.y]) # Worksheet 4 - Fehlgeschlagenes Routing - ws4 = wb.create_sheet("Routingfehler") - ws4.append(["Unterverteiler", "Sensor- / Aktorname", "Grund"]) + ws4 = wb.create_sheet("Routing Errors") + ws4.append(["Subdistributor", "Sensor / Actuator", "Details"]) nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists) @@ -171,20 +168,20 @@ def write_excel_from_json(plines:Polylines, outpath:str): uv_nicht_angebunden = uv in nicht_angebunden if uv in plines.errors_existing_dists: - ws4.append([uv,"-", "Distributor not found in layout"]) + ws4.append([uv,"-", "Distributor not found in given layout"]) continue for sensor in routing_error.sensoren: sensor_nicht_angebunden = sensor in nicht_angebunden if sensor_nicht_angebunden and uv_nicht_angebunden: - grund = "Sensor und Unterverteiler nicht angebunden" + grund = "Subdistributor and sensor / actuator not connected to racks" elif sensor_nicht_angebunden: - grund = "Sensor / Aktor nicht angebunden" + grund = "Sensor / actuator not connected to racks" elif uv_nicht_angebunden: - grund = "Unterverteiler nicht angebunden" + grund = "Subdistributor not connected to racks" else: - grund = "Fehlgeschlagenes Routing trotz Anbindung" + grund = "Failed routing (not caused by missing connection)" ws4.append([uv, sensor, grund]) diff --git a/lib/routing.py b/lib/routing.py index d46bc9b..b568e18 100644 --- a/lib/routing.py +++ b/lib/routing.py @@ -148,11 +148,11 @@ def prepare_data(rawdata:dict): if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Berechne Wege von Sensoren zu Verteilern über Kabeltrassen') - parser.add_argument('-f', '--filename', action='store', required=True, default="easy_position.json", help='file with all informations about positions gathered from getpositions', metavar='my_positions.json') - parser.add_argument('-c', '--console', action='store_true', help='Ausgabe auf Konsole') - parser.add_argument('-g', '--graph', action='store_true', help='Zeichnet den Graphen der Anlage') - parser.add_argument('-w', '--write', action='store', help='erstellt Ausgabe-file für das Zeichnen von Kabeln in drawdxf') + parser = argparse.ArgumentParser(description='Calculate cable-routing from Subdistributors zu sensors / actuators alon cable-racks') + parser.add_argument('-f', '--filename', action='store', required=True, default="file_positions.json", help='file with all informations about positions gathered from getpositions', metavar='my_positions.json') + parser.add_argument('-c', '--console', action='store_true', help='print to console') + parser.add_argument('-g', '--graph', action='store_true', help='draw and show generated graph') + parser.add_argument('-w', '--write', action='store', help='create .json file to pass into drawing module to visualize results') args = parser.parse_args() From 36f13a736e0e95e5c4e1ec04c517ea35f77ed51a Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Wed, 4 Jun 2025 14:26:44 +0200 Subject: [PATCH 2/2] Abfrage ob es Fehler gibt bevor Fehler Worksheet erstellt werden --- lib/drawdxf.py | 61 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/drawdxf.py b/lib/drawdxf.py index 97838c1..08931a4 100644 --- a/lib/drawdxf.py +++ b/lib/drawdxf.py @@ -148,42 +148,45 @@ def write_excel_from_json(plines:Polylines, outpath:str): for rlength in sorted(length_summary): ws2.append([int(rlength), length_summary[rlength]]) - # Worksheet 3 - Nicht an Racks gekoppeltes Equipment - ws3 = wb.create_sheet("Not connected Equipment") - ws3.append(["Type", "ID", "x", "y"]) - for error in plines.errors_sensors: - ws3.append(["Sensor / Actuator", error.name, error.coords.x, error.coords.y]) + if len(plines.errors_existing_sensors) > 0 or len(plines.errors_dists) > 0: + # Worksheet 3 - Nicht an Racks gekoppeltes Equipment + ws3 = wb.create_sheet("Not connected Equipment") + ws3.append(["Type", "ID", "x", "y"]) + for error in plines.errors_sensors: + ws3.append(["Sensor / Actuator", error.name, error.coords.x, error.coords.y]) - for error in plines.errors_dists: - ws3.append(["Subistributor", error.name, error.coords.x, error.coords.y]) + for error in plines.errors_dists: + ws3.append(["Subistributor", error.name, error.coords.x, error.coords.y]) - # Worksheet 4 - Fehlgeschlagenes Routing - ws4 = wb.create_sheet("Routing Errors") - ws4.append(["Subdistributor", "Sensor / Actuator", "Details"]) - nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists) + if len(plines.errors_routing) > 0: + # Worksheet 4 - Fehlgeschlagenes Routing + ws4 = wb.create_sheet("Routing Errors") + ws4.append(["Subdistributor", "Sensor / Actuator", "Details"]) - for routing_error in plines.errors_routing: - uv = routing_error.unterverteiler - uv_nicht_angebunden = uv in nicht_angebunden - - if uv in plines.errors_existing_dists: - ws4.append([uv,"-", "Distributor not found in given layout"]) - continue + nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists) - for sensor in routing_error.sensoren: - sensor_nicht_angebunden = sensor in nicht_angebunden + for routing_error in plines.errors_routing: + uv = routing_error.unterverteiler + uv_nicht_angebunden = uv in nicht_angebunden + + if uv in plines.errors_existing_dists: + ws4.append([uv,"-", "Distributor not found in given layout"]) + continue - if sensor_nicht_angebunden and uv_nicht_angebunden: - grund = "Subdistributor and sensor / actuator not connected to racks" - elif sensor_nicht_angebunden: - grund = "Sensor / actuator not connected to racks" - elif uv_nicht_angebunden: - grund = "Subdistributor not connected to racks" - else: - grund = "Failed routing (not caused by missing connection)" + for sensor in routing_error.sensoren: + sensor_nicht_angebunden = sensor in nicht_angebunden - ws4.append([uv, sensor, grund]) + if sensor_nicht_angebunden and uv_nicht_angebunden: + grund = "Subdistributor and sensor / actuator not connected to racks" + elif sensor_nicht_angebunden: + grund = "Sensor / actuator not connected to racks" + elif uv_nicht_angebunden: + grund = "Subdistributor not connected to racks" + else: + grund = "Failed routing (not caused by missing connection)" + + ws4.append([uv, sensor, grund]) wb.save(outpath)