getpositions schreibt nur noch eine json Ergebnisdatei raus. Config launch.json und routing.py angepasst; in Requirements networkx aufgenommen.

This commit is contained in:
2025-05-09 20:49:47 +02:00
parent 9b1f3bef80
commit ae86dbcafa
6 changed files with 91 additions and 11 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ from dataclasses import dataclass, asdict, fields
from dacite import from_dict
from typing import List
from datetime import datetime
import shutil
@@ -73,7 +73,7 @@ def new_dxf(json_file, dxf_file, out_path):
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', metavar='myfile.json')
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('-d', '--dxf', action='store', required=True, help='this dxf drawing will be copied and the new layer with the cables will be added', metavar='myfile.dxf')
args = parser.parse_args()
+10 -2
View File
@@ -170,6 +170,7 @@ if __name__ == '__main__':
parser.add_argument('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors')
parser.add_argument('-d', '--dists', action='store_true', help='fetch all positions of all subdistributors')
parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks')
parser.add_argument('-w', '--write', action='store_true', help='write results into a json file')
parser.add_argument('-c', '--console', action='store_true', help='print results to output')
args = parser.parse_args()
@@ -179,7 +180,8 @@ if __name__ == '__main__':
config_dir = os.environ.get("PROJECT_CFG")
filename = args.filename
doc = get_dxf_file(os.path.join(work_dir, filename)) # type: ignore
dxf_path = os.path.join(work_dir, filename)
doc = get_dxf_file(dxf_path) # type: ignore
msp = doc.modelspace()
res_pos = dict()
@@ -190,21 +192,27 @@ if __name__ == '__main__':
config = configparser.ConfigParser(allow_no_value=True)
config.read(os.path.join(config_dir, "getpositions.cfg"))
output_results = dict()
if args.sensors:
res_pos = get_input_positions(msp)
output_results['sensors'] = res_pos
if args.console:
print(to_json(res_pos))
write_results(to_json(res_pos), work_dir, "sensors.json")
if args.dists:
res_dist = get_subdistributor_positions(msp)
output_results['distributors'] = res_dist
if args.console:
print(to_json(res_dist))
write_results(to_json(res_dist), work_dir, "subdistributors.json")
if args.rack:
res_rac = get_rack_positions(msp)
output_results['racks'] = res_rac
if args.console:
print(to_json(res_rac))
write_results(to_json(res_rac), work_dir, "racks.json")
if args.write:
basename = os.path.splitext(args.filename)[0]
write_results(to_json(output_results), work_dir, basename+"_positions.json")
else:
parser.print_help()
+2
View File
@@ -1,2 +1,4 @@
matplotlib=3.10.0
networkx==3.4.2
dacite==1.9.2
ezdxf==1.4.1
+8 -6
View File
@@ -122,6 +122,7 @@ def node_to_coords(node_name, racks):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Berechne Wege von Sensoren zu Verteilern über Kabeltrassen')
parser.add_argument('-i', '--inputfile', 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')
args = parser.parse_args()
@@ -131,14 +132,15 @@ if __name__ == "__main__":
config_dir = os.environ.get("PROJECT_CFG")
# Pfade zu JSON-Dateien
sensors_path = os.path.join(work_dir, "sensors.json")
subdist_path = os.path.join(work_dir, "subdistributors.json")
racks_path = os.path.join(work_dir, "racks.json")
jsonfilename = args.inputfile
sensors_path = os.path.join(work_dir, jsonfilename)
# Einlesen
sensors = load_json(sensors_path)
subdists = load_json(subdist_path)
racks = load_json(racks_path)
data = load_json(sensors_path)
sensors = data["sensors"]
subdists = data["distributors"]
racks = data["racks"]
# Graph erstellen
graph = {}