|
@@ -60,15 +60,15 @@ def saftywarning_cal():
|
|
|
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", db_safety_platform_engine)
|
|
|
result = result[['start_time', 'end_time', 'product_id', 'code', 'level', 'info', 'advice']]
|
|
|
df_fault_ram=result[(result['end_time']=='0000-00-00 00:00:00') & (result['code']==110)]
|
|
|
|
|
|
now_time=datetime.datetime.now()
|
|
|
- start_time=now_time-datetime.timedelta(hours=12)
|
|
|
+ start_time=now_time-datetime.timedelta(hours=6)
|
|
|
start_time1=now_time-datetime.timedelta(days=7)
|
|
|
- start_time2=now_time-datetime.timedelta(days=90)
|
|
|
- start_time3=now_time-datetime.timedelta(days=3)
|
|
|
+ start_time2=now_time-datetime.timedelta(days=3)
|
|
|
+ start_time3=now_time-datetime.timedelta(days=1)
|
|
|
|
|
|
start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
start_time1=start_time1.strftime('%Y-%m-%d %H:%M:%S')
|
|
@@ -77,6 +77,7 @@ def saftywarning_cal():
|
|
|
end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
for i in range(0, len(df_sn)):
|
|
|
+ factory = "骑享"
|
|
|
try:
|
|
|
if df_sn.loc[i, 'imei'][5:9] == 'N640':
|
|
|
celltype=1 #6040三元电芯
|
|
@@ -86,8 +87,9 @@ def saftywarning_cal():
|
|
|
celltype=99 # 6060锂电芯
|
|
|
elif df_sn.loc[i, 'imei'][3:5] == 'LX' and df_sn.loc[i, 'imei'][5:9] == 'N750':
|
|
|
celltype=3 #力信 50ah三元电芯
|
|
|
- elif df_sn.loc[i, 'imei'][3:5] == 'CL' and df_sn.loc[i, 'imei'][5:9] == 'N750':
|
|
|
- celltype=4 #CATL 50ah三元电芯
|
|
|
+ elif df_sn.loc[i, 'imei'][3:9] == 'CLL128':
|
|
|
+ celltype=100 # 重卡
|
|
|
+ factory = "金茂换电"
|
|
|
else:
|
|
|
logger.info("pid-{} celltype-{} SN: {} SKIP!".format(os.getpid(), "未知", sn))
|
|
|
continue
|
|
@@ -97,7 +99,7 @@ def saftywarning_cal():
|
|
|
|
|
|
# 读取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_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 = pd.read_sql("select time,sn,cellsoc_diff,cellvolt_diff,cellmin_num,cellmax_num,cellvolt_rank 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........................................................................
|
|
@@ -147,10 +149,9 @@ def saftywarning_cal():
|
|
|
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)
|
|
|
+ df_voltsigma=VoltStray.main(sn,df_bms,celltype)
|
|
|
+ if not df_voltsigma.empty:
|
|
|
+ df_voltsigma.to_sql("outlier_voltchangeratio",con=db_qxcas_engine, if_exists="append",index=False)
|
|
|
|
|
|
|
|
|
#内短路ram处理.........................................................
|
|
@@ -173,8 +174,8 @@ 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_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,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_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,cellvolt_diff,cellmin_num,cellmax_num,cellvolt_rank from cellstateestimation_uniform_socvoltdiff where sn = '{}' and time between '{}' and '{}'".format(sn,start_time2,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
|
|
@@ -182,12 +183,12 @@ def saftywarning_cal():
|
|
|
|
|
|
#热安全预警
|
|
|
if df_fault_ram_sn.empty:
|
|
|
- BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform,df_voltsigma)
|
|
|
+ BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_uniform,df_voltsigma,df_soh)
|
|
|
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['factory'] = factory
|
|
|
df_warning_res.to_sql("all_fault_info",con=db_safety_platform_engine, if_exists="append",index=False)
|
|
|
conn_platform.commit()
|
|
|
else:
|
|
@@ -196,9 +197,9 @@ def saftywarning_cal():
|
|
|
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))
|
|
|
+ cursor_platform.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'
|
|
|
+ '''.format(datetime.datetime.now(), df_fault_ram_sn.iloc[-1]['end_time'], df_fault_ram_sn.iloc[-1]['Batpos'],sn, 110))
|
|
|
conn_platform.commit()
|
|
|
except:
|
|
|
logger.error(traceback.format_exc)
|
|
@@ -234,7 +235,7 @@ if __name__ == "__main__":
|
|
|
password='Qixiang2021'
|
|
|
conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
|
|
|
cursor = conn.cursor()
|
|
|
- cursor.execute("select sn, imei, add_time from app_device")
|
|
|
+ cursor.execute("select sn, imei, add_time from app_device where status in (1,2,3)")
|
|
|
res = cursor.fetchall()
|
|
|
df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
|
|
|
df_sn = df_sn.reset_index(drop=True)
|
|
@@ -296,7 +297,7 @@ if __name__ == "__main__":
|
|
|
saftywarning_cal()
|
|
|
#定时任务.......................................................................................................................................................................
|
|
|
scheduler = BlockingScheduler()
|
|
|
- scheduler.add_job(saftywarning_cal, 'interval', seconds=12*3600, id='saftywarning_cal')
|
|
|
+ scheduler.add_job(saftywarning_cal, 'interval', hours=6, id='saftywarning_cal')
|
|
|
|
|
|
try:
|
|
|
scheduler.start()
|