import datetime import pandas as pd import numpy as np import datetime from USER.SPF.alibaba.Common import DBDownload from USER.SPF.alibaba.Common import log import CBMSBatSoh if __name__ == "__main__": SNnums= ['LS002'] end_time=datetime.datetime.now()-datetime.timedelta(seconds=10) start_time=end_time-datetime.timedelta(seconds=12000) start_time=start_time.strftime('%Y-%m-%d %H:%M:%S') end_time=end_time.strftime('%Y-%m-%d %H:%M:%S') #log信息配置............................................................................................................................................................................ mylog=log.Mylog('log_soh.txt','error') mylog.logcfg() for sn in SNnums: 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: # print('未找到对应电池编号!!!\n',sn) # # sys.exit() celltype=99 #............................................................读取原始数据库数据........................................................................... df_bms= pd.read_excel(r'D:\01WorkSpace\项目\Alibaba\data\原始数据_2022-01-10_2022-02-10\力神_LS002.xlsx') cellvolt_name=['CellVolt'+str(x) for x in range(1,73)] celltemp_name=['CellTemp'+str(x) for x in range(1,33)] df_volt=pd.DataFrame([x[0].split(",") for x in np.array(df_bms[['cell_volt']])]) df_volt.columns = cellvolt_name df_volt=df_volt.astype('float') df_temp=pd.DataFrame([x[0].split(",") for x in np.array(df_bms[['cell_temp']])]) df_temp.columns = celltemp_name df_temp=df_temp.astype('float') df_bms=pd.concat([df_bms,df_volt,df_temp],axis=1) df_bms.dropna(axis=0, inplace=True) df_bms=df_bms.reset_index(drop=True) #............................................................读取结果数据库数据......................................................................... # 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,packsoh', tablename=tablename, sn=sn, timename='time_sp', st=start_time, sp=end_time) df_soh=pd.DataFrame() # print(df_soh) #.................................................................计算soh................................................................................... BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_soh) df_res=BatSoh.batsoh() df_res.to_excel(r'D:\01WorkSpace\python\data_analyze_platform\USER\SPF\alibaba\99Result\\'+'CBMS_SOH_'+sn+'.xlsx') # print('done!!!') except Exception as e: print(repr(e)) mylog.logopt(sn,e) pass