Pārlūkot izejas kodu

Merge branch 'dev' of http://git.fast-fun.cn:92/lmstack/data_analyze_platform into dev

zhuxi 2 gadi atpakaļ
vecāks
revīzija
4a2d33c47b

+ 25 - 16
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSSafetyWarning.py

@@ -48,6 +48,8 @@ class SafetyWarning:
         mk_z_list=[]
         mk_Tau_list=[]
         mk_slope_list=[]
+        mk_s_list=[]
+        mk_svar_list=[]
 
         if not self.df_short.empty:
             short_current=self.df_short['short_current']
@@ -87,8 +89,7 @@ class SafetyWarning:
             cellvolt_rank=self.df_uniform['cellvolt_rank']
             cellvolt_rank=cellvolt_rank.str.replace("[", '')
             cellvolt_rank=cellvolt_rank.str.replace("]", '')
-
-        # plt.figure()
+    
         for i in range(self.param.CellVoltNums):
             #漏电流故障判断...........................................................................
             if not self.df_short.empty:
@@ -114,14 +115,14 @@ class SafetyWarning:
                 y=VoltChange[volt_column[i]]
                 volt3sigma=np.array(Volt_3Sigma[volt_column[i]].map(lambda x:eval(x)))
                 volt3sigma_sum=np.sum(volt3sigma<-3)
-                # #电压变化率
-                # a1,b1=np.polyfit(VoltChange['time'].tolist(),y.tolist(),1)
-                # y1=a1*VoltChange['time']+b1
-                # y_mean=y.mean()
-                # R2=1-(np.sum((y1-y)**2))/(np.sum((y-y_mean)**2))
-                # R2_list.append(R2)
+                #电压变化率
+                a1,b1=np.polyfit(VoltChange['time'].tolist(),y.tolist(),1)
+                y1=a1*VoltChange['time']+b1
+                y_mean=y.mean()
+                R2=1-(np.sum((y1-y)**2))/(np.sum((y-y_mean)**2))
+                R2_list.append(R2)
                 
-                # volt_rate.append(a1)
+                volt_rate.append(a1)
                 # plt.plot(xtime1,y1,label='单体电压'+str(i+1))
                 # plt.xlabel('时间', fontsize=25)
                 # plt.ylabel('SOC差', fontsize=25)
@@ -147,13 +148,15 @@ class SafetyWarning:
                 mk_z_list.append(mk_res.z)
                 mk_Tau_list.append(mk_res.Tau)
                 mk_slope_list.append(mk_res.slope)
+                mk_s_list.append(mk_res.s)
+                mk_svar_list.append(mk_res.var_s)
                 """
                 trend:趋势;
                 h:有无趋势;
                 p:趋势的显著水平,越小趋势越明显;
                 z:检验统计量,正代表随时间增大趋势,负代表随时间减小趋势;
                 Tau:反映两个序列的相关性,接近1的值表示强烈的正相关,接近-1的值表示强烈的负相关;
-                s:如果S是一个正数,那么后一部分的观测值相比之前的观测值会趋向于变大;如果S是一个负数,那么后一部分的观测值相比之前的观测值会趋向于变小
+                s:Mann-Kendal的分数,如果S是一个正数,那么后一部分的观测值相比之前的观测值会趋向于变大;如果S是一个负数,那么后一部分的观测值相比之前的观测值会趋向于变小
                 slope:趋势斜率
                 """
                 # print('单体电压{}:\n'.format(i+1), mk_res)
@@ -167,6 +170,8 @@ class SafetyWarning:
                 mk_z_list.append(0)
                 mk_Tau_list.append(0)
                 mk_slope_list.append(0)
+                mk_s_list.append(0)
+                mk_svar_list.append(0)
 
             #电芯SOC排名判断.............................................................................
             if not self.df_uniform.empty:
@@ -189,8 +194,9 @@ class SafetyWarning:
                 df_res.loc[0]=[time_now, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
                 break
             else:
-                pass       
+                pass  
         
+        # plt.show()   
         #电池电压变化率离群度计算...............................................................................
         volt_rate_std=np.std(volt_rate)
         volt_rate_mean=np.mean(volt_rate)
@@ -199,7 +205,11 @@ class SafetyWarning:
         #mk离群度计算
         mk_slope_std=np.std(mk_slope_list)
         mk_slope_mean=np.mean(mk_slope_list)
-        mk_slope_3sigma=(np.array(mk_slope_list)-mk_slope_mean)/mk_slope_std   
+        mk_slope_3sigma=(np.array(mk_slope_list)-mk_slope_mean)/mk_slope_std
+
+        # mk_s_std=np.std(mk_s_list)
+        # mk_s_mean=np.mean(mk_s_list)
+        # mk_s_3sigma=(np.array(mk_s_list)-mk_s_mean)/mk_s_std 
 
         mk_z_std=np.std(mk_z_list)
         mk_z_mean=np.mean(mk_z_list)
@@ -227,20 +237,20 @@ class SafetyWarning:
         #mana-kendall趋势检测
         for i in range(len(mk_p_list)):
             #适用动态工况判断
-            if mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<self.param.mk_z and mk_Tau_list[i]<self.param.mk_Tau and mk_slope_3sigma[i]<-3 and mk_slope_list[i]<self.param.mk_slope and abs(cellsoh_3sigma[i])<2.5:
+            if mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<self.param.mk_z and mk_Tau_list[i]<self.param.mk_Tau and mk_slope_3sigma[i]<-3 and mk_slope_list[i]<self.param.mk_slope and abs(cellsoh_3sigma[i])<2.5 and volt_rate_3sigma[i]<-3:
                 faultcode=110
                 faultlv=4
                 faultinfo='电芯{}发生热失控安全预警'.format(i+1)
                 faultadvice='2联系用户远离电池,立刻召回电池'
                 df_res.loc[0]=[time_now, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
             #适用静态工况判断
-            elif self.celltype<=50 and mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<-6 and (mk_Tau_list[i]<-0.9 or mk_z_3sigma[i]<-3) and mk_slope_3sigma[i]<-3.5 and mk_slope_list[i]<-0.025:
+            elif self.celltype<=50 and mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<-6 and (mk_Tau_list[i]<-0.9 or mk_z_3sigma[i]<-3) and mk_slope_3sigma[i]<-3.5 and mk_slope_list[i]<-0.025 and volt_rate_3sigma[i]<-3:
                 faultcode=110
                 faultlv=4
                 faultinfo='电芯{}发生热失控安全预警'.format(i+1)
                 faultadvice='2联系用户远离电池,立刻召回电池'
                 df_res.loc[0]=[time_now, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
-            elif self.celltype>50 and mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<-6 and (mk_Tau_list[i]<-0.9 or mk_z_3sigma[i]<-3) and mk_slope_3sigma[i]<-3.5 and mk_slope_list[i]<-0.25:
+            elif self.celltype>50 and mk_trend_list[i]=='decreasing' and mk_p_list[i]<self.param.mk_p and mk_z_list[i]<-6 and (mk_Tau_list[i]<-0.9 or mk_z_3sigma[i]<-3) and mk_slope_3sigma[i]<-3.5 and mk_slope_list[i]<-0.25 and volt_rate_3sigma[i]<-3:
                 faultcode=110
                 faultlv=4
                 faultinfo='电芯{}发生热失控安全预警'.format(i+1)
@@ -249,5 +259,4 @@ class SafetyWarning:
             else:
                 pass
 
-        # plt.show()
         return df_res