From c26fdc278100887dc7376a71e631182f13cee801 Mon Sep 17 00:00:00 2001 From: mistangl Date: Thu, 26 Oct 2023 15:51:57 +0200 Subject: [PATCH] =?UTF-8?q?unittest=20f=C3=BCr=20die=20SortierId=20geschri?= =?UTF-8?q?eben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 3 +- CreoMigrate.code-workspace | 7 +++- bin/get_cmd.bat | 1 - lib/compare_lists.py | 74 ++++++++++++++++++++++++++++++++++---- lib/test_compare.py | 32 +++++++++++++++++ 5 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 lib/test_compare.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 71b7418..aa416fd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Python: Aktuelle Datei", @@ -21,7 +22,7 @@ "console": "integratedTerminal", "justMyCode": true "args": [ - "--sivas=826002201" + "--sivas=829522001" ], } ] diff --git a/CreoMigrate.code-workspace b/CreoMigrate.code-workspace index 876a149..53db69b 100644 --- a/CreoMigrate.code-workspace +++ b/CreoMigrate.code-workspace @@ -4,5 +4,10 @@ "path": "." } ], - "settings": {} + "settings": { + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" + } } \ No newline at end of file diff --git a/bin/get_cmd.bat b/bin/get_cmd.bat index 2cdb6a5..b8dcc8a 100644 --- a/bin/get_cmd.bat +++ b/bin/get_cmd.bat @@ -1,5 +1,4 @@ @echo off call cremig_setenv.bat - start diff --git a/lib/compare_lists.py b/lib/compare_lists.py index 516cfb8..1366b25 100644 --- a/lib/compare_lists.py +++ b/lib/compare_lists.py @@ -1,8 +1,19 @@ import argparse import os -import pandas -# import configparser -# import json +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 @@ -10,7 +21,10 @@ Dieses Programm holt sich aus - Sivas eine Liste der gewünschten Teile """ -def create_excel_export(): +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 @@ -18,15 +32,63 @@ def create_excel_export(): # Bezeichnung: SIVAS Bezeichnung # Bestandsabfrage: Importieren oder Verfügbar # die restlichen Spalten bleiben leer - pass + + 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 - pass + create_excel_export(existingIds, sivasData, sivasId, outPath) + if __name__ == '__main__': diff --git a/lib/test_compare.py b/lib/test_compare.py new file mode 100644 index 0000000..7438c1a --- /dev/null +++ b/lib/test_compare.py @@ -0,0 +1,32 @@ +from compare_lists import create_sorter_string +import json +import unittest + +class RecursiveStringTest(unittest.TestCase): + + def testCalculation(self): + jsonString = '''{ + "829524001": { + "Position": "10/0", + "Parent": "829522001" + }, + "829526001": { + "Position": ".10/0", + "Parent": "829524001" + }, + "829526000": { + "Position": "..10/0", + "Parent": "829526002" + }, + "829526002": { + "Position": ".20/0", + "Parent": "829524001" + } + } + ''' + sivasData = json.loads(jsonString) + self.assertEqual(create_sorter_string(sivasData, '829526000'), '829522001-829524001-829526002-829526000') + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file