zuordnung zwischen SIVAS .csv und INternem Datenmodell eingebaut. sivas_data_from_csv impl.
This commit is contained in:
+58
-4
@@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
from controller import Controller
|
from controller import Controller
|
||||||
|
import pandas as pd
|
||||||
|
import os
|
||||||
|
|
||||||
class CadItem():
|
class CadItem():
|
||||||
"""
|
"""
|
||||||
@@ -92,6 +94,38 @@ class CadItem():
|
|||||||
"cb_oberflaeche_neu",
|
"cb_oberflaeche_neu",
|
||||||
"cb_farbe_neu",
|
"cb_farbe_neu",
|
||||||
]
|
]
|
||||||
|
# dies sind die Excel Headel der SIVAS csv Export Datei
|
||||||
|
# und wie diese in das Datenmodell der Gui integriert werden kann
|
||||||
|
excel_to_gui = {
|
||||||
|
"Teilenummer":"teilenummer",
|
||||||
|
"Bezeichnung1":"bezeichnung1_sivas",
|
||||||
|
"Bezeichnung2":"bezeichnung2_sivas",
|
||||||
|
"Beschaffungsart":"beschaffungsart_sivas",
|
||||||
|
"Mengeneinheit":"mengeneinheit_sivas",
|
||||||
|
"Halbzeug":"halbzeug_sivas",
|
||||||
|
"TOS_Gruppe":"tosgruppe_sivas",
|
||||||
|
"Dispogruppe":"dispolaufgruppe_sivas",
|
||||||
|
"Dispolaufgruppe":"dispolaufgruppe_sivas",
|
||||||
|
"ErsatzFuer":"ersatzfuer_neu",
|
||||||
|
"ErsetztDurch":"ersetztdurch_neu",
|
||||||
|
"AktuellerIndex":"aenderungsindex_sivas",
|
||||||
|
"Hersteller":"hersteller_sivas",
|
||||||
|
"HerstellerTeilenummer":"herstteilenr_sivas",
|
||||||
|
"Version":"version_sivas",
|
||||||
|
"HalbzeugExtern":"halbzeug_sivas",
|
||||||
|
"Werkstoff":"werkstofftyp_sivas",
|
||||||
|
"Oberfläche":"oberflaeche_neu_combo",
|
||||||
|
# "Truemmer":"truemmer",
|
||||||
|
# "HzOhneSaegeliste":"",
|
||||||
|
"Ruestcode":"ruestcode_sivas",
|
||||||
|
"Fertigungsart":"fertigungsart_sivas",
|
||||||
|
"FosGruppe":"fosGruppe_sivas",
|
||||||
|
"Kalkulationsart":"kalkulationsart_sivas",
|
||||||
|
"Indexerfasser":"",
|
||||||
|
"Aenderungstext":"aenderungstext_sivas",
|
||||||
|
"Freigabevermerk":"freigabevermerk_sivas",
|
||||||
|
# "Indexbearbeiter":"in"
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" is initalized with its unique id"""
|
""" is initalized with its unique id"""
|
||||||
@@ -101,9 +135,12 @@ class CadItem():
|
|||||||
self.gui_data = {}
|
self.gui_data = {}
|
||||||
self.read_only_items = {}
|
self.read_only_items = {}
|
||||||
self.controller = None
|
self.controller = None
|
||||||
|
self.env = None
|
||||||
|
|
||||||
def set_controller(self, controller):
|
def set_controller(self, controller):
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
def set_env(self, env):
|
||||||
|
self.environment = env
|
||||||
|
|
||||||
def set_asm_id(self, asm_id):
|
def set_asm_id(self, asm_id):
|
||||||
self.set_gui_data("asm_id", asm_id)
|
self.set_gui_data("asm_id", asm_id)
|
||||||
@@ -177,6 +214,21 @@ class CadItem():
|
|||||||
def get_all_gui_data(self):
|
def get_all_gui_data(self):
|
||||||
return self.gui_data
|
return self.gui_data
|
||||||
|
|
||||||
|
def sivas_data_from_csv(self, cid):
|
||||||
|
path = os.path.join(self.environment.out_dir, cid + '.csv')
|
||||||
|
if os.path.exists(path):
|
||||||
|
data = self.load_csv(path)
|
||||||
|
self.set_gui_dict(data)
|
||||||
|
def load_csv(self, path):
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return None
|
||||||
|
df = pd.read_csv(path)
|
||||||
|
ret = dict()
|
||||||
|
columns = df.columns.values
|
||||||
|
for colname in columns:
|
||||||
|
ret[self.excel_to_gui[colname]] = df[0][colname]
|
||||||
|
return ret
|
||||||
|
|
||||||
def from_json(self, json_str):
|
def from_json(self, json_str):
|
||||||
jsonobj = json.loads(json_str)
|
jsonobj = json.loads(json_str)
|
||||||
|
|
||||||
@@ -225,13 +277,15 @@ class CadItem():
|
|||||||
return json.dumps(obj)
|
return json.dumps(obj)
|
||||||
|
|
||||||
def load(self, path):
|
def load(self, path):
|
||||||
try:
|
"""loads all data of a model from a json string"""
|
||||||
with open(path, 'r') as f:
|
try:
|
||||||
self.from_json(json.load(f))
|
with open(path, 'r') as f:
|
||||||
except Exception:
|
self.from_json(json.load(f))
|
||||||
|
except Exception:
|
||||||
raise Exception("guid_data, data, parent_children_mapping or red_ids not found")
|
raise Exception("guid_data, data, parent_children_mapping or red_ids not found")
|
||||||
|
|
||||||
def save(self, path):
|
def save(self, path):
|
||||||
|
"""saves all data of model to a json string"""
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
json.dump(self.to_dict(), f)
|
json.dump(self.to_dict(), f)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user