Fehlerhandling für Sensoren und Distributoren die nicht zugeordnet werden konnten. Sammlung und Ausgabe in eigenen Key für die Ergebnisse
This commit is contained in:
+2
-2
@@ -591,7 +591,7 @@ class Anlage():
|
||||
for dname, listofsensors in d2sensors.items():
|
||||
self.map_distributor_to_sensors(dname, listofsensors)
|
||||
|
||||
def create_cable_path(self, G, sname, dname):
|
||||
def create_cable_path(self, G, sname, dname) -> tuple:
|
||||
quelle = self._nodeids.get_id(self.get_distributor_point(dname))
|
||||
ziel = self._nodeids.get_id(self.get_sensor_point(sname))
|
||||
pfad_nodes = nx.shortest_path(G, source=quelle, target=ziel, weight='weight')
|
||||
@@ -599,7 +599,7 @@ class Anlage():
|
||||
|
||||
return pfad_nodes, pfad_length
|
||||
|
||||
def create_cable_paths(self, G):
|
||||
def create_cable_paths(self, G) -> dict:
|
||||
pfade = dict()
|
||||
pfade["kabel"] = list()
|
||||
for sname, dname in self._sensor2dist.items():
|
||||
|
||||
+12
-6
@@ -27,7 +27,7 @@ def to_json(d, pretty: bool = True) -> str:
|
||||
return json.dumps(d, indent=2 if pretty else None, ensure_ascii=False, default=str) #ensure_ascii false für darstellung von "ue"
|
||||
|
||||
|
||||
def create_plant(racks:dict, sensors:dict, distributors:dict, mapping:dict):
|
||||
def create_plant(racks:dict, sensors:dict, distributors:dict, mapping:dict) -> dict:
|
||||
|
||||
# racks = {'Rack_1-0': [Point(0, 0), Point(0, 10)],
|
||||
# 'Rack_2-0': [Point(10, -2), Point(10, 5)],
|
||||
@@ -60,11 +60,11 @@ def create_plant(racks:dict, sensors:dict, distributors:dict, mapping:dict):
|
||||
# Füge Sensoren als Knoten hinzu
|
||||
an.add_sensors(sensors)
|
||||
# Verbinde Sensoren mit deren naheliegendsten Racks
|
||||
an.connect_sensors_to_racks()
|
||||
errors_sensors = an.connect_sensors_to_racks()
|
||||
# Füge UV hinzu
|
||||
an.add_distributors(distributors)
|
||||
# Verbinde UV mit deren naheliegendsten Racks
|
||||
an.connect_distributor_to_racks()
|
||||
errors_dists = an.connect_distributor_to_racks()
|
||||
# Verknüpfe Sensoren mit zugehörigem UV
|
||||
an.map_distributors_to_sensors(mapping)
|
||||
|
||||
@@ -78,6 +78,8 @@ def create_plant(racks:dict, sensors:dict, distributors:dict, mapping:dict):
|
||||
if args.graph:
|
||||
draw_graph(G,an)
|
||||
|
||||
paths['errors_sensors'] = errors_sensors
|
||||
paths['errors_dists'] = errors_dists
|
||||
return paths
|
||||
|
||||
def draw_graph(G:nx.Graph, an:Anlage):
|
||||
@@ -139,9 +141,13 @@ if __name__ == "__main__":
|
||||
(racks, sensors, subdists, mapping) = prepare_data(rawdata)
|
||||
|
||||
# virtuelle Anlage erstellen
|
||||
plant = create_plant(racks, sensors, subdists, mapping)
|
||||
|
||||
cable_paths = plant
|
||||
cable_paths = create_plant(racks, sensors, subdists, mapping)
|
||||
if args.console:
|
||||
print(to_json(cable_paths))
|
||||
print("failed sensor:")
|
||||
print(to_json(cable_paths['errors_sensors']))
|
||||
print("failed dists:")
|
||||
print(to_json(cable_paths['errors_dists']))
|
||||
|
||||
# Ausgabe schreiben
|
||||
if args.write:
|
||||
|
||||
Reference in New Issue
Block a user