Fehler-Handling erweitert: Warnings die bei erstellung des Mappings entstehen werden durch routing hindurch bis nach drawdxf geleitet und in Excel ausgabe geschrieben.

This commit is contained in:
2025-06-12 12:41:27 +02:00
parent b950573b93
commit 85ae4f17f4
3 changed files with 35 additions and 17 deletions
+24 -10
View File
@@ -4,7 +4,7 @@ import json
import os.path
from dataclasses import dataclass, asdict, fields
from dacite import from_dict
from typing import List
from typing import List, Dict
from datetime import datetime
from openpyxl import Workbook
import math
@@ -30,12 +30,14 @@ class Polyline:
ret.append( (p.x, p.y) )
return ret
@dataclass
@dataclass
# Fehlgeschlagene Anbindung von einem Sensor / Dist zu einem Rack
class Error_Connection:
name: str
coords: Point
@dataclass
# Felgeschlagene Verbindung von einem Dist zu Sensor(en) aus beliebigem Grund
class Error_Routing:
unterverteiler: str
sensoren: List[str]
@@ -46,8 +48,9 @@ class Polylines:
errors_routing: List[Error_Routing]
errors_sensors: List[Error_Connection]
errors_dists: List[Error_Connection]
errors_existing_dists: List[str]
errors_existing_sensors: List[str]
errors_dists_not_in_layout: List[str]
errors_sensors_not_in_layout: List[str]
errors_missing_attributes: Dict[str, str]
def add_polyline(msp, points:Polyline, dxf_attribs):
@@ -305,22 +308,24 @@ def write_excel_from_json(plines:Polylines, outpath:str):
cumm_length = length_summary.get(artnr, "")
ws2.append([artnr, count, cumm_length])
# Abfage ob Fehler Worsheets ausgegeben werden
if len(plines.errors_existing_sensors) > 0 or len(plines.errors_dists) > 0:
if len(plines.errors_sensors) > 0 or len(plines.errors_dists) > 0:
# Worksheet 3 - Nicht an Racks gekoppeltes Equipment
ws3 = wb.create_sheet("Not connected Equipment")
ws3 = wb.create_sheet("ERR-Equipment-Connection")
ws3.append(["Type", "ID", "x", "y"])
# nicht angebundene Sensoren
for error in plines.errors_sensors:
ws3.append(["Sensor / Actuator", error.name, error.coords.x, error.coords.y])
# nicht angebundene Distributoren
for error in plines.errors_dists:
ws3.append(["Subistributor", error.name, error.coords.x, error.coords.y])
if len(plines.errors_routing) > 0:
# Worksheet 4 - Fehlgeschlagenes Routing
ws4 = wb.create_sheet("Routing Errors")
ws4 = wb.create_sheet("ERR-Routing")
ws4.append(["Subdistributor", "Sensor / Actuator", "Details"])
nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists)
@@ -329,8 +334,9 @@ def write_excel_from_json(plines:Polylines, outpath:str):
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"])
# Wenn Distributor nicht in Layout gefunden, dann nur diesen Fehler ausgeben. Alle Verbindungen hier fehlgeschlagen
if uv in plines.errors_dists_not_in_layout:
ws4.append([uv,"-", "Distributor not found in given layout."])
continue
for sensor in routing_error.sensoren:
@@ -346,6 +352,14 @@ def write_excel_from_json(plines:Polylines, outpath:str):
grund = "Failed routing (not caused by missing connection)"
ws4.append([uv, sensor, grund])
if len(plines.errors_missing_attributes) > 0:
# Worksheet 5 - Fehlende Attribute -> kein Routing
ws5 = wb.create_sheet("ERR-Attributes")
ws5.append(["ID", "Error Detail"])
for sname, err_msg in plines.errors_missing_attributes.items():
ws5.append([sname, err_msg])
wb.save(outpath)