123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import CBMSBatBehave
- import pymysql
- import datetime
- import pandas as pd
- import multiprocessing
- from LIB.BACKEND import DBManager, Log
- import time, datetime
- from apscheduler.schedulers.blocking import BlockingScheduler
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
- #...............................................主函数..........................................................................................................
- 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_L7255 + SNnums_C7255 + SNnums_U7255 + SNnums_4840, SNnums_6040 + SNnums_6060]
- SNnums=SNnums_ZKHD
-
- mylog=log.Mylog('log_diag.txt','error')
- mylog.logcfg()
-
- start=time.time()
- now_time=datetime.datetime.now() #-datetime.timedelta(seconds=3600*24+3600*14.6)
- start_time=now_time-datetime.timedelta(seconds=70)
- start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
- end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
- start_time='2021-12-1 00:00:00'
- end_time='2021-12-30 23:59:59'
- for sn in SNnums:
- try:
- if 'PK500' in sn:
- celltype=1 #6040三元电芯
- elif 'PK502' in sn:
- celltype=2 #4840三元电芯
- elif 'K504B' in sn:
- celltype=99 #60ah林磷酸铁锂电芯
- elif 'MGMLXN750' in sn:
- celltype=3 #力信50ah三元电芯
- elif ('MGMCLN750' or 'UD') in sn:
- celltype=4 #CATL 50ah三元电芯
- elif 'TJMCL' in sn:
- celltype=100 #金茂重卡换电
- else:
- print('SN:{},未找到对应电池类型!!!'.format(sn))
- continue
- # sys.exit()
- #读取原始数据库数据........................................................................................................................................................
- 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(axis=0,subset=['总电流[A]','SOH[%]','SOC[%]']) #去除有空值的行
- 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+'_BMS_'+'.csv',encoding='GB18030')
- # print(df_bms)
- #用户行为分析................................................................................................................................................................
- if not df_bms.empty:
- BatBehave=CBMSBatBehave.BatBehave(sn,celltype,df_bms)
- df_res=BatBehave.behave()
- #当前热失控故障写入数据库
- if not df_res.empty:
- #读取老的excel结果
- try:
- df_res_old= pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析1'+'.xlsx',index_col=0)
- except:
- df_res_old=pd.DataFrame()
- #新的结果与老结果合并
- if df_res_old.empty:
- df_res=df_res
- else:
- df_res=df_res.append(df_res_old)
- #合并后的结果存入excel文件
- if not df_res.empty:
- df_res.to_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\99Result\\'+'CBMS_'+'行为分析1'+'.xlsx')
- # print('done!!!')
-
- end=time.time()
- print(end-start)
- except Exception as e:
- print(repr(e))
- mylog.logopt(e)
|