浏览代码

更新热失控报警结束时间的写入

qingfeng 3 年之前
父节点
当前提交
9d8f6d05e2

+ 32 - 11
LIB/MIDDLE/CellStateEstimation/BatSafetyAlarm/V1_0_1/CBMSSafetyAlarm.py

@@ -42,7 +42,7 @@ class SafetyAlarm:
     
     #寻找当前行数据的所有温度值...................................................................................
     def _celltemp_get(self,num):   
-        celltemp = list(self.df_bms.loc[num,self.celltemp_name])
+        celltemp = np.array(self.df_bms.loc[num,self.celltemp_name])
         return celltemp
 
     #获取当前行所有电压数据............................................................................................
@@ -93,7 +93,7 @@ class SafetyAlarm:
 
                         delttime=(time2-time1).total_seconds()
                         celltemp_rate=(max(temp2-temp1)*60)/delttime    #计算最大温升速率
-                        if celltemp_rate>self.param.TrwTempRate and self.param.CellTempLwLmt<min(temp1) and max(temp1)<self.param.CellTempUpLmt:
+                        if celltemp_rate>self.param.TrwTempRate and self.param.CellTempLwLmt<min(temp1) and max(temp1)<self.param.CellTempUpLmt and max(temp2-temp1)>3:
                             celltemprise=1
                         else:
                             pass
@@ -115,19 +115,41 @@ class SafetyAlarm:
                 pass
             
             #电压诊断功能.........................................................................................................................................
-            cellvolt=self._cellvolt_get(i)
-            cellvolt2=np.array(cellvolt)
-            cellvoltmin=min(cellvolt)
-            cellvoltmax=max(cellvolt)
-            cellvoltmin_index=cellvolt.index(cellvoltmin)
-            cellvoltmax_index=cellvolt.index(cellvoltmax)
+            if i<1:
+                cellvolt2=self._cellvolt_get(i)
+                cellvoltmin2=min(cellvolt2)
+                cellvoltmax2=max(cellvolt2)
+                cellvoltmin_index2=list(cellvolt2).index(cellvoltmin2)
+                cellvoltmax_index2=list(cellvolt2).index(cellvoltmax2)
+                if not self.df_bms_ram.empty:
+                    cellvolt1=np.array(self.df_bms_ram.iloc[-1]['cellvolt'])
+                    cellvoltmin1=min(cellvolt1)
+                    cellvoltmax1=max(cellvolt1)
+                    cellvoltmin_index1=list(cellvolt1).index(cellvoltmin1)
+                    cellvoltmax_index1=list(cellvolt1).index(cellvoltmax1)
+                else:
+                    cellvoltmin1=cellvoltmin2
+                    cellvoltmax1=cellvoltmax2
+                    cellvoltmin_index1=cellvoltmin_index2
+                    cellvoltmax_index1=cellvoltmax_index2
+            else:
+                cellvolt2=self._cellvolt_get(i)
+                cellvoltmin2=min(cellvolt2)
+                cellvoltmax2=max(cellvolt2)
+                cellvoltmin_index2=list(cellvolt2).index(cellvoltmin2)
+                cellvoltmax_index2=list(cellvolt2).index(cellvoltmax2)
+                cellvolt1=self._cellvolt_get(i-1)
+                cellvoltmin1=min(cellvolt1)
+                cellvoltmax1=max(cellvolt1)
+                cellvoltmin_index1=list(cellvolt1).index(cellvoltmin1)
+                cellvoltmax_index1=list(cellvolt1).index(cellvoltmax1)
 
             #电压有效性..........................................................................................................................................
-            if (cellvoltmin<2 and cellvoltmax>4.5 and (cellvoltmax_index-cellvoltmin_index)==1) or cellvoltmin<0.01:   #电压断线故障进入
+            if (cellvoltmin2<2 and cellvoltmax2>4.5 and abs(cellvoltmax_index2-cellvoltmin_index2)==1) or cellvoltmin2<0.01 or (cellvoltmin1<2 and cellvoltmax1>4.5 and abs(cellvoltmax_index1-cellvoltmin_index1)==1) or cellvoltmin1<0.01:   #电压断线故障进入
                 cellvoltvalid=0
             else:
                 cellvoltvalid=1
-   
+
             if cellvoltvalid==1:
                 #单体电压跌落诊断...........................................................................................................................
                 if i<1:
@@ -135,7 +157,6 @@ class SafetyAlarm:
                         time1=self.df_bms_ram.iloc[-1]['time']
                         time2=self.bmstime[i]
                         delttime=(time2-time1).total_seconds()
-                        cellvolt1=np.array(self.df_bms_ram.iloc[-1]['cellvolt'])
                         if delttime<310:
                             if self.packcrnt[i]<0.5 and max(cellvolt1-cellvolt2)>self.param.TrwCellVoltFall:
                                 cellvoltfall=1

+ 17 - 16
LIB/MIDDLE/CellStateEstimation/BatSafetyAlarm/main.py

@@ -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()