Merge branch 'main' of http://gitea.schoenenberger.de/mistangl/kabellaengen
This commit is contained in:
+40
-40
@@ -12,9 +12,6 @@ from collections import defaultdict
|
||||
import configparser
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Point:
|
||||
x: float
|
||||
@@ -60,7 +57,7 @@ def add_polyline(msp, points:Polyline, dxf_attribs):
|
||||
def new_dxf(plines, out_path):
|
||||
""" creates a new dxf file with a polyline inside which is created by the given json file
|
||||
"""
|
||||
print("creating dxf ..")
|
||||
print("creating new .dxf ..")
|
||||
|
||||
doc = ezdxf.new('R2018', setup=True)
|
||||
create_cables(plines, doc)
|
||||
@@ -72,7 +69,7 @@ def new_dxf(plines, out_path):
|
||||
def modify_original_dxf(plines, originaldxf):
|
||||
""" adds new layer to original .dxf-file that contains cables
|
||||
"""
|
||||
print("adding cables to original .dxf ..")
|
||||
print("adding cables into original .dxf ..")
|
||||
|
||||
doc = ezdxf.readfile(originaldxf)
|
||||
create_cables(plines, doc)
|
||||
@@ -84,7 +81,7 @@ def modify_original_dxf(plines, originaldxf):
|
||||
def copy_layers_into_new(originaldxf, outpath, plines):
|
||||
""" creates a new dxf file with a racks, sensors, subdists from original file including cable paths
|
||||
"""
|
||||
print("copying layers from original .dxf into new .dxf ..")
|
||||
print("copying layers (Racks, Subdistributors, ...) from original .dxf into new .dxf ..")
|
||||
|
||||
quelle = ezdxf.readfile(originaldxf)
|
||||
ziel = ezdxf.new('R2018', setup=True)
|
||||
@@ -123,7 +120,7 @@ def model_from_json(json_file):
|
||||
|
||||
def export_excel(json_file, out_path):
|
||||
# Hier für Excel Export
|
||||
print("creating excel file ..")
|
||||
print("creating excel file with cable information ..")
|
||||
plines = model_from_json(json_file)
|
||||
write_excel_from_json(plines, out_path)
|
||||
print("done")
|
||||
@@ -135,8 +132,8 @@ def write_excel_from_json(plines:Polylines, outpath:str):
|
||||
|
||||
#Worksheet 1 - Kabellängen
|
||||
ws1 = wb.active
|
||||
ws1.title = "Kabellängen"
|
||||
ws1.append(["Kabel-ID", "Länge aus Json (m)", "Gerundete Länge (m)"])
|
||||
ws1.title = "Length by ID"
|
||||
ws1.append(["Cable-ID", "True Length (m)", "Rounded Length (m)"])
|
||||
|
||||
for pl in plines.kabel:
|
||||
length = pl.length /1000 # Umrechnung von mm in m
|
||||
@@ -145,48 +142,51 @@ def write_excel_from_json(plines:Polylines, outpath:str):
|
||||
ws1.append([pl.id, length, int(rounded_len)])
|
||||
|
||||
# Worksheet 2 - Zusammengefasste Längen
|
||||
ws2 = wb.create_sheet("Längenübersicht")
|
||||
ws2.append(["Gerundete Länge (m)", "Anzahl Kabel"])
|
||||
ws2 = wb.create_sheet("Length Summary")
|
||||
ws2.append(["Rounded Length (m)", "Number of Cables"])
|
||||
|
||||
for rlength in sorted(length_summary):
|
||||
ws2.append([int(rlength), length_summary[rlength]])
|
||||
|
||||
# Worksheet 3 - Nicht an Racks gekoppeltes Equipment
|
||||
ws3 = wb.create_sheet("Equipment nicht angebunden")
|
||||
ws3.append(["Typ", "Name", "x", "y"])
|
||||
for error in plines.errors_sensors:
|
||||
ws3.append(["Sensor / Aktor", error.name, error.coords.x, error.coords.y])
|
||||
if len(plines.errors_existing_sensors) > 0 or len(plines.errors_dists) > 0:
|
||||
# Worksheet 3 - Nicht an Racks gekoppeltes Equipment
|
||||
ws3 = wb.create_sheet("Not connected Equipment")
|
||||
ws3.append(["Type", "ID", "x", "y"])
|
||||
for error in plines.errors_sensors:
|
||||
ws3.append(["Sensor / Actuator", error.name, error.coords.x, error.coords.y])
|
||||
|
||||
for error in plines.errors_dists:
|
||||
ws3.append(["Unterverteiler", error.name, error.coords.x, error.coords.y])
|
||||
for error in plines.errors_dists:
|
||||
ws3.append(["Subistributor", error.name, error.coords.x, error.coords.y])
|
||||
|
||||
# Worksheet 4 - Fehlgeschlagenes Routing
|
||||
ws4 = wb.create_sheet("Routingfehler")
|
||||
ws4.append(["Unterverteiler", "Sensor- / Aktorname", "Grund"])
|
||||
|
||||
nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists)
|
||||
if len(plines.errors_routing) > 0:
|
||||
# Worksheet 4 - Fehlgeschlagenes Routing
|
||||
ws4 = wb.create_sheet("Routing Errors")
|
||||
ws4.append(["Subdistributor", "Sensor / Actuator", "Details"])
|
||||
|
||||
for routing_error in plines.errors_routing:
|
||||
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 layout"])
|
||||
continue
|
||||
nicht_angebunden = set(e.name for e in plines.errors_sensors + plines.errors_dists)
|
||||
|
||||
for sensor in routing_error.sensoren:
|
||||
sensor_nicht_angebunden = sensor in nicht_angebunden
|
||||
for routing_error in plines.errors_routing:
|
||||
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"])
|
||||
continue
|
||||
|
||||
if sensor_nicht_angebunden and uv_nicht_angebunden:
|
||||
grund = "Sensor und Unterverteiler nicht angebunden"
|
||||
elif sensor_nicht_angebunden:
|
||||
grund = "Sensor / Aktor nicht angebunden"
|
||||
elif uv_nicht_angebunden:
|
||||
grund = "Unterverteiler nicht angebunden"
|
||||
else:
|
||||
grund = "Fehlgeschlagenes Routing trotz Anbindung"
|
||||
for sensor in routing_error.sensoren:
|
||||
sensor_nicht_angebunden = sensor in nicht_angebunden
|
||||
|
||||
ws4.append([uv, sensor, grund])
|
||||
if sensor_nicht_angebunden and uv_nicht_angebunden:
|
||||
grund = "Subdistributor and sensor / actuator not connected to racks"
|
||||
elif sensor_nicht_angebunden:
|
||||
grund = "Sensor / actuator not connected to racks"
|
||||
elif uv_nicht_angebunden:
|
||||
grund = "Subdistributor not connected to racks"
|
||||
else:
|
||||
grund = "Failed routing (not caused by missing connection)"
|
||||
|
||||
ws4.append([uv, sensor, grund])
|
||||
|
||||
|
||||
wb.save(outpath)
|
||||
|
||||
+5
-5
@@ -148,11 +148,11 @@ def prepare_data(rawdata:dict):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Berechne Wege von Sensoren zu Verteilern über Kabeltrassen')
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, default="easy_position.json", help='file with all informations about positions gathered from getpositions', metavar='my_positions.json')
|
||||
parser.add_argument('-c', '--console', action='store_true', help='Ausgabe auf Konsole')
|
||||
parser.add_argument('-g', '--graph', action='store_true', help='Zeichnet den Graphen der Anlage')
|
||||
parser.add_argument('-w', '--write', action='store', help='erstellt Ausgabe-file für das Zeichnen von Kabeln in drawdxf')
|
||||
parser = argparse.ArgumentParser(description='Calculate cable-routing from Subdistributors zu sensors / actuators alon cable-racks')
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, default="file_positions.json", help='file with all informations about positions gathered from getpositions', metavar='my_positions.json')
|
||||
parser.add_argument('-c', '--console', action='store_true', help='print to console')
|
||||
parser.add_argument('-g', '--graph', action='store_true', help='draw and show generated graph')
|
||||
parser.add_argument('-w', '--write', action='store', help='create .json file to pass into drawing module to visualize results')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user