Verwendung der Config Basierten Sensor-Typisierung und Kabel Abfage mithilfe von BMK.cfg.

Hier evtl in Zukunft zusammenlegen der beiden Configs zu einer (-> Abklärung mit Fachabteilung)
This commit is contained in:
2025-06-13 11:00:34 +02:00
parent 68d1519853
commit 15187ab85f
2 changed files with 24 additions and 20 deletions
+18 -17
View File
@@ -273,7 +273,7 @@ def export_excel(plines, out_path):
def write_excel_from_json(plines:Polylines, outpath:str):
wb = Workbook()
sens2cable = map_sensor_to_cable(plines)
sens2cable = map_sensor_to_cable_cfg(plines)
# Dicts für Anzahl bzw kummulierte Länge
count_summary = defaultdict(int)
length_summary = defaultdict(float)
@@ -287,7 +287,7 @@ def write_excel_from_json(plines:Polylines, outpath:str):
length = pl.length /1000 # Umrechnung von mm in m
for artnr in sens2cable[pl.id]:
cable_name = ""
if artnr != "Kabel länger als max. Kabellänge":
if artnr.isdigit():
cable_name = cable_cfg["Sivasnummern"][artnr]
ws1.append([pl.id, length, artnr, cable_name])
@@ -434,20 +434,21 @@ def copy_layers_into_dxf_by_filter(dxf_source: ezdxf.document.Drawing, dxf_targe
def get_cable_artnr(section, length):
"""
Sucht in der angegebenen Config-Section die passende Kabel-Artikelnr. für die gegebene Länge.
Übergibt bei Treffer True, artnr
bei Fehler: False, errmsg
"""
# Existiert über BMK vergebene Kabel-Kennzeichnung in kabel.cfg?
if section not in cable_cfg:
return None
return False, f"Keine Kabelkennzeichnung '{section}' in kabel.cfg"
entries = cable_cfg[section]
# Alle Einträge der Form: "5" = "123456789"
length_keys = sorted([float(k) for k in entries.keys()])
for l in length_keys:
if length <= l:
return entries[str(l)] # Annahme: Keys sind ganze Zahlen in Metern
return True, entries[str(l)]
return None
return False, f"Kabel länger als max. Kabellänge in Sektion '{section}'"
def map_sensor_to_cable(plines):
sens2cable = defaultdict(list)
@@ -499,34 +500,34 @@ def map_sensor_to_cable_cfg(plines):
for pl in plines.kabel:
sensor_name = pl.id.split('-')[-1]
cable_length = pl.length/1000
cable_length = round(pl.length/1000, 1)
sensor_artinr = pl.s_artinr
name_prefix = sensor_name[:2]
# Suche nach Key in der BMK-Config
key_with_artnr = f"{name_prefix}-{sensor_artinr}"
key_with_artnr = f"{name_prefix}-{sensor_artinr}" # Spezialfälle über "Key mit Artikelnummer" abgleichen
if key_with_artnr in mapping:
section_list = mapping[key_with_artnr]
elif name_prefix in mapping:
elif name_prefix in mapping: # Standardzuweisung
section_list = mapping[name_prefix]
else:
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen")
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen (BMK.cfg)")
# Liste aus evtl. mehreren Sektionen erzeugen
sections = [s.strip for s in section_list.split(",")]
sections = [s.strip() for s in section_list.split(",")]
# Evtl. Kabelkürzung durchführen, fall Kabelschwanz vorhanden
# Evtl. Kabelkürzung durchführen, falls Kabelschwanz vorhanden
if config_BMK.has_section("Length-Adjustments") and config_BMK.has_option("Length-Adjustments", name_prefix):
length_reduction = float(config_BMK.get("Length-Adjustments", name_prefix))
cable_length = max(0.0, cable_length-length_reduction)
# Kabel-Atikelnummer innerhalb der Sektion der kabel.cfg bestimmen
for section in sections:
cable_artnr = get_cable_artnr(section, cable_length)
if cable_artnr is None:
sens2cable[pl.id].append(f"Kabel länger als max. Kabellänge")
sucess, result = get_cable_artnr(section, cable_length)
if not sucess:
sens2cable[pl.id].append(result)
else:
sens2cable[pl.id].append(cable_artnr)
sens2cable[pl.id].append(result)
return sens2cable
+6 -3
View File
@@ -83,6 +83,9 @@ def get_type_of_name_cfg(name):
return "unknown"
def get_attributes_of_insert(insert):
'''
Hier in Zukunft weniger Abfragen: IO und B und Reale_Position wird überflüssig wenn jeder Sensor nur noch eiun Block mit allen Attributen!
'''
id = ""
ld = dict()
typ = 'unknown'
@@ -95,7 +98,7 @@ def get_attributes_of_insert(insert):
ld[attr_tag] = attr_text
if attr_tag == "IO":
typ = get_type_of_name(attr_text)
typ = get_type_of_name_cfg(attr_text)
id = attr_text
#print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben
@@ -103,7 +106,7 @@ def get_attributes_of_insert(insert):
if attr_tag == "B":
# Suche nach Sensoren
typ = get_type_of_name(attr_text)
typ = get_type_of_name_cfg(attr_text)
id = attr_text
pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben
ld["pos"] = (round(pos.x, 1), round(pos.y, 1))
@@ -155,7 +158,7 @@ def get_input_positions(msp) -> tuple:
def get_input_positions_iter(dxf_path) -> tuple:
return extract_input_positions(iterdxf.modelspace(dxf_path))
def create_mappings(positions:dict) -> dict:
def create_mappings(positions:dict) -> tuple:
unterverteiler_pfad = ""
dnamen = dict()
# sammle die Sensoren mit ihren zugehörigen Unterverteilern