Funktion zum Abgleich der Namen der Unterverteiler mit den ANgaben in der Config geschrieben
This commit is contained in:
+41
-7
@@ -48,6 +48,20 @@ def get_type_of_name_cfg(name: str) -> str:
|
||||
return "unknown"
|
||||
|
||||
|
||||
def matches_cabinet_pattern(name: str) -> bool:
|
||||
"""Check if the given name matches any Cabinet-Pattern from BMK.cfg"""
|
||||
if not config_BMK.has_section("Cabinet-Pattern"):
|
||||
return False
|
||||
|
||||
patterns = [pattern for pattern, _ in config_BMK.items("Cabinet-Pattern")]
|
||||
|
||||
for pattern in patterns:
|
||||
if re.match(pattern, name):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, str]:
|
||||
"""
|
||||
Diese Funktion schaut nach den aktuell definierten Attributen in den Blöcken
|
||||
@@ -407,19 +421,17 @@ def create_mappings(positions: dict) -> tuple[dict, dict]:
|
||||
|
||||
return (uv2sensor, warnings)
|
||||
|
||||
def get_subdistributor_positions_of_symbol(d_insert: dict, d_pos: dict) -> tuple[dict, str, str]:
|
||||
def get_subdistributor_position_of_symbol(d_insert: dict, d_pos: dict) -> tuple[dict, str]:
|
||||
"""
|
||||
Diese Funktion schaut nach den aktuell definierten Attributen in den Blöcken
|
||||
die ID aus dem Eintrag unter "NAME"
|
||||
Diese Funktion schaut nach den aktuell definierten Attributen in allen Unterverteiler Blöcken
|
||||
Sie müssen auch UH heissen
|
||||
|
||||
"""
|
||||
id_ = ""
|
||||
ld = d_insert
|
||||
typ = 'unknown'
|
||||
|
||||
# die neueren Bläcke heissen nicht IO, sondern haben einen Namen
|
||||
# die neueren Blöcke haben einen Namen
|
||||
if "NAME" in d_insert:
|
||||
typ = get_type_of_name_cfg(d_insert["NAME"])
|
||||
id_ = d_insert["NAME"]
|
||||
pos = d_pos["NAME"]
|
||||
ld["pos"] = (pos[0], pos[1])
|
||||
@@ -433,8 +445,29 @@ def get_subdistributor_positions_of_symbol(d_insert: dict, d_pos: dict) -> tuple
|
||||
midx = pos[0] + breite_marker * 0.5
|
||||
midy = pos[1] + hoehe_marker * 0.5
|
||||
ld["pos"] = (round(midx, 1), round(midy, 1))
|
||||
return ld, id_
|
||||
return None, None
|
||||
|
||||
def get_subdistributor_positions_from_symbols(all_inserts:list, all_positions:list, dist2sensors: dict) -> dict:
|
||||
"""Ermittelt Unterverteiler-Positionen aus allen Symbolen
|
||||
"""
|
||||
ret = {}
|
||||
all_distributors = dist2sensors.keys()
|
||||
for insert, pos in zip(all_inserts, all_positions):
|
||||
if "NAME" not in insert: # Unterverteiler haben immer einen eindeutigen Namen
|
||||
continue
|
||||
ld, id_ = get_subdistributor_position_of_symbol(insert, pos)
|
||||
|
||||
# Check if id_ matches Cabinet-Pattern from BMK.cfg
|
||||
if not matches_cabinet_pattern(id_):
|
||||
continue
|
||||
|
||||
if f"-{id_}" in dist2sensors or f"+{id_}" in dist2sensors:
|
||||
# Fix: use ld["pos"] instead of undefined insert_point
|
||||
ret[id_] = ld["pos"]
|
||||
|
||||
return ret
|
||||
|
||||
return ld, id_, typ
|
||||
|
||||
def get_subdistributor_positions_from_entities(entities, dist2sensors: dict) -> dict:
|
||||
"""Ermittelt Unterverteiler-Positionen aus einer beliebigen Entity-Iterable.
|
||||
@@ -781,6 +814,7 @@ if __name__ == '__main__':
|
||||
else:
|
||||
entities = msp.query('MTEXT')
|
||||
res_dist = get_subdistributor_positions_from_entities(entities, res_mappings)
|
||||
new_res_dist = get_subdistributor_positions_from_symbols(all_inserts, all_positions, res_mappings)
|
||||
output_results['distributors'] = res_dist
|
||||
if args.console:
|
||||
print(to_json(res_dist))
|
||||
|
||||
Reference in New Issue
Block a user