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