123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import CBMSBatSoh
- #coding=utf-8
- import datetime
- import pandas as pd
- from LIB.BACKEND import DBManager, Log
- import time, datetime
- import os
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
- dbManager = DBManager.DBManager()
- if __name__ == "__main__":
- # excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
- # SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
- # SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
- # SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
- # SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
- # SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
- # SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
- # SNdata_ZKHD=pd.read_excel(excelpath, sheet_name='重卡换电')
- # SNnums_6060=SNdata_6060['SN号'].tolist()
- # SNnums_6040=SNdata_6040['SN号'].tolist()
- # SNnums_4840=SNdata_4840['SN号'].tolist()
- # SNnums_L7255=SNdata_L7255['SN号'].tolist()
- # SNnums_C7255=SNdata_C7255['SN号'].tolist()
- # SNnums_U7255=SNdata_U7255['SN号'].tolist()
- # SNnums_ZKHD=SNdata_ZKHD['SN号'].tolist()
- # SNnums= SNnums_ZKHD
- SNdata_6040 = pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\CBMS_SOH_26040.xlsx')
- SNnums=SNdata_6040['sn'].tolist()
- SNnums=['PK50001A100000545']
- # filepath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download'
- # files=os.listdir(filepath)
- # files=[files[5]]
- end_time=datetime.datetime.now()-datetime.timedelta(seconds=10)
- start_time=end_time-datetime.timedelta(seconds=1200)
- start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
- end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
- start_time='2020-10-31 00:49:37'
- end_time='2021-12-31 19:49:37'
- #log信息配置............................................................................................................................................................................
- mylog=log.Mylog('log_soh.txt','error')
- mylog.logcfg()
- for sn in SNnums:
- # sn=filesname[:-4]
- print(sn)
- try:
- if 'PK500' in sn:
- celltype=1 #6040三元电芯
- elif 'PK502' in sn:
- celltype=2 #4840三元电芯
- elif 'PK504' in sn:
- celltype=99 #60ah林磷酸铁锂电芯
- elif 'MGMLXN750' in sn:
- celltype=3 #力信50ah三元电芯
- elif 'MGMCLN750' in sn:
- celltype=4 #CATL 50ah三元电芯
- else:
- celltype=100
- print('未找到对应电池编号!!!\n',sn)
- # sys.exit()
- # df_bms= pd.read_csv(filepath+'\\'+filesname,encoding='GB18030')
- # df_accum= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
-
- #..........................................................................读取原始数据库数据...........................................................................
- dbManager = DBManager.DBManager()
- df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
- df_bms = df_data['bms']
- df_bms=df_bms.dropna(subset=['总电流[A]'])
- df_bms.reset_index(inplace=True,drop=True) #重置索引
- df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\98Download\\'+sn+'.csv',encoding='GB18030')
- df_accum=pd.DataFrame()
- #..........................................................................读取结果数据库数据.........................................................................
- host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
- port=3306
- db='qx_cas'
- user='qx_read'
- password='Qx@123456'
- mode=1
- tablename='cellstateestimation_soh'
- DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
- with DBRead as DBRead:
- df_soh=DBRead.getdata(param='time_st,time_sp,sn,method,soh,cellsoh', tablename=tablename, sn=sn, timename='time_sp', st=start_time, sp=end_time)
- # print(df_soh)
- # df_soh=pd.DataFrame()
- #..............................................................................计算soh...................................................................................
- BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,df_soh)
- df_res=BatSoh.batsoh()
- df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_SOH'+sn+'.csv',encoding='GB18030')
- # print('done!!!')
-
- except Exception as e:
- print(repr(e))
- mylog.logopt(sn,e)
- pass
|