Kabel-Config komplett mit float zahlen als keys versehen. Fehlermeldungen angepasst. Übeprüfung des pos-Eintrags im dict vo merge_two_dict wieder einkommentiert.

This commit is contained in:
2025-06-10 16:05:28 +02:00
parent 7733b50609
commit 2d29705d4a
2 changed files with 14 additions and 20 deletions
+8 -14
View File
@@ -115,7 +115,7 @@ def draw_cables(plines, doc):
# Polyline für Kabel zeichnen # Polyline für Kabel zeichnen
add_polyline(msp, pl, dxfattribs_cable) 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 ''' 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 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 sensors[name] = sensor
return sensors return sensors
def export_excel(json_file, out_path): def export_excel(plines, out_path):
# Hier für Excel Export # Hier für Excel Export
print("creating excel file with cable information ..") print("creating excel file with cable information ..")
plines = model_from_json(json_file)
sens2cable = map_sensor_to_cable(sensors, plines) sens2cable = map_sensor_to_cable(sensors, plines)
write_excel_from_json(plines, sens2cable, out_path) write_excel_from_json(plines, sens2cable, out_path)
print("done") print("done")
@@ -438,20 +437,14 @@ def get_cable_artnr(section, length):
entries = cable_cfg[section] entries = cable_cfg[section]
# Alle Einträge der Form: "5" = "123456789" # Alle Einträge der Form: "5" = "123456789"
try: length_keys = sorted([float(k) for k in entries.keys()])
length_keys = sorted(
[float(k) for k in entries.keys() if k.replace('.', '', 1).isdigit()]
)
except ValueError:
return None
for l in length_keys: for l in length_keys:
if length <= l: 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 return None
def map_sensor_to_cable(sensors, plines): def map_sensor_to_cable(sensors, plines):
sens2cable = defaultdict() sens2cable = defaultdict()
for pl in plines.kabel: for pl in plines.kabel:
@@ -468,6 +461,7 @@ def map_sensor_to_cable(sensors, plines):
section = None #Default section = None #Default
# Hier MB ebenfalls als Motor gezählt. Motoren in Fortna-Layout nicht angebunden!
if name_prefix == "MA" or name_prefix == "MB": if name_prefix == "MA" or name_prefix == "MB":
section = "MA" section = "MA"
@@ -483,11 +477,11 @@ def map_sensor_to_cable(sensors, plines):
section = "WD_I" section = "WD_I"
if section is None: if section is None:
cable_artnr = "KEIN KABEL" cable_artnr = "Kein Kabeltyp zu Sensor-Artikelnummer zugewiesen"
else: else:
cable_artnr = get_cable_artnr(section, cable_length) cable_artnr = get_cable_artnr(section, cable_length)
if cable_artnr is None: if cable_artnr is None:
cable_artnr = "KEIN KABEL" cable_artnr = "Kabel länger als max. Kabellänge"
sens2cable[pl.id] = cable_artnr sens2cable[pl.id] = cable_artnr
@@ -573,7 +567,7 @@ if __name__ == '__main__':
if args.excel: if args.excel:
excel_path = os.path.join(work_dir, args.excel) excel_path = os.path.join(work_dir, args.excel)
export_excel(json_path, excel_path) export_excel(plines, excel_path)
+6 -6
View File
@@ -160,11 +160,11 @@ def get_input_positions_iter(dxf_path) -> tuple:
# Nur wenn eine ID vorhanden ist, und eine gültige Position existiert # Nur wenn eine ID vorhanden ist, und eine gültige Position existiert
if typ == "Sensor": if typ == "Sensor":
#if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2:
if id in allSensors: if id in allSensors:
allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos"
else: else:
allSensors[id] = ld allSensors[id] = ld
elif typ == "Kabel": elif typ == "Kabel":
allCables[id] = ld allCables[id] = ld
elif typ == "Schaltschrankelement": elif typ == "Schaltschrankelement":
@@ -464,7 +464,7 @@ if __name__ == '__main__':
msp = doc.modelspace() msp = doc.modelspace()
use_iter = False use_iter = False
else: 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 use_iter = True
res_sens = dict() res_sens = dict()