From ec6d903515c5d36e7c39ad89e572e675f86cade2 Mon Sep 17 00:00:00 2001 From: mistangl Date: Thu, 14 Aug 2025 17:09:16 +0200 Subject: [PATCH] wenn nur ein Tunnel oder zu viele gleichlautende Tunnel definiert wurden, dann Fehler werfen --- lib/getpositions.py | 20 +++++++++++++++++--- lib/plant.py | 12 +++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/getpositions.py b/lib/getpositions.py index a705f45..53afb3e 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -621,10 +621,11 @@ def check_file_in_work(work_dir: Path, filename: Path) -> tuple[Path, bool]: mypath = filename return mypath, fexists -def check_existance(res_mappings: dict, res_dist: dict, res_pos: dict) -> dict: +def check_existance(res_mappings: dict, res_dist: dict, res_pos: dict, res_tunnel: dict) -> dict: ret = dict() ret["missing_distributors"] = list() ret["missing_sensors"] = list() + ret["missing_tunnel"] = list() for dname in res_mappings.keys(): if dname not in res_dist: ret["missing_distributors"].append(dname) @@ -632,7 +633,13 @@ def check_existance(res_mappings: dict, res_dist: dict, res_pos: dict) -> dict: for s in lofsensors: if s not in res_pos: ret['missing_sensors'].append(s) - + for tname in res_tunnel.keys(): + if len(res_tunnel[tname]) < 2 : + ret["missing_tunnel"].append(tname) + if len(res_tunnel[tname]) > 2 : + if "overdefined_tunnel" not in ret: + ret["overdefined_tunnel"] = list() + ret["overdefined_tunnel"].append(tname) return ret def dxf_is_binary(dxf_path: Path) -> bool: @@ -810,11 +817,18 @@ if __name__ == '__main__': if args.write: basename = os.path.splitext(args.write)[0] - res_not_found = check_existance(res_mappings, res_dist, res_sens) + res_not_found = check_existance(res_mappings, res_dist, res_sens, res_tunnel) + if args.errors and "overdefined_tunnel" in res_not_found: + print("unorrect tunnels found. Writing errors-file.") + err_ids = list(res_not_found["overdefined_tunnel"]) + write_results(to_json(list(err_ids)), work_dir, args.errors) + added_warnings = merge_two_dicts(warnings, missing_attribs) res_not_found["missing_attributes"] = added_warnings output_results["not_found"] = res_not_found output_results["double_ids"] = res_double + + write_results(to_json(output_results), work_dir, f"{basename}.json") else: diff --git a/lib/plant.py b/lib/plant.py index 14e868c..3572531 100644 --- a/lib/plant.py +++ b/lib/plant.py @@ -434,11 +434,13 @@ class Anlage(): die Rückage enthält ein Tuple, welche Tunnel keinem Rack zugeordnet werden konnten ''' for tname, pos in self._tunnels.items(): - tunbeg = pos[0] - tunend = pos[1] - trackname = f"t-Rack-{tname}" - self._racks.add_rack(tunbeg, tunend, trackname) - + if len(pos) == 2: + tunbeg = pos[0] + tunend = pos[1] + trackname = f"t-Rack-{tname}" + self._racks.add_rack(tunbeg, tunend, trackname) + else: + raise Exception("Tunnel has more than one begin and end/ just one begin") errors = list() for name, pos in self._tunnels.items(): p1 = self._tunnels[name][0]