118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
import argparse
|
|
import os
|
|
import pandas as pd
|
|
import json
|
|
|
|
def create_sorter_string(sivasData, sivasId):
|
|
p = sivasData[sivasId]['Parent']
|
|
s = sivasId
|
|
if p not in sivasData:
|
|
return None
|
|
recurval = create_sorter_string(sivasData, p)
|
|
if recurval is not None:
|
|
s = recurval + '-'+ s
|
|
return s
|
|
|
|
|
|
|
|
"""
|
|
Dieses Programm holt sich aus
|
|
- RD Fusion eine aktuellen Stand der exisitierenden IDS
|
|
- Sivas eine Liste der gewünschten Teile
|
|
|
|
"""
|
|
def create_excel_export(existingIds, sivasData, sivasId, outPath):
|
|
|
|
excelIdsExistingPath = os.path.join(outPath, sivasId + ".xlsx")
|
|
|
|
""" exportiert die Nummern der Sivas ID in eine Excel Datei um vorhandene von fehlenden zu unterscheiden """
|
|
# Sortierung Teilenummer Bezeichnung Bestandsabfrage Teile Beurteilung Zusatzbemerkung
|
|
# Sortierung: Minus - Separierten "Pfad" dieses Einzelteils im Assembly
|
|
# Teilenummer: Sivas Teilenummer
|
|
# Bezeichnung: SIVAS Bezeichnung
|
|
# Bestandsabfrage: Importieren oder Verfügbar
|
|
# die restlichen Spalten bleiben leer
|
|
|
|
sortierung = list()
|
|
teilenummer = list()
|
|
bezeichnung = list()
|
|
bestand = list()
|
|
teilebeurteilung = list()
|
|
zusatzbemerkung = list()
|
|
|
|
for item in sivasData:
|
|
sortierung.append(sivasData[item]['Parent'])
|
|
teilenummer.append(item)
|
|
bezeichnung.append(sivasData[item]['Bezeichnung'])
|
|
if existingIds[item] is True:
|
|
existing = "VERFÜGBAR"
|
|
else:
|
|
existing = "IMPORTIEREN"
|
|
bestand.append(existing)
|
|
teilebeurteilung.append('')
|
|
zusatzbemerkung.append('')
|
|
|
|
|
|
data = {
|
|
"Sortierung":sortierung,
|
|
"Teilenummer":teilenummer,
|
|
"Bezeichnung":bezeichnung,
|
|
"Bestandsabfrage":bestand,
|
|
"Teile Beurteilung":teilebeurteilung,
|
|
"Zusatzbemerkung":zusatzbemerkung
|
|
}
|
|
df = pd.DataFrame.from_dict(data)
|
|
df.to_excel(excelIdsExistingPath, sheet_name="Ergebnis", index_label="Sortierung")
|
|
|
|
|
|
def compareFiles(rdDataBasePath, jsonPath, sivasId, outPath):
|
|
# Lies die RD Datenbank ein
|
|
df = pd.read_csv(rdDataBasePath, sep=';')
|
|
|
|
teileNummern = list()
|
|
for nummer in df["Teilenummer"].to_list():
|
|
teileNummern.append(str(nummer))
|
|
tn = tuple(teileNummern)
|
|
|
|
# hole dir alle Ids aus der Json Datei
|
|
with open(jsonPath, encoding='utf-8') as fp:
|
|
sivasData = json.load(fp)
|
|
|
|
# Prüfe das Vorhandensein der JsonIds in der RD Datenbank
|
|
existingIds = dict()
|
|
for item in sivasData:
|
|
if item in tn:
|
|
existingIds[item] = True
|
|
else:
|
|
existingIds[item] = False
|
|
|
|
# Schreibe eine Exceldatei mit den korrekten Spalten raus
|
|
create_excel_export(existingIds, sivasData, sivasId, outPath)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database')
|
|
parser.add_argument('-s', '--sivas', action='store', help='fetch data of this id from sivas fo local database folder')
|
|
parser.add_argument('-d', '--database', action='store', default="RD_Bestandspool.csv", help='local filename of the latest fetched RuleDesigner Database')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
if args.sivas:
|
|
# fetching the names of all existing cad files from the local file
|
|
dataDir = os.environ.get('CREMIG_DATA')
|
|
rdDataBasePath = os.path.join(dataDir, args.database)
|
|
# get the path to ask for further json files
|
|
exePath = os.environ.get('SIVAS_DATABASE_QUERY')
|
|
# in case the infos for this cad file are already there
|
|
sivasId = str(args.sivas)
|
|
jsonPath = os.path.join(dataDir, sivasId + ".json")
|
|
# there the results are written
|
|
outPath = os.environ.get('CREMIG_WORK')
|
|
|
|
compareFiles(rdDataBasePath, jsonPath, sivasId, outPath)
|
|
|
|
|
|
|