|
@@ -12,6 +12,8 @@ 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.BatSafetyWarning.V1_0_1 import CBMSBatUniform
|
|
|
|
+from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import VoltStray
|
|
from urllib import parse
|
|
from urllib import parse
|
|
import pymysql
|
|
import pymysql
|
|
|
|
|
|
@@ -25,6 +27,8 @@ def saftywarning_cal():
|
|
global df_warning_ram2
|
|
global df_warning_ram2
|
|
global df_warning_ram3
|
|
global df_warning_ram3
|
|
global df_lfp_ram
|
|
global df_lfp_ram
|
|
|
|
+ global df_lfp_ram1
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
# 读取结果数据库
|
|
# 读取结果数据库
|
|
@@ -38,7 +42,10 @@ def saftywarning_cal():
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
user2, parse.quote_plus(password2), host2, port2, db2
|
|
user2, parse.quote_plus(password2), host2, port2, db2
|
|
))
|
|
))
|
|
- conn = pymysql.connect(host=host2, port=port2, user=user2, password=password2, database=db2)
|
|
|
|
|
|
+ conn_platform = pymysql.connect(host=host2, port=port2, user=user2, password=password2, database=db2)
|
|
|
|
+ cursor_platform = conn_platform.cursor()
|
|
|
|
+
|
|
|
|
+
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='qx_cas'
|
|
db='qx_cas'
|
|
@@ -50,8 +57,8 @@ def saftywarning_cal():
|
|
user, parse.quote_plus(password), host, port, db
|
|
user, parse.quote_plus(password), host, port, db
|
|
))
|
|
))
|
|
|
|
|
|
- conn = pymysql.connect(host=host2, port=port2, user=user2, password=password2, database=db2)
|
|
|
|
- cursor = conn.cursor()
|
|
|
|
|
|
+ conn_cas = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
|
|
|
|
+ cursor_cas = conn_cas.cursor()
|
|
|
|
|
|
result=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice from all_fault_info where factory = '{}'".format('骑享'), db_safety_platform_engine)
|
|
result=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice from all_fault_info where factory = '{}'".format('骑享'), db_safety_platform_engine)
|
|
result = result[['start_time', 'end_time', 'product_id', 'code', 'level', 'info', 'advice']]
|
|
result = result[['start_time', 'end_time', 'product_id', 'code', 'level', 'info', 'advice']]
|
|
@@ -61,8 +68,12 @@ def saftywarning_cal():
|
|
start_time=now_time-datetime.timedelta(hours=12)
|
|
start_time=now_time-datetime.timedelta(hours=12)
|
|
start_time1=now_time-datetime.timedelta(days=7)
|
|
start_time1=now_time-datetime.timedelta(days=7)
|
|
start_time2=now_time-datetime.timedelta(days=90)
|
|
start_time2=now_time-datetime.timedelta(days=90)
|
|
|
|
+ start_time3=now_time-datetime.timedelta(days=3)
|
|
|
|
+
|
|
start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
start_time1=start_time1.strftime('%Y-%m-%d %H:%M:%S')
|
|
start_time1=start_time1.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ start_time2=start_time2.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ start_time3=start_time3.strftime('%Y-%m-%d %H:%M:%S')
|
|
end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
for i in range(0, len(df_sn)):
|
|
for i in range(0, len(df_sn)):
|
|
@@ -86,7 +97,9 @@ def saftywarning_cal():
|
|
|
|
|
|
# 读取soh数据
|
|
# 读取soh数据
|
|
df_soh = pd.read_sql("select time_st,sn,soh,cellsoh from cellstateestimation_soh where sn = '{}' order by id desc limit 1".format(sn), db_qxcas_engine)
|
|
df_soh = pd.read_sql("select time_st,sn,soh,cellsoh from cellstateestimation_soh where sn = '{}' order by id desc limit 1".format(sn), db_qxcas_engine)
|
|
-
|
|
|
|
|
|
+ df_uniform = pd.read_sql("select time,sn,cellsoc_diff,cellvolt_diff,cellmin_num,cellmax_num from cellstateestimation_uniform_socvoltdiff where sn = '{}' order by id desc limit 1".format(sn), db_qxcas_engine)
|
|
|
|
+ df_uniform.loc[0,'cellvolt_rank']=str([1]*20)
|
|
|
|
+ df_voltsigma=pd.DataFrame()
|
|
#读取原始数据库数据................................................................................id........................................................................
|
|
#读取原始数据库数据................................................................................id........................................................................
|
|
dbManager = DBManager.DBManager()
|
|
dbManager = DBManager.DBManager()
|
|
df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
|
|
df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
|
|
@@ -104,18 +117,41 @@ def saftywarning_cal():
|
|
df_warning_ram_sn1.reset_index(inplace=True,drop=True) #重置索引
|
|
df_warning_ram_sn1.reset_index(inplace=True,drop=True) #重置索引
|
|
df_warning_ram_sn2.reset_index(inplace=True,drop=True) #重置索引
|
|
df_warning_ram_sn2.reset_index(inplace=True,drop=True) #重置索引
|
|
df_warning_ram_sn3.reset_index(inplace=True,drop=True) #重置索引
|
|
df_warning_ram_sn3.reset_index(inplace=True,drop=True) #重置索引
|
|
- if celltype>50:
|
|
|
|
- df_lfp_ram=df_lfp_ram.reindex(columns=df_bms.columns.tolist()+['sn'])
|
|
|
|
|
|
+ if celltype>50 and (not df_lfp_ram.empty):
|
|
df_lfp_ram_sn=df_lfp_ram[df_lfp_ram['sn']==sn]
|
|
df_lfp_ram_sn=df_lfp_ram[df_lfp_ram['sn']==sn]
|
|
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()
|
|
|
|
+ df_lfp_ram=pd.DataFrame(columns=df_bms.columns.tolist()+['sn'])
|
|
|
|
+
|
|
|
|
+ if celltype>50 and (not df_lfp_ram1.empty):
|
|
|
|
+ df_lfp_ram_sn1=df_lfp_ram1[df_lfp_ram1['sn']==sn]
|
|
|
|
+ df_lfp_ram_sn1.reset_index(inplace=True,drop=True) #重置索引
|
|
|
|
+ else:
|
|
|
|
+ df_lfp_ram_sn1=pd.DataFrame()
|
|
|
|
+ df_lfp_ram1=pd.DataFrame(columns=df_bms.columns.tolist()+['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)
|
|
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_short_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
|
|
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)
|
|
df_short_res.to_sql("cellStateEstimation_interShort",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
+
|
|
|
|
+ #静置电压排名..................................................................................................................................................
|
|
|
|
+ BatUniform=CBMSBatUniform.BatUniform(sn,celltype,df_bms,df_uniform,df_ram_res3,df_lfp_ram_sn1)
|
|
|
|
+ df_rank_res, df_ram_res3, df_ram_res5=BatUniform.batuniform()
|
|
|
|
+ if not df_rank_res.empty:
|
|
|
|
+ df_uniform=df_rank_res
|
|
|
|
+ df_rank_res.to_sql("cellstateestimation_uniform_socvoltdiff",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
+
|
|
|
|
+ #电压离群.....................................................................................................................................................
|
|
|
|
+ OutLineVol=VoltStray.main(sn,df_bms,celltype)
|
|
|
|
+ if not OutLineVol.empty:
|
|
|
|
+ df_voltsigma=OutLineVol
|
|
|
|
+ OutLineVol.to_sql("outlier_voltchangeratio",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)
|
|
@@ -131,44 +167,49 @@ def saftywarning_cal():
|
|
if celltype>50:
|
|
if celltype>50:
|
|
df_lfp_ram=df_lfp_ram.drop(df_lfp_ram[df_lfp_ram.sn==sn].index)
|
|
df_lfp_ram=df_lfp_ram.drop(df_lfp_ram[df_lfp_ram.sn==sn].index)
|
|
df_lfp_ram=pd.concat([df_lfp_ram,df_ram_res4],ignore_index=True)
|
|
df_lfp_ram=pd.concat([df_lfp_ram,df_ram_res4],ignore_index=True)
|
|
|
|
+ df_lfp_ram1=df_lfp_ram1.drop(df_lfp_ram1[df_lfp_ram1.sn==sn].index)
|
|
|
|
+ df_lfp_ram1=pd.concat([df_lfp_ram1,df_ram_res5],ignore_index=True)
|
|
|
|
|
|
#电池热安全预警..............................................................................................................................................................
|
|
#电池热安全预警..............................................................................................................................................................
|
|
#读取内短路、析锂和一致性结果数据库数据
|
|
#读取内短路、析锂和一致性结果数据库数据
|
|
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 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,cellvolt_diff,cellmin_num,cellmax_num,cellvolt_rank from cellstateestimation_uniform_socvoltdiff where sn = '{}' and time between '{}' and '{}'".format(sn,start_time3,end_time), db_qxcas_engine)
|
|
|
|
+ df_voltsigma = pd.read_sql("select time,sn,VolOl_Uni,VolChng_Uni from outlier_voltchangeratio where sn = '{}' and time between '{}' and '{}'".format(sn,start_time3,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]
|
|
|
|
|
|
#热安全预警
|
|
#热安全预警
|
|
if df_fault_ram_sn.empty:
|
|
if df_fault_ram_sn.empty:
|
|
- BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform)
|
|
|
|
|
|
+ BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform,df_voltsigma)
|
|
df_warning_res=BatWarning.diag()
|
|
df_warning_res=BatWarning.diag()
|
|
#当前热失控故障写入数据库
|
|
#当前热失控故障写入数据库
|
|
if not df_warning_res.empty:
|
|
if not df_warning_res.empty:
|
|
df_warning_res['add_time'] = datetime.datetime.now()
|
|
df_warning_res['add_time'] = datetime.datetime.now()
|
|
df_warning_res['factory'] = '骑享'
|
|
df_warning_res['factory'] = '骑享'
|
|
- df_warning_res.to_sql("all_fault_info",con=conn, if_exists="append",index=False)
|
|
|
|
- conn.commit()
|
|
|
|
|
|
+ df_warning_res.to_sql("all_fault_info",con=db_safety_platform_engine, if_exists="append",index=False)
|
|
|
|
+ conn_platform.commit()
|
|
else:
|
|
else:
|
|
fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
|
|
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历史故障筛选并更改数据库故障结束时间
|
|
|
|
|
|
+ if (now_time-fault_time).total_seconds()>3*24*3600: #df_warning_end历史故障筛选并更改数据库故障结束时间
|
|
df_fault_ram_sn['end_time']=end_time
|
|
df_fault_ram_sn['end_time']=end_time
|
|
df_fault_ram_sn['Batpos']=1
|
|
df_fault_ram_sn['Batpos']=1
|
|
try:
|
|
try:
|
|
cursor.execute('''
|
|
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='骑享'
|
|
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))
|
|
'''.format(datetime.datetime.now(), df_fault_ram_sn.loc[0,'end_time'], df_fault_ram_sn.loc[0,'Batpos'],sn, 110))
|
|
- conn.commit()
|
|
|
|
|
|
+ conn_platform.commit()
|
|
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)
|
|
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)
|
|
- cursor.close()
|
|
|
|
- conn.close()
|
|
|
|
|
|
+ cursor_platform.close()
|
|
|
|
+ conn_platform.close()
|
|
|
|
+ cursor_cas.close()
|
|
|
|
+ conn_cas.close()
|
|
db_qxcas_engine.dispose()
|
|
db_qxcas_engine.dispose()
|
|
db_safety_platform_engine.dispose()
|
|
db_safety_platform_engine.dispose()
|
|
logger.info("pid-{} Done!".format(os.getpid()))
|
|
logger.info("pid-{} Done!".format(os.getpid()))
|
|
@@ -246,8 +287,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','time3','standingtime','standingtime1'])
|
|
|
|
|
|
+ df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1','standingtime2'])
|
|
df_lfp_ram=pd.DataFrame()
|
|
df_lfp_ram=pd.DataFrame()
|
|
|
|
+ df_lfp_ram1=pd.DataFrame()
|
|
|
|
+
|
|
# now_time='2021-10-15 00:00:00'
|
|
# now_time='2021-10-15 00:00:00'
|
|
# now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
|
|
# now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
|
|
saftywarning_cal()
|
|
saftywarning_cal()
|