Mit curser weiter bearbeitet. Schaltschrankelemente werden jettz auch von getpositions raus geschrieben

This commit is contained in:
2025-07-15 08:02:56 +02:00
parent a2d22500c4
commit 95f8f6722b
4 changed files with 39 additions and 20 deletions
+5 -4
View File
@@ -182,7 +182,7 @@ class CompareBuffer:
l.append(b)
return l
def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict]:
def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict, dict]:
all_sensors = dict()
all_cables = dict()
all_schaltschrank = dict()
@@ -216,7 +216,7 @@ def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict]:
# die noch übrigen Blöcke melden
missing_attribs, double_ids = get_errors_double_and_attributes(wp)
return all_sensors, double_ids, missing_attribs
return all_sensors, all_schaltschrank, double_ids, missing_attribs
def get_errors_double_and_attributes(wp: CompareBuffer) -> tuple[dict, dict]:
missing_attribs = dict()
@@ -664,9 +664,9 @@ if __name__ == '__main__':
if args.sensors:
# Sensoren auslesen
if use_iter:
res_sens, res_double, missing_attribs = get_input_positions_iter(dxf_path)
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_iter(dxf_path)
else:
res_sens, res_double, missing_attribs = get_input_positions(msp)
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions(msp)
if args.errors and len(res_double) > 0:
print("Duplicate blocks found. Writing errors-file.")
@@ -675,6 +675,7 @@ if __name__ == '__main__':
output_results['sensors'] = res_sens
output_results['schaltschrank_elemente'] = res_schaltschrank_elemente
#output_results['cables'] = res_cables
if args.console:
+1 -1
View File
@@ -416,7 +416,7 @@ class ExcelConverter:
elif export_type == "TIA":
df_gleiche_eingaenge, df_gleiche_ausgaenge, df_fehler, df_consts, df_tags = dataframes
with pd.ExcelWriter(export_path, engine='openpyxl') as writer:
with pd.ExcelWriter(export_path, engine='openpyxl', mode='w') as writer:
# 1. PLC Tags Sheet mit Header. Spalten: Name, Path, Data Type, Logical Address, Comment, Hmi Visible, Hmi Accessible, Hmi Writeable, Typeobject ID, Version ID
df_tags.to_excel(writer, sheet_name='PLC Tags', index=False)
+21 -8
View File
@@ -5,11 +5,7 @@ from ioconverter import ExcelConverter
import json
from pathlib import Path
def prepare_data(rawdata:dict):
sensors = rawdata["sensors"]
dsensors = dict()
lsensors = list()
for sname, sdata in sensors.items():
def process_item(sname, sdata):
data = {
"id": sdata.get("IO", ""),
"bezeichnung": sdata.get("BEZEICHNUNG", ""),
@@ -26,10 +22,27 @@ def prepare_data(rawdata:dict):
csvstr = "','".join(str(data[key]) for key in reihenfolge)
csvstr = "'"+csvstr+"'"
sps_nr = None
if "SPS" in sdata:
sps_nr = sdata.get("SPS", None)
sps_nr = sdata.get("SPS", None)
return csvstr, sps_nr
def prepare_data(rawdata:dict):
sensors = rawdata["sensors"]
schaltschrank_elemente = rawdata["schaltschrank_elemente"]
dsensors = dict()
lsensors = list()
for sname, sdata in sensors.items():
csvstr, sps_nr = process_item(sname, sdata)
if sps_nr:
if sps_nr not in dsensors:
dsensors[sps_nr] = list()
dsensors[sps_nr].append(csvstr)
else:
lsensors.append(csvstr)
for schaltele, sdata in schaltschrank_elemente.items():
csvstr, sps_nr = process_item(schaltele, sdata)
if sps_nr:
if sps_nr not in dsensors:
dsensors[sps_nr] = list()
+12 -7
View File
@@ -10,6 +10,7 @@ from shapely.geometry import LineString, Point
from shapely.ops import nearest_points
from plant import Anlage
import configparser
from pathlib import Path
# Funktionen
@@ -21,7 +22,7 @@ def write_results(jsnResults, outdir, filename):
""" write results to a json file
"""
print("writing results to a json file ...")
outfile = os.path.join(outdir, filename)
outfile = Path(outdir) / filename
with open(outfile, 'w', encoding='utf-8') as fh:
fh.write(jsnResults)
print("done")
@@ -171,20 +172,24 @@ if __name__ == "__main__":
args = parser.parse_args()
# Umgebungsvariablen
work_dir = os.environ.get("PROJECT_WORK")
config_dir = os.environ.get("PROJECT_CFG")
work_dir_env = os.environ.get("PROJECT_WORK")
config_dir_env = os.environ.get("PROJECT_CFG")
if work_dir_env is None or config_dir_env is None:
raise RuntimeError("PROJECT_WORK or PROJECT_CFG environment variable not set.")
work_dir = Path(work_dir_env)
config_dir = Path(config_dir_env)
# Pfade zu JSON-Dateien
jsonfilename = args.filename
sensors_path = os.path.join(work_dir, jsonfilename)
sensors_path = work_dir / jsonfilename
# Einlesen und Vorbereiten der Daten
rawdata = load_json(sensors_path)
(racks, sensors, subdists, mapping, tunnels, tunlength, errors_dists, errors_sensors, errors_attributes) = prepare_data(rawdata)
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "allgemein.cfg"))
config.optionxform = lambda optionstr: optionstr # preserve case for letters
config.read(str(config_dir / "allgemein.cfg"))
# virtuelle Anlage erstellen
@@ -200,7 +205,7 @@ if __name__ == "__main__":
# Ausgabe schreiben
if args.write:
basename = os.path.splitext(args.write)[0]
basename = Path(args.write).stem
cable_paths["errors_dists_not_in_layout"] = errors_dists
cable_paths["errors_sensors_not_in_layout"] = errors_sensors
cable_paths["errors_missing_attributes"] = errors_attributes