|
@@ -12,15 +12,11 @@ import traceback
|
|
from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSSafetyWarning
|
|
from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSSafetyWarning
|
|
from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSBatInterShort
|
|
from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSBatInterShort
|
|
-
|
|
|
|
-from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
|
|
|
|
from urllib import parse
|
|
from urllib import parse
|
|
import pymysql
|
|
import pymysql
|
|
-import pdb
|
|
|
|
|
|
+
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
-import datacompy
|
|
|
|
-import logging
|
|
|
|
-import multiprocessing
|
|
|
|
|
|
+
|
|
#...................................电池包电芯安全诊断函数......................................................................................................................
|
|
#...................................电池包电芯安全诊断函数......................................................................................................................
|
|
def saftywarning_cal():
|
|
def saftywarning_cal():
|
|
global df_sn
|
|
global df_sn
|
|
@@ -114,13 +110,12 @@ def saftywarning_cal():
|
|
df_lfp_ram_sn.reset_index(inplace=True,drop=True) #重置索引
|
|
df_lfp_ram_sn.reset_index(inplace=True,drop=True) #重置索引
|
|
else:
|
|
else:
|
|
df_lfp_ram_sn=pd.DataFrame()
|
|
df_lfp_ram_sn=pd.DataFrame()
|
|
-
|
|
|
|
BatShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh,df_warning_ram_sn,df_warning_ram_sn1,df_warning_ram_sn2,df_warning_ram_sn3,df_lfp_ram_sn)
|
|
BatShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh,df_warning_ram_sn,df_warning_ram_sn1,df_warning_ram_sn2,df_warning_ram_sn3,df_lfp_ram_sn)
|
|
df_short_res, df_ram_res, df_ram_res1, df_ram_res2, df_ram_res3, df_ram_res4=BatShort.intershort()
|
|
df_short_res, df_ram_res, df_ram_res1, df_ram_res2, df_ram_res3, df_ram_res4=BatShort.intershort()
|
|
|
|
|
|
if not df_short_res.empty:
|
|
if not df_short_res.empty:
|
|
- df_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
|
|
|
|
- df_res.to_sql("cellStateEstimation_interShort",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
|
|
+ df_short_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
|
|
|
|
+ df_short_res.to_sql("cellStateEstimation_interShort",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
|
|
#内短路ram处理.........................................................
|
|
#内短路ram处理.........................................................
|
|
df_warning_ram=df_warning_ram.drop(df_warning_ram[df_warning_ram.sn==sn].index)
|
|
df_warning_ram=df_warning_ram.drop(df_warning_ram[df_warning_ram.sn==sn].index)
|
|
@@ -140,35 +135,35 @@ def saftywarning_cal():
|
|
#电池热安全预警..............................................................................................................................................................
|
|
#电池热安全预警..............................................................................................................................................................
|
|
#读取内短路、析锂和一致性结果数据库数据
|
|
#读取内短路、析锂和一致性结果数据库数据
|
|
df_short = pd.read_sql("select time_sp,sn,short_current from cellstateestimation_intershort where sn = '{}' and time_sp between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
|
|
df_short = pd.read_sql("select time_sp,sn,short_current from cellstateestimation_intershort where sn = '{}' and time_sp between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
|
|
- df_liplated = pd.read_sql("select time,sn,liplated,liplated_amount as lipltd_amount from mechanism_liplated where sn = '{}' and time between '{}' and '{}'".format(sn,start_time2,end_time), db_qxcas_engine)
|
|
|
|
|
|
+ df_liplated = pd.read_sql("select time,sn,liplated,liplated_amount from mechanism_liplated where sn = '{}' and time between '{}' and '{}'".format(sn,start_time2,end_time), db_qxcas_engine)
|
|
df_uniform = pd.read_sql("select time,sn,cellsoc_diff,cellmin_num from cellstateestimation_uniform_socvoltdiff where sn = '{}' and time between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
|
|
df_uniform = pd.read_sql("select time,sn,cellsoc_diff,cellmin_num from cellstateestimation_uniform_socvoltdiff where sn = '{}' and time between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
|
|
|
|
|
|
#获取sn的故障RAM
|
|
#获取sn的故障RAM
|
|
df_fault_ram_sn=df_fault_ram[df_fault_ram['product_id']==sn]
|
|
df_fault_ram_sn=df_fault_ram[df_fault_ram['product_id']==sn]
|
|
|
|
|
|
#热安全预警
|
|
#热安全预警
|
|
- BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform,df_fault_ram_sn)
|
|
|
|
- df_warning_res=BatWarning.diag()
|
|
|
|
-
|
|
|
|
- df_warning_end=df_warning_res[df_warning_res['end_time'] != '0000-00-00 00:00:00']
|
|
|
|
- df_warning_end = df_warning_end.reset_index(drop=True)
|
|
|
|
- if not df_warning_end.empty: #df_warning_end历史故障筛选并更改数据库故障结束时间
|
|
|
|
- try:
|
|
|
|
- cursor.execute('''
|
|
|
|
- update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and code={} and end_time='0000-00-00 00:00:00' and factory='骑享'
|
|
|
|
- '''.format(datetime.datetime.now(), df_warning_end.loc[0,'end_time'], df_warning_end.loc[0,'Batpos'],sn, 110))
|
|
|
|
|
|
+ if df_fault_ram_sn.empty:
|
|
|
|
+ BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform)
|
|
|
|
+ df_warning_res=BatWarning.diag()
|
|
|
|
+ #当前热失控故障写入数据库
|
|
|
|
+ if not df_warning_res.empty:
|
|
|
|
+ df_warning_res['add_time'] = datetime.datetime.now()
|
|
|
|
+ df_warning_res['factory'] = '骑享'
|
|
|
|
+ df_warning_res.to_sql("all_fault_info",con=conn, if_exists="append",index=False)
|
|
conn.commit()
|
|
conn.commit()
|
|
- conn.close();
|
|
|
|
- except:
|
|
|
|
- logger.error(traceback.format_exc)
|
|
|
|
- logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
|
|
-
|
|
|
|
- elif df_fault_ram_sn.empty and (not df_warning_res.empty):
|
|
|
|
- df_warning_res['add_time'] = datetime.datetime.now()
|
|
|
|
- df_warning_res['factory'] = '骑享'
|
|
|
|
- df_warning_res.to_sql("all_fault_info",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
else:
|
|
else:
|
|
- pass
|
|
|
|
|
|
+ fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
|
|
|
|
+ if (now_time-fault_time).total_seconds()>24*3600: #df_warning_end历史故障筛选并更改数据库故障结束时间
|
|
|
|
+ df_fault_ram_sn['end_time']=end_time
|
|
|
|
+ df_fault_ram_sn['Batpos']=1
|
|
|
|
+ try:
|
|
|
|
+ cursor.execute('''
|
|
|
|
+ update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and code={} and end_time='0000-00-00 00:00:00' and factory='骑享'
|
|
|
|
+ '''.format(datetime.datetime.now(), df_fault_ram_sn.loc[0,'end_time'], df_fault_ram_sn.loc[0,'Batpos'],sn, 110))
|
|
|
|
+ conn.commit()
|
|
|
|
+ except:
|
|
|
|
+ logger.error(traceback.format_exc)
|
|
|
|
+ logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
except:
|
|
except:
|
|
logger.error(traceback.format_exc)
|
|
logger.error(traceback.format_exc)
|
|
logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
@@ -251,9 +246,10 @@ if __name__ == "__main__":
|
|
df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
|
|
df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
|
|
df_warning_ram1=pd.DataFrame(columns=['sn','time1','deltsoc1'])
|
|
df_warning_ram1=pd.DataFrame(columns=['sn','time1','deltsoc1'])
|
|
df_warning_ram2=pd.DataFrame(columns=['sn','time2','deltAs2'])
|
|
df_warning_ram2=pd.DataFrame(columns=['sn','time2','deltAs2'])
|
|
- df_warning_ram3=pd.DataFrame(columns=['sn','standingtime','standingtime1'])
|
|
|
|
|
|
+ df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1'])
|
|
df_lfp_ram=pd.DataFrame()
|
|
df_lfp_ram=pd.DataFrame()
|
|
-
|
|
|
|
|
|
+ # now_time='2021-10-15 00:00:00'
|
|
|
|
+ # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
|
|
saftywarning_cal()
|
|
saftywarning_cal()
|
|
#定时任务.......................................................................................................................................................................
|
|
#定时任务.......................................................................................................................................................................
|
|
scheduler = BlockingScheduler()
|
|
scheduler = BlockingScheduler()
|