consolidator
/
generalDebug.py
61 строка · 3.2 Кб
1import glob2import pandas as pd3from ModuleMaker import ModuleMaker4from OraWorker import OraWorker5
6
7
8def converter(row:pd.Series)->pd.Series:9# row["Доп параметр2"]=float(str(row["Доп параметр2"]).replace(",","."))10row["Код"] = row["Вид материала в SAP ERP"][:4]11return row12
13def ntd_convert(row:pd.Series,ntd_cols:list,ora:OraWorker)->pd.Series:14ntd = "".join([str(row[key]) for key in ntd_cols])15# product_up = ora.product_check("*",row["ID в SAP ERP VMZ"])16row["НТД качества"]=ntd.replace("nan","")17# row["Продукт УП"] = product_up[0]18return row19
20def get_nearest(guidName:str,query:str,nearestColumn:str,nearestValue:float,valueColumn:str):21df = pd.read_csv(guidName,encoding="windows-1251",delimiter=";")22df=df.apply(converter,axis=1)23df = df.query(query)24df_res = df.iloc[(df[nearestColumn]-nearestValue).abs().argsort()[:1]]25return df_res[valueColumn].values[0]26
27if __name__=="__main__":28
29r = ModuleMaker.make_from_file("handlers2\\module_pattern.py","key","ww_test_module")30print(r)31
32# "ID в SAP ERP VMZ","Полное наименование материала","Вид материала в SAP ERP","Производство"33# cols1 = ["ID в SAP ERP VMZ","Полное наименование материала","Вид материала в SAP ERP","Производство"]34# path_pattern="D:\\work\\Укрупнение\\current\\data\\2*\\*.xlsx"35# exclude_pattern = "нение_"36# files=[f for f in glob.glob(path_pattern) if exclude_pattern not in f] if exclude_pattern is not None else [f for f in glob.glob(path_pattern)]37# frames = []38# ora = OraWorker("sapnwc","sapnwc","172.17.80.116/scpora",".\\ora")39# for f in files:40# try:41# xl = pd.ExcelFile(f)42# for sheet in xl.sheet_names:43# df = pd.read_excel(f,sheet_name=sheet)44# df["file"]=f45# df["sheet"]=sheet46# ntd_cols_q = [col for col in df.columns if "НТД" in col and "ачества" in col and "*" not in col]47# ntd_cols_cover = [col for col in df.columns if "НТД" in col and "окрытия" in col and "3" not in col]48# steel_cols = [col for col in df.columns if "стал" in col or "проч" in col]49# if not df.empty:50# df = df.apply(lambda r: ntd_convert(r,ntd_cols_q,ora),axis=1)51# frames.append(df[cols1+["НТД качества"]+steel_cols+ntd_cols_cover+["file","sheet"]])52# print(f"{f}[{sheet}] added")53# except Exception as exp1:54# print(f"{f} failed: {exp1}")55# result=pd.concat(frames)56# result = result.drop_duplicates()57# result = result.apply(converter,axis=1)58# ntd_cols_cover = [col for col in result.columns if "НТД" in col and "покрытия" in col and "3" not in col]59# steel_cols = [col for col in df.columns if "стал" in col or "проч" in col]60# ora.close()61# result[cols1+["Код","НТД качества"]+steel_cols+ntd_cols_cover+["file","sheet"]].to_excel("output\\VM_Productions3.xlsx",index=False)62
63
64