Mit curser weiter bearbeitet. Schaltschrankelemente werden jettz auch von getpositions raus geschrieben
This commit is contained in:
+5
-4
@@ -182,7 +182,7 @@ class CompareBuffer:
|
|||||||
l.append(b)
|
l.append(b)
|
||||||
return l
|
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_sensors = dict()
|
||||||
all_cables = dict()
|
all_cables = dict()
|
||||||
all_schaltschrank = dict()
|
all_schaltschrank = dict()
|
||||||
@@ -216,7 +216,7 @@ def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict]:
|
|||||||
# die noch übrigen Blöcke melden
|
# die noch übrigen Blöcke melden
|
||||||
missing_attribs, double_ids = get_errors_double_and_attributes(wp)
|
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]:
|
def get_errors_double_and_attributes(wp: CompareBuffer) -> tuple[dict, dict]:
|
||||||
missing_attribs = dict()
|
missing_attribs = dict()
|
||||||
@@ -664,9 +664,9 @@ if __name__ == '__main__':
|
|||||||
if args.sensors:
|
if args.sensors:
|
||||||
# Sensoren auslesen
|
# Sensoren auslesen
|
||||||
if use_iter:
|
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:
|
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:
|
if args.errors and len(res_double) > 0:
|
||||||
print("Duplicate blocks found. Writing errors-file.")
|
print("Duplicate blocks found. Writing errors-file.")
|
||||||
@@ -675,6 +675,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
output_results['sensors'] = res_sens
|
output_results['sensors'] = res_sens
|
||||||
|
output_results['schaltschrank_elemente'] = res_schaltschrank_elemente
|
||||||
#output_results['cables'] = res_cables
|
#output_results['cables'] = res_cables
|
||||||
|
|
||||||
if args.console:
|
if args.console:
|
||||||
|
|||||||
+1
-1
@@ -416,7 +416,7 @@ class ExcelConverter:
|
|||||||
elif export_type == "TIA":
|
elif export_type == "TIA":
|
||||||
df_gleiche_eingaenge, df_gleiche_ausgaenge, df_fehler, df_consts, df_tags = dataframes
|
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
|
# 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)
|
df_tags.to_excel(writer, sheet_name='PLC Tags', index=False)
|
||||||
|
|
||||||
|
|||||||
+21
-8
@@ -5,11 +5,7 @@ from ioconverter import ExcelConverter
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
def prepare_data(rawdata:dict):
|
def process_item(sname, sdata):
|
||||||
sensors = rawdata["sensors"]
|
|
||||||
dsensors = dict()
|
|
||||||
lsensors = list()
|
|
||||||
for sname, sdata in sensors.items():
|
|
||||||
data = {
|
data = {
|
||||||
"id": sdata.get("IO", ""),
|
"id": sdata.get("IO", ""),
|
||||||
"bezeichnung": sdata.get("BEZEICHNUNG", ""),
|
"bezeichnung": sdata.get("BEZEICHNUNG", ""),
|
||||||
@@ -26,10 +22,27 @@ def prepare_data(rawdata:dict):
|
|||||||
csvstr = "','".join(str(data[key]) for key in reihenfolge)
|
csvstr = "','".join(str(data[key]) for key in reihenfolge)
|
||||||
csvstr = "'"+csvstr+"'"
|
csvstr = "'"+csvstr+"'"
|
||||||
|
|
||||||
sps_nr = None
|
sps_nr = sdata.get("SPS", None)
|
||||||
if "SPS" in sdata:
|
return csvstr, sps_nr
|
||||||
sps_nr = sdata.get("SPS", None)
|
|
||||||
|
|
||||||
|
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:
|
||||||
if sps_nr not in dsensors:
|
if sps_nr not in dsensors:
|
||||||
dsensors[sps_nr] = list()
|
dsensors[sps_nr] = list()
|
||||||
|
|||||||
+12
-7
@@ -10,6 +10,7 @@ from shapely.geometry import LineString, Point
|
|||||||
from shapely.ops import nearest_points
|
from shapely.ops import nearest_points
|
||||||
from plant import Anlage
|
from plant import Anlage
|
||||||
import configparser
|
import configparser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
# Funktionen
|
# Funktionen
|
||||||
@@ -21,7 +22,7 @@ def write_results(jsnResults, outdir, filename):
|
|||||||
""" write results to a json file
|
""" write results to a json file
|
||||||
"""
|
"""
|
||||||
print("writing 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:
|
with open(outfile, 'w', encoding='utf-8') as fh:
|
||||||
fh.write(jsnResults)
|
fh.write(jsnResults)
|
||||||
print("done")
|
print("done")
|
||||||
@@ -171,20 +172,24 @@ if __name__ == "__main__":
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Umgebungsvariablen
|
# Umgebungsvariablen
|
||||||
work_dir = os.environ.get("PROJECT_WORK")
|
work_dir_env = os.environ.get("PROJECT_WORK")
|
||||||
config_dir = os.environ.get("PROJECT_CFG")
|
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
|
# Pfade zu JSON-Dateien
|
||||||
jsonfilename = args.filename
|
jsonfilename = args.filename
|
||||||
sensors_path = os.path.join(work_dir, jsonfilename)
|
sensors_path = work_dir / jsonfilename
|
||||||
|
|
||||||
# Einlesen und Vorbereiten der Daten
|
# Einlesen und Vorbereiten der Daten
|
||||||
rawdata = load_json(sensors_path)
|
rawdata = load_json(sensors_path)
|
||||||
(racks, sensors, subdists, mapping, tunnels, tunlength, errors_dists, errors_sensors, errors_attributes) = prepare_data(rawdata)
|
(racks, sensors, subdists, mapping, tunnels, tunlength, errors_dists, errors_sensors, errors_attributes) = prepare_data(rawdata)
|
||||||
|
|
||||||
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
|
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
|
||||||
config.optionxform = lambda option: option # preserve case for letters
|
config.optionxform = lambda optionstr: optionstr # preserve case for letters
|
||||||
config.read(os.path.join(config_dir, "allgemein.cfg"))
|
config.read(str(config_dir / "allgemein.cfg"))
|
||||||
|
|
||||||
|
|
||||||
# virtuelle Anlage erstellen
|
# virtuelle Anlage erstellen
|
||||||
@@ -200,7 +205,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Ausgabe schreiben
|
# Ausgabe schreiben
|
||||||
if args.write:
|
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_dists_not_in_layout"] = errors_dists
|
||||||
cable_paths["errors_sensors_not_in_layout"] = errors_sensors
|
cable_paths["errors_sensors_not_in_layout"] = errors_sensors
|
||||||
cable_paths["errors_missing_attributes"] = errors_attributes
|
cable_paths["errors_missing_attributes"] = errors_attributes
|
||||||
|
|||||||
Reference in New Issue
Block a user