|
@@ -12,7 +12,7 @@ from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
|
|
|
#...................................电池包电芯安全诊断函数......................................................................................................................
|
|
|
def diag_cal(sn_list, df_bms_ram):
|
|
|
|
|
|
- start=time.time()
|
|
|
+ # start=time.time()
|
|
|
now_time=datetime.datetime.now()
|
|
|
start_time=now_time-datetime.timedelta(seconds=70)
|
|
|
start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
@@ -28,7 +28,7 @@ def diag_cal(sn_list, df_bms_ram):
|
|
|
db='safety_platform'
|
|
|
mysql = pymysql.connect (host=host, port=port, user=user, password=password, database=db)
|
|
|
cursor = mysql.cursor()
|
|
|
- param='start_time, end_time, product_id, code, level, info,advice'
|
|
|
+ param='start_time,end_time,product_id,code,level,info,advice'
|
|
|
tablename='all_fault_info'
|
|
|
sql = "select %s from %s where code=119 and end_time='0000-00-00 00:00:00'" %(param,tablename)
|
|
|
cursor.execute(sql)
|
|
@@ -60,10 +60,10 @@ def diag_cal(sn_list, df_bms_ram):
|
|
|
print(df_bms)
|
|
|
|
|
|
#电池诊断................................................................................................................................................................
|
|
|
- if not df_bms.empty:
|
|
|
- df_diag_ram_sn=df_diag_ram[df_diag_ram['product_id']==sn]
|
|
|
- df_bms_ram_sn=df_bms_ram[df_bms_ram['sn']==sn]
|
|
|
- if df_diag_ram_sn.empty:
|
|
|
+ df_diag_ram_sn=df_diag_ram[df_diag_ram['product_id']==sn]
|
|
|
+ df_bms_ram_sn=df_bms_ram[df_bms_ram['sn']==sn]
|
|
|
+ if df_diag_ram_sn.empty:
|
|
|
+ if not df_bms.empty:
|
|
|
SafetyAlarm=CBMSSafetyAlarm.SafetyAlarm(sn,celltype,df_bms, df_bms_ram_sn)
|
|
|
df_diag_res, df_bms_res=SafetyAlarm.diag()
|
|
|
|
|
@@ -74,19 +74,20 @@ def diag_cal(sn_list, df_bms_ram):
|
|
|
|
|
|
#当前热失控故障写入数据库
|
|
|
if not df_diag_res.empty:
|
|
|
- with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控.txt','a') as file:
|
|
|
+ with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控报警.txt','a') as file:
|
|
|
file.write(str(tuple(df_diag_res.iloc[-1]))+'\n')
|
|
|
|
|
|
- #当前热失控已超过一天变为历史故障并更改数据库
|
|
|
- elif (now_time-datetime.strptime(df_diag_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')).total_seconds()>24*3600:
|
|
|
- df_diag_ram_sn.iloc[-1]['end_time']=now_time
|
|
|
+ #当前热失控已超过一天变为历史故障并更改数据库
|
|
|
+ else:
|
|
|
+ fault_time=datetime.datetime.strptime(df_diag_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
|
|
|
+ if (now_time-fault_time).total_seconds()>24*3600:
|
|
|
+ df_diag_ram_sn['end_time']=end_time
|
|
|
df_diag_ram_sn['Batpos']=1
|
|
|
- with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控.txt','a') as file:
|
|
|
- file.write(str(tuple(df_diag_res.iloc[-1]))+'\n')
|
|
|
+ with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控报警.txt','a') as file:
|
|
|
+ file.write(str(tuple(df_diag_ram_sn.iloc[-1]))+'\n')
|
|
|
|
|
|
- #故障处理........................................................................................................................................................
|
|
|
- end=time.time()
|
|
|
- print(end-start)
|
|
|
+ # end=time.time()
|
|
|
+ # print(end-start)
|
|
|
#...................................................主进程...........................................................................................................
|
|
|
def mainprocess():
|
|
|
global SNnums
|
|
@@ -119,7 +120,7 @@ if __name__ == "__main__":
|
|
|
SNnums_C7255=SNdata_C7255['SN号'].tolist()
|
|
|
SNnums_U7255=SNdata_U7255['SN号'].tolist()
|
|
|
SNnums=[SNnums_L7255 + SNnums_C7255 + SNnums_U7255, SNnums_6040 + SNnums_4840 + SNnums_6060]
|
|
|
- SNnums=[[], ['MGMCLN750N215N205']]
|
|
|
+ SNnums=[[], ['PK504B10100004447']]
|
|
|
|
|
|
mylog=log.Mylog('log_diag.txt','error')
|
|
|
mylog.logcfg()
|