Alle Programme so weit angepasst, dass Programmkette läuft.
This commit is contained in:
Vendored
+3
-2
@@ -109,14 +109,15 @@
|
||||
},
|
||||
|
||||
{
|
||||
"name": "routing for easy_positions.json",
|
||||
"name": "routing for easy.json",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"args": [
|
||||
"--filename",
|
||||
"easy_positions.json"
|
||||
"easy.json",
|
||||
"-g"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ for /F %%i in ("%1") do set FILENAME=%%~ni
|
||||
|
||||
getpositions.bat --filename %1 -s -r -w %1
|
||||
routing.bat --filename %FILENAME%.json -w todraw.json
|
||||
REM draw.bat --filename todraw.json --new -o %FILENAME%_cables.dxf
|
||||
draw.bat --filename todraw.json --new %FILENAME%_cables.dxf
|
||||
|
||||
+5
-5
@@ -84,14 +84,14 @@ def check_file_in_work(work_dir, filename):
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
|
||||
parser.add_argument('-j', '--jsonfile', action='store', required=True, help='this json file contains all cables and its coordinates which should be drawn. Saved with an unique timestamp', metavar='myfile.json')
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, help='this json file contains all cables and its coordinates which should be drawn. Saved with an unique timestamp', metavar='myfile.json')
|
||||
parser.add_argument('-d', '--dxf', action='store', help='this dxf drawing will be copied and the new layer with the cables will be added', metavar='myfile.dxf')
|
||||
parser.add_argument('-n', '--new', action='store_true', help='create a new dxf file with cables in it. Name is basename and a timtestamp')
|
||||
parser.add_argument('-n', '--new', action='store', help='create a new dxf file with cables in it. Name is basename and a timtestamp')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
work_dir = os.fspath(os.environ.get('PROJECT_WORK'))
|
||||
jfile = args.jsonfile
|
||||
jfile = args.filename
|
||||
(json_path, jexists) = check_file_in_work(work_dir, jfile)
|
||||
if not jexists:
|
||||
print("file %s does not exit", jfile)
|
||||
@@ -112,8 +112,8 @@ if __name__ == '__main__':
|
||||
# erzeuge eine neue dxf Datei mit aktuellen Zeitstempel im Namen
|
||||
#basename = os.path.splitext(dxf_path)[0]
|
||||
#timestamp = datetime.now().strftime(basename+"_%Y%m%d-%H%M%S.dxf")
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S.dxf")
|
||||
out_path = os.path.join(work_dir, timestamp)
|
||||
#timestamp = datetime.now().strftime("%Y%m%d-%H%M%S.dxf")
|
||||
out_path = os.path.join(work_dir, args.new)
|
||||
|
||||
res_pos = new_dxf(json_path, out_path)
|
||||
|
||||
+29
-17
@@ -6,7 +6,7 @@ from collections import defaultdict
|
||||
import bisect
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
from itertools import pairwise, combinations
|
||||
from itertools import pairwise, combinations, permutations
|
||||
import re
|
||||
|
||||
class PointSorter:
|
||||
@@ -108,10 +108,9 @@ class NodeIDs():
|
||||
def show(self):
|
||||
return self._id2cord
|
||||
class RackIDs():
|
||||
def __init__(self, racks=dict(), tol_snap = 1):
|
||||
def __init__(self, tol_snap = 200):
|
||||
self._point2rack = dict()
|
||||
self._rack2begend = dict()
|
||||
self.add_racks(racks)
|
||||
# Toleranzen zur Rack anbindung aneinander (Rack Snap)
|
||||
self._tol_snap = tol_snap
|
||||
|
||||
@@ -192,15 +191,21 @@ class RackIDs():
|
||||
self.add_point_to_rack(inter, rnames[l1])
|
||||
self.add_point_to_rack(inter, rnames[l2])
|
||||
|
||||
for (l1, l2) in combinations(allracks,2):
|
||||
for (l1, l2) in permutations(allracks,2):
|
||||
first = Point(l2.coords[0])
|
||||
last = Point(l2.coords[1])
|
||||
if l1.distance(first) <= self._tol_snap:
|
||||
snap_point = l1.interpolate(l1.project(first))
|
||||
self.add_point_to_rack(snap_point, rnames[l1])
|
||||
# Füge zusätzliches Rack als Verbindung zwischen Endpunkt und snap_point ein
|
||||
connrackname = f"c-{rnames[l2]}"
|
||||
self.add_rack(first, snap_point, connrackname)
|
||||
if l1.distance(last) <= self._tol_snap:
|
||||
snap_point = l1.interpolate(l1.project(last))
|
||||
self.add_point_to_rack(snap_point, rnames[l1])
|
||||
# Füge zusätzliches Rack als Verbindung zwischen Endpunkt und snap_point ein
|
||||
connrackname = f"c-{rnames[l2]}"
|
||||
self.add_rack(last, snap_point, connrackname)
|
||||
|
||||
def rack_is_horizontal(self, name):
|
||||
[pa, pe] = self._rack2begend[name]
|
||||
@@ -260,9 +265,9 @@ class Anlage():
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, tol_snap=200, snap_step=10, tol_connect=2, tol_connect_step=0.5):
|
||||
def __init__(self, tol_snap=200, snap_step=10, tol_connect=1000, tol_connect_step=50):
|
||||
# Container für alle Racks
|
||||
self._racks = RackIDs()
|
||||
self._racks = RackIDs(tol_snap=tol_snap)
|
||||
# zuordnung zwischen KnotenID und Punkt
|
||||
self._nodeids = NodeIDs()
|
||||
# Container für alle Sensoren
|
||||
@@ -282,7 +287,6 @@ class Anlage():
|
||||
# Infos zum zeichnen des Graphen
|
||||
self._node_positions = dict()
|
||||
|
||||
|
||||
def set_racks(self, racks:dict[str, list[Point]]):
|
||||
r"""
|
||||
Fügt racks aus eingelsener Datei zu Anlage hinzu.
|
||||
@@ -348,7 +352,7 @@ class Anlage():
|
||||
def connect_sensors_to_racks(self):
|
||||
for sname, pos in self._sensors.items():
|
||||
rack_borders = self._racks.get_racks_borders()
|
||||
onpoint, rack_name = self.find_nearest_rack_from_point(2, 0.5, pos, rack_borders)
|
||||
onpoint, rack_name = self.find_nearest_rack_from_point(self._tol_connect, self._connect_step, pos, rack_borders)
|
||||
self._sensor_onpoints[sname] = (onpoint, rack_name)
|
||||
self.add_point_to_rack(onpoint, rack_name)
|
||||
# Füge "virtuelle Racks" von Sensor zu Aufpunkt von Sensor auf Rack hinzu.
|
||||
@@ -576,12 +580,17 @@ class Anlage():
|
||||
|
||||
def create_cable_paths(self, G):
|
||||
pfade = dict()
|
||||
pfade["kabel"] = list()
|
||||
for sname, dname in self._sensor2dist.items():
|
||||
pfad_nodes, pfad_length = self.create_cable_path(G, sname, dname)
|
||||
pfad_coords = self._nodeids.get_points(pfad_nodes)
|
||||
pfade[f"{dname}-{sname}"] = {"path_nodes": pfad_nodes,
|
||||
"path_coords": pfad_coords,
|
||||
"path_length": pfad_length}
|
||||
tuplecoords = [(p.x, p.y) for p in pfad_coords]
|
||||
ld = dict()
|
||||
ld['id'] = f"{dname}-{sname}"
|
||||
ld["coords"]= [{"x":round(p.x,1), "y":round(p.y,1)} for p in pfad_coords]
|
||||
ld["length"]= round(pfad_length,1)
|
||||
ld["nodes"]=pfad_nodes
|
||||
pfade["kabel"].append(ld)
|
||||
|
||||
return pfade
|
||||
|
||||
@@ -645,16 +654,17 @@ class TestLinesweep(unittest.TestCase):
|
||||
racks_data = {
|
||||
'Rack_1': [Point(0, 0), Point(0, 10)],
|
||||
'Rack_2': [Point(1, 5), Point(5, 5)],
|
||||
'Rack_3': [Point(1.5, 7.5), Point(5,7.5)]
|
||||
'Rack_3': [Point(1.5, 7.5), Point(5, 7.5)]
|
||||
}
|
||||
|
||||
# Initialisiere Racks
|
||||
rack = RackIDs()
|
||||
rack = RackIDs(tol_snap=1)
|
||||
# Füge Racks aus gegebenen Daten hinzu und teile Rack_1 bestehend aus 3 Punkten in 2 Racks auf
|
||||
rack.add_racks(racks_data)
|
||||
# Verknüpfe Racks mit echten Schnittpunkten und füge Schnittpunkte (exakt & beinahe) zu jeweiligem Rack hinzu
|
||||
rack.join_racks()
|
||||
|
||||
#Rack 2 wird verlängert auf SP mit Rack 1. Rack 3 ausserhalb der Toleranz
|
||||
self.assertEqual(rack.get_points_from_rack("Rack_1"), [Point(0, 0), Point(0, 5), Point (0, 10)])
|
||||
|
||||
|
||||
@@ -666,7 +676,8 @@ class TestLinesweep(unittest.TestCase):
|
||||
'Rack_2-1': [Point(0, 10), Point(5, 10)]}
|
||||
|
||||
|
||||
point2rack = RackIDs(res_rack_seg)
|
||||
point2rack = RackIDs()
|
||||
point2rack.add_racks(res_rack_seg)
|
||||
|
||||
self.assertEqual(point2rack.get_racks_from_point(Point(1, 0)), ["Rack_1-0", "Rack_2-0"])
|
||||
self.assertEqual(point2rack.get_racks_from_point(Point(5, 6)), ["Rack_1-0"])
|
||||
@@ -681,7 +692,8 @@ class TestLinesweep(unittest.TestCase):
|
||||
'Rack_2-1': [Point(0, 10), Point(5, 10)]}
|
||||
|
||||
|
||||
point2rack = RackIDs(res_rack_seg)
|
||||
point2rack = RackIDs()
|
||||
point2rack.add_racks(res_rack_seg)
|
||||
point2rack.add_point_to_rack(Point(1,4), "Rack_2-0")
|
||||
|
||||
self.assertEqual(point2rack.get_points_from_rack("Rack_2-0"), [Point(1, 0), Point(1,4), Point(1, 8)])
|
||||
@@ -757,7 +769,7 @@ class TestLinesweep(unittest.TestCase):
|
||||
|
||||
rack_segs = {'Rack_1': [Point(0, 0), Point(0, 10)],
|
||||
'Rack_2': [Point(10, -2), Point(10, 5)],
|
||||
'Rack_2': [Point(0, 3), Point(10, 3)]}
|
||||
'Rack_3': [Point(0, 3), Point(10, 3)]}
|
||||
|
||||
sensors = {'Sens_1': Point(1, 1),
|
||||
'Sens_2': Point(2, 4),
|
||||
@@ -770,7 +782,7 @@ class TestLinesweep(unittest.TestCase):
|
||||
'Dist_2': ['Sens_3']}
|
||||
|
||||
# Erstelle Anlage
|
||||
an = Anlage()
|
||||
an = Anlage(tol_snap=1)
|
||||
# Füge racks aus Daten hinzu
|
||||
an.set_racks(rack_segs)
|
||||
# Verbinde Racks miteinander (ggf. verlängere ungenaue Racks)
|
||||
|
||||
+24
-9
@@ -85,21 +85,36 @@ def draw_graph(G:nx.Graph, an:Anlage):
|
||||
|
||||
edge_colors = [G[u][v].get('color', 'black') for u, v in G.edges()]
|
||||
|
||||
nx.draw(G, pos, with_labels=False, node_size=10, font_size=8, edge_color=edge_colors)
|
||||
nx.draw(G, pos, with_labels=True, node_size=10, font_size=8, edge_color=edge_colors, node_color='none')
|
||||
nx.draw_networkx_nodes(G, pos, linewidths= 0.5, edgecolors = 'red', node_color = 'none')
|
||||
plt.show()
|
||||
|
||||
def prepare_data(rawdata:dict):
|
||||
sensors = rawdata["sensors"]
|
||||
dsensors = dict()
|
||||
for sname, sdata in sensors.items():
|
||||
dsensors[sname] = Point(sdata["pos"])
|
||||
|
||||
subdists = rawdata["distributors"]
|
||||
dsubdists = dict()
|
||||
for dname, pos in subdists.items():
|
||||
dsubdists[dname] = Point(pos)
|
||||
|
||||
racks = rawdata["racks"]
|
||||
mapping = rawdata["mapping"]
|
||||
dracks = dict()
|
||||
for rname,lp in racks:
|
||||
if rname not in dracks:
|
||||
dracks[rname] = list()
|
||||
dracks[rname].append(Point(lp))
|
||||
for rname,lp in racks.items():
|
||||
# if rname not in dracks:
|
||||
# dracks[rname] = list()
|
||||
# dracks[rname].append(Point(lp))
|
||||
ltemp = list()
|
||||
for p in lp:
|
||||
ltemp.append(Point(p))
|
||||
dracks[rname] = ltemp
|
||||
|
||||
mapping = rawdata["mappings"]
|
||||
|
||||
return (sensors, subdists, dracks, mapping)
|
||||
|
||||
return (dracks, dsensors, dsubdists, mapping)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -130,8 +145,8 @@ if __name__ == "__main__":
|
||||
|
||||
# Ausgabe schreiben
|
||||
if args.write:
|
||||
basename = os.path.splitext(args.write)[0]
|
||||
write_results(to_json(cable_paths), work_dir, f"{basename}.json")
|
||||
basename = os.path.splitext(args.write)[0]
|
||||
write_results(to_json(cable_paths), work_dir, f"{basename}.json")
|
||||
|
||||
|
||||
|
||||
|
||||
+6702
-15590
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user