unittest für die SortierId geschrieben

This commit is contained in:
2023-10-26 15:51:57 +02:00
parent 2027650c25
commit c26fdc2781
5 changed files with 108 additions and 9 deletions
+2 -1
View File
@@ -5,6 +5,7 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Python: Aktuelle Datei", "name": "Python: Aktuelle Datei",
"type": "python", "type": "python",
@@ -21,7 +22,7 @@
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": true "justMyCode": true
"args": [ "args": [
"--sivas=826002201" "--sivas=829522001"
], ],
} }
] ]
+6 -1
View File
@@ -4,5 +4,10 @@
"path": "." "path": "."
} }
], ],
"settings": {} "settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
} }
-1
View File
@@ -1,5 +1,4 @@
@echo off @echo off
call cremig_setenv.bat call cremig_setenv.bat
start start
+68 -6
View File
@@ -1,8 +1,19 @@
import argparse import argparse
import os import os
import pandas import pandas as pd
# import configparser import json
# 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 Dieses Programm holt sich aus
@@ -10,7 +21,10 @@ Dieses Programm holt sich aus
- Sivas eine Liste der gewünschten Teile - 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 """ """ exportiert die Nummern der Sivas ID in eine Excel Datei um vorhandene von fehlenden zu unterscheiden """
# Sortierung Teilenummer Bezeichnung Bestandsabfrage Teile Beurteilung Zusatzbemerkung # Sortierung Teilenummer Bezeichnung Bestandsabfrage Teile Beurteilung Zusatzbemerkung
# Sortierung: Minus - Separierten "Pfad" dieses Einzelteils im Assembly # Sortierung: Minus - Separierten "Pfad" dieses Einzelteils im Assembly
@@ -18,15 +32,63 @@ def create_excel_export():
# Bezeichnung: SIVAS Bezeichnung # Bezeichnung: SIVAS Bezeichnung
# Bestandsabfrage: Importieren oder Verfügbar # Bestandsabfrage: Importieren oder Verfügbar
# die restlichen Spalten bleiben leer # 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): def compareFiles(rdDataBasePath, jsonPath, sivasId, outPath):
# Lies die RD Datenbank ein # 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 # 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 # 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 # Schreibe eine Exceldatei mit den korrekten Spalten raus
pass create_excel_export(existingIds, sivasData, sivasId, outPath)
if __name__ == '__main__': if __name__ == '__main__':
+32
View File
@@ -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()