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:
+18
-17
@@ -273,7 +273,7 @@ def export_excel(plines, out_path):
|
|||||||
|
|
||||||
def write_excel_from_json(plines:Polylines, outpath:str):
|
def write_excel_from_json(plines:Polylines, outpath:str):
|
||||||
wb = Workbook()
|
wb = Workbook()
|
||||||
sens2cable = map_sensor_to_cable(plines)
|
sens2cable = map_sensor_to_cable_cfg(plines)
|
||||||
# Dicts für Anzahl bzw kummulierte Länge
|
# Dicts für Anzahl bzw kummulierte Länge
|
||||||
count_summary = defaultdict(int)
|
count_summary = defaultdict(int)
|
||||||
length_summary = defaultdict(float)
|
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
|
length = pl.length /1000 # Umrechnung von mm in m
|
||||||
for artnr in sens2cable[pl.id]:
|
for artnr in sens2cable[pl.id]:
|
||||||
cable_name = ""
|
cable_name = ""
|
||||||
if artnr != "Kabel länger als max. Kabellänge":
|
if artnr.isdigit():
|
||||||
cable_name = cable_cfg["Sivasnummern"][artnr]
|
cable_name = cable_cfg["Sivasnummern"][artnr]
|
||||||
ws1.append([pl.id, length, artnr, cable_name])
|
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):
|
def get_cable_artnr(section, length):
|
||||||
"""
|
"""
|
||||||
Sucht in der angegebenen Config-Section die passende Kabel-Artikelnr. für die gegebene Länge.
|
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:
|
if section not in cable_cfg:
|
||||||
return None
|
return False, f"Keine Kabelkennzeichnung '{section}' in kabel.cfg"
|
||||||
|
|
||||||
entries = cable_cfg[section]
|
entries = cable_cfg[section]
|
||||||
|
|
||||||
# Alle Einträge der Form: "5" = "123456789"
|
|
||||||
length_keys = sorted([float(k) for k in entries.keys()])
|
length_keys = sorted([float(k) for k in entries.keys()])
|
||||||
|
|
||||||
for l in length_keys:
|
for l in length_keys:
|
||||||
if length <= l:
|
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):
|
def map_sensor_to_cable(plines):
|
||||||
sens2cable = defaultdict(list)
|
sens2cable = defaultdict(list)
|
||||||
@@ -499,34 +500,34 @@ def map_sensor_to_cable_cfg(plines):
|
|||||||
|
|
||||||
for pl in plines.kabel:
|
for pl in plines.kabel:
|
||||||
sensor_name = pl.id.split('-')[-1]
|
sensor_name = pl.id.split('-')[-1]
|
||||||
cable_length = pl.length/1000
|
cable_length = round(pl.length/1000, 1)
|
||||||
sensor_artinr = pl.s_artinr
|
sensor_artinr = pl.s_artinr
|
||||||
name_prefix = sensor_name[:2]
|
name_prefix = sensor_name[:2]
|
||||||
|
|
||||||
# Suche nach Key in der BMK-Config
|
# 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:
|
if key_with_artnr in mapping:
|
||||||
section_list = mapping[key_with_artnr]
|
section_list = mapping[key_with_artnr]
|
||||||
elif name_prefix in mapping:
|
elif name_prefix in mapping: # Standardzuweisung
|
||||||
section_list = mapping[name_prefix]
|
section_list = mapping[name_prefix]
|
||||||
else:
|
else:
|
||||||
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen")
|
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen (BMK.cfg)")
|
||||||
|
|
||||||
# Liste aus evtl. mehreren Sektionen erzeugen
|
# 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):
|
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))
|
length_reduction = float(config_BMK.get("Length-Adjustments", name_prefix))
|
||||||
cable_length = max(0.0, cable_length-length_reduction)
|
cable_length = max(0.0, cable_length-length_reduction)
|
||||||
|
|
||||||
# Kabel-Atikelnummer innerhalb der Sektion der kabel.cfg bestimmen
|
# Kabel-Atikelnummer innerhalb der Sektion der kabel.cfg bestimmen
|
||||||
for section in sections:
|
for section in sections:
|
||||||
cable_artnr = get_cable_artnr(section, cable_length)
|
sucess, result = get_cable_artnr(section, cable_length)
|
||||||
if cable_artnr is None:
|
if not sucess:
|
||||||
sens2cable[pl.id].append(f"Kabel länger als max. Kabellänge")
|
sens2cable[pl.id].append(result)
|
||||||
else:
|
else:
|
||||||
sens2cable[pl.id].append(cable_artnr)
|
sens2cable[pl.id].append(result)
|
||||||
|
|
||||||
return sens2cable
|
return sens2cable
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -83,6 +83,9 @@ def get_type_of_name_cfg(name):
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
def get_attributes_of_insert(insert):
|
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 = ""
|
id = ""
|
||||||
ld = dict()
|
ld = dict()
|
||||||
typ = 'unknown'
|
typ = 'unknown'
|
||||||
@@ -95,7 +98,7 @@ def get_attributes_of_insert(insert):
|
|||||||
ld[attr_tag] = attr_text
|
ld[attr_tag] = attr_text
|
||||||
|
|
||||||
if attr_tag == "IO":
|
if attr_tag == "IO":
|
||||||
typ = get_type_of_name(attr_text)
|
typ = get_type_of_name_cfg(attr_text)
|
||||||
id = attr_text
|
id = attr_text
|
||||||
#print(f"-- coord io {id}--: {attrib.dxf.insert}") # position des Blocks
|
#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
|
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":
|
if attr_tag == "B":
|
||||||
# Suche nach Sensoren
|
# Suche nach Sensoren
|
||||||
typ = get_type_of_name(attr_text)
|
typ = get_type_of_name_cfg(attr_text)
|
||||||
id = attr_text
|
id = attr_text
|
||||||
pos = attrib.dxf.insert #Position aufzeichnen und bei Bedarf später mit REAL_POS überschreiben
|
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))
|
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:
|
def get_input_positions_iter(dxf_path) -> tuple:
|
||||||
return extract_input_positions(iterdxf.modelspace(dxf_path))
|
return extract_input_positions(iterdxf.modelspace(dxf_path))
|
||||||
|
|
||||||
def create_mappings(positions:dict) -> dict:
|
def create_mappings(positions:dict) -> tuple:
|
||||||
unterverteiler_pfad = ""
|
unterverteiler_pfad = ""
|
||||||
dnamen = dict()
|
dnamen = dict()
|
||||||
# sammle die Sensoren mit ihren zugehörigen Unterverteilern
|
# sammle die Sensoren mit ihren zugehörigen Unterverteilern
|
||||||
|
|||||||
Reference in New Issue
Block a user