瀏覽代碼

Merge remote-tracking branch 'origin/dev' into pro

lmstack 3 年之前
父節點
當前提交
a39e408279

+ 158 - 147
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSBatInterShort.py

@@ -86,7 +86,8 @@ class BatInterShort():
         time_last=time_now-datetime.timedelta(seconds=1800)
         df_volt=self.df_bms[(self.df_bms['time']>=time_last) & (self.df_bms['time']<=time_now)]
         df_volt=df_volt[self.cellvolt_name]
-        if len(df_volt)>2:
+        cellvolt_std=df_volt.std(axis=0)
+        if len(df_volt)>2 and max(cellvolt_std)<1.5:
             cellvolt_sum=df_volt.sum(0)-df_volt.max(0)-df_volt.min(0)
             cellvolt_mean=cellvolt_sum/(len(df_volt)-2)
             cellvolt=cellvolt_mean/1000
@@ -96,8 +97,10 @@ class BatInterShort():
                 cellvolt=df_volt.mean(0)/1000
             else:
                 cellvolt=pd.DataFrame()
+        elif len(df_volt)==1:
+            cellvolt=df_volt.iloc[0]/1000
         else:
-            cellvolt=df_volt.iloc[0]
+            cellvolt=pd.DataFrame()
         return cellvolt
 
     #获取当前行所有电压数据........................................................................................
@@ -314,49 +317,53 @@ class BatInterShort():
                     if standingtime>self.StandardStandingTime*2:      #静置时间满足要求
                         standingtime=0
                         cellvolt_now=self._avgvolt_get(i)
+                        if not cellvolt_now.empty:
+                            cellvolt_min=min(cellvolt_now)
+                            cellvolt_max=max(cellvolt_now)
+                            # cellvolt_last=self._avgvolt_get(i-1)
+                            # deltvolt=max(abs(cellvolt_now-cellvolt_last))
+                            cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
+                            cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
+
+                            if 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and (45<cellsoc_max or cellsoc_max<30) and (45<cellsoc_min or cellsoc_min<30): 
+                                dict_baltime={}   #获取每个电芯的均衡时间
+                                deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
+                                time_last=self.bmstime[i]
+                                firsttime=0
+                                df_ram_last.loc[0]=[self.sn,time_last,deltsoc_last,cellsoc_last]   #更新RAM信息
+                    else:
+                        pass                
+                elif standingtime>3600*12:
+                    standingtime=0
+                    cellvolt_now=self._avgvolt_get(i)
+                    if not cellvolt_now.empty:
                         cellvolt_min=min(cellvolt_now)
                         cellvolt_max=max(cellvolt_now)
                         # cellvolt_last=self._avgvolt_get(i-1)
                         # deltvolt=max(abs(cellvolt_now-cellvolt_last))
                         cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
                         cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
-
-                        if (not cellvolt_now.empty) and 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and (45<cellsoc_max or cellsoc_max<30) and (45<cellsoc_min or cellsoc_min<30): 
-                            dict_baltime={}   #获取每个电芯的均衡时间
-                            deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
-                            time_last=self.bmstime[i]
-                            firsttime=0
-                            df_ram_last.loc[0]=[self.sn,time_last,deltsoc_last,cellsoc_last]   #更新RAM信息
-                    else:
-                        pass                
-                elif standingtime>3600*12:
-                    standingtime=0
-                    cellvolt_now=self._avgvolt_get(i)
-                    cellvolt_min=min(cellvolt_now)
-                    cellvolt_max=max(cellvolt_now)
-                    # cellvolt_last=self._avgvolt_get(i-1)
-                    # deltvolt=max(abs(cellvolt_now-cellvolt_last))
-                    
-                    if (not cellvolt_now.empty) and 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5:
-                        dict_baltime=self._bal_time(dict_bal)   #获取每个电芯的均衡时间
-                        deltsoc_now, cellsoc_now=self._celldeltsoc_get(i,dict_baltime,capacity)
-                        time_now=self.bmstime[i]
-                        if -5<max(cellsoc_now-cellsoc_last)<5:
-                            df_ram_last.loc[0]=[self.sn,time_now,deltsoc_now,cellsoc_now] #更新RAM信息
-                            
-                            list_sub=deltsoc_now-deltsoc_last
-                            list_pud=(0.01*capacity*3600*1000)/(time_now-time_last).total_seconds()
-                            leak_current=list_sub*list_pud
-                            # leak_current=np.array(leak_current)
-                            leak_current=np.round(leak_current,3)
-                            leak_current=list(leak_current)
-                            
-                            df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)]  #计算结果存入Dataframe
-                            time_last=time_now  #更新时间
-                            deltsoc_last=deltsoc_now    #更新soc差
-                            dict_bal={}
-                        else:
-                            firsttime=1
+                        
+                        if 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and (45<cellsoc_max or cellsoc_max<30) and (45<cellsoc_min or cellsoc_min<30):
+                            dict_baltime=self._bal_time(dict_bal)   #获取每个电芯的均衡时间
+                            deltsoc_now, cellsoc_now=self._celldeltsoc_get(i,dict_baltime,capacity)
+                            time_now=self.bmstime[i]
+                            if -5<max(cellsoc_now-cellsoc_last)<5:
+                                df_ram_last.loc[0]=[self.sn,time_now,deltsoc_now,cellsoc_now] #更新RAM信息
+                                
+                                list_sub=deltsoc_now-deltsoc_last
+                                list_pud=(0.01*capacity*3600*1000)/(time_now-time_last).total_seconds()
+                                leak_current=list_sub*list_pud
+                                # leak_current=np.array(leak_current)
+                                leak_current=np.round(leak_current,3)
+                                leak_current=list(leak_current)
+                                
+                                df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)]  #计算结果存入Dataframe
+                                time_last=time_now  #更新时间
+                                deltsoc_last=deltsoc_now    #更新soc差
+                                dict_bal={}
+                            else:
+                                firsttime=1
                 else: 
                     try:  
                         balstat=int(self.df_bms.loc[i,'单体均衡状态'])
@@ -376,39 +383,40 @@ class BatInterShort():
                 if self.StandardStandingTime<standingtime1:  
                     standingtime1=0
                     cellvolt_now1=self._avgvolt_get(i)
-                    cellvolt_max1=max(cellvolt_now1)
-                    cellvolt_min1=min(cellvolt_now1)
-                    # cellvolt_last1=self._avgvolt_get(i-1)
-                    # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
-                    cellsoc_now1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
-
-                    if (not cellvolt_now1.empty) and cellsoc_now1>=self.param.FullChrgSoc-10 and 2<cellvolt_min1<4.5 and 2<cellvolt_max1<4.5:
-                        if firsttime1==1:
-                            dict_baltime1={}   #获取每个电芯的均衡时间
-                            deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
-                            time_last1=self.bmstime[i]
-                            firsttime1=0
-                            df_ram_last1.loc[0]=[self.sn,time_last1,deltsoc_last1]    #更新RAM信息
-                        else:
-                            dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
-                            time_now1=self.bmstime[i]
-                            if (time_now1-time_last1).total_seconds()>3600*20:
-                                deltsoc_now1, cellsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
-                                df_ram_last1.loc[0]=[self.sn,time_now1,deltsoc_now1] #更新RAM信息
-
-                                list_sub1=deltsoc_now1-deltsoc_last1
-                                list_pud1=(0.01*capacity*3600*1000)/(time_now1-time_last1).total_seconds()
-                                leak_current1=list_sub1*list_pud1
-                                # leak_current1=np.array(leak_current1)
-                                leak_current1=np.round(leak_current1,3)
-                                leak_current1=list(leak_current1)
-                                
-                                df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)]  #计算结果存入Dataframe
-                                time_last1=time_now1  #更新时间
-                                deltsoc_last1=deltsoc_now1    #更新soc差
-                                dict_bal1={}
+                    if not cellvolt_now1.empty:
+                        cellvolt_max1=max(cellvolt_now1)
+                        cellvolt_min1=min(cellvolt_now1)
+                        # cellvolt_last1=self._avgvolt_get(i-1)
+                        # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
+                        cellsoc_now1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
+
+                        if cellsoc_now1>=self.param.FullChrgSoc-10 and 2<cellvolt_min1<4.5 and 2<cellvolt_max1<4.5:
+                            if firsttime1==1:
+                                dict_baltime1={}   #获取每个电芯的均衡时间
+                                deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
+                                time_last1=self.bmstime[i]
+                                firsttime1=0
+                                df_ram_last1.loc[0]=[self.sn,time_last1,deltsoc_last1]    #更新RAM信息
                             else:
-                                pass
+                                dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
+                                time_now1=self.bmstime[i]
+                                if (time_now1-time_last1).total_seconds()>3600*20:
+                                    deltsoc_now1, cellsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
+                                    df_ram_last1.loc[0]=[self.sn,time_now1,deltsoc_now1] #更新RAM信息
+
+                                    list_sub1=deltsoc_now1-deltsoc_last1
+                                    list_pud1=(0.01*capacity*3600*1000)/(time_now1-time_last1).total_seconds()
+                                    leak_current1=list_sub1*list_pud1
+                                    # leak_current1=np.array(leak_current1)
+                                    leak_current1=np.round(leak_current1,3)
+                                    leak_current1=list(leak_current1)
+                                    
+                                    df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)]  #计算结果存入Dataframe
+                                    time_last1=time_now1  #更新时间
+                                    deltsoc_last1=deltsoc_now1    #更新soc差
+                                    dict_bal1={}
+                                else:
+                                    pass
                     else:
                         pass
                 else:   
@@ -522,55 +530,57 @@ class BatInterShort():
                     if standingtime>self.StandardStandingTime:      #静置时间满足要求
                         standingtime=0
                         cellvolt_now=self._avgvolt_get(i)
+                        if not cellvolt_now.empty:
+                            cellvolt_min=min(cellvolt_now)
+                            cellvolt_max=max(cellvolt_now)
+                            # cellvolt_last=self._avgvolt_get(i-1)
+                            # deltvolt=max(abs(cellvolt_now-cellvolt_last))
+                            cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
+                            cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
+
+                            if cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
+                                dict_baltime={}  #获取每个电芯的均衡时间
+                                deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
+                                time_last=self.bmstime[i]
+                                firsttime=0
+                                df_ram_last.loc[0]=[self.sn,time_last,deltsoc_last,cellsoc_last]   #更新RAM信息
+                            else:
+                                pass
+                    else:
+                        pass                
+                elif standingtime>3600*12:
+                    standingtime=0
+                    cellvolt_now=np.array(self._avgvolt_get(i))
+                    if not cellvolt_now.empty:
                         cellvolt_min=min(cellvolt_now)
                         cellvolt_max=max(cellvolt_now)
-                        # cellvolt_last=self._avgvolt_get(i-1)
+                        # cellvolt_last=np.array(self._avgvolt_get(i-1))
                         # deltvolt=max(abs(cellvolt_now-cellvolt_last))
                         cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
                         cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
 
-                        if (not cellvolt_now.empty)  and cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
-                            dict_baltime={}  #获取每个电芯的均衡时间
-                            deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
-                            time_last=self.bmstime[i]
-                            firsttime=0
-                            df_ram_last.loc[0]=[self.sn,time_last,deltsoc_last,cellsoc_last]   #更新RAM信息
+                        if cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
+                            dict_baltime=self._bal_time(dict_bal)   #获取每个电芯的均衡时间
+                            deltsoc_now, cellsoc_now=self._celldeltsoc_get(i, dict_baltime,capacity)    #获取每个电芯的SOC差
+                            time_now=self.bmstime[i]
+                            if -5<max(cellsoc_now-cellsoc_last)<5:
+                                df_ram_last.loc[0]=[self.sn,time_now,deltsoc_now,cellsoc_now]   #更新RAM信息
+
+                                list_sub=deltsoc_now-deltsoc_last
+                                list_pud=(0.01*capacity*3600*1000)/(time_now-time_last).total_seconds()
+                                leak_current=list_sub*list_pud
+                                # leak_current=np.array(leak_current)
+                                leak_current=np.round(leak_current,3)
+                                leak_current=list(leak_current)
+                                
+                                df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)]  #计算结果存入Dataframe
+                                time_last=time_now  #更新时间
+                                deltsoc_last=deltsoc_now    #更新soc差
+                                dict_bal={}
+                            else:
+                                firsttime=1
                         else:
                             pass
-                    else:
-                        pass                
-                elif standingtime>3600*12:
-                    standingtime=0
-                    cellvolt_now=np.array(self._avgvolt_get(i))
-                    cellvolt_min=min(cellvolt_now)
-                    cellvolt_max=max(cellvolt_now)
-                    # cellvolt_last=np.array(self._avgvolt_get(i-1))
-                    # deltvolt=max(abs(cellvolt_now-cellvolt_last))
-                    cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
-                    cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
-
-                    if (not cellvolt_now.empty)  and cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
-                        dict_baltime=self._bal_time(dict_bal)   #获取每个电芯的均衡时间
-                        deltsoc_now, cellsoc_now=self._celldeltsoc_get(i, dict_baltime,capacity)    #获取每个电芯的SOC差
-                        time_now=self.bmstime[i]
-                        if -5<max(cellsoc_now-cellsoc_last)<5:
-                            df_ram_last.loc[0]=[self.sn,time_now,deltsoc_now,cellsoc_now]   #更新RAM信息
-
-                            list_sub=deltsoc_now-deltsoc_last
-                            list_pud=(0.01*capacity*3600*1000)/(time_now-time_last).total_seconds()
-                            leak_current=list_sub*list_pud
-                            # leak_current=np.array(leak_current)
-                            leak_current=np.round(leak_current,3)
-                            leak_current=list(leak_current)
-                            
-                            df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)]  #计算结果存入Dataframe
-                            time_last=time_now  #更新时间
-                            deltsoc_last=deltsoc_now    #更新soc差
-                            dict_bal={}
-                        else:
-                            firsttime=1
-                    else:
-                        pass
                 else: 
                     try:  
                         balstat=int(self.df_bms.loc[i,'单体均衡状态'])
@@ -590,42 +600,43 @@ class BatInterShort():
                 if standingtime1>self.StandardStandingTime: 
                     standingtime1=0
                     cellvolt_now1=self._avgvolt_get(i)
-                    cellvolt_max1=max(cellvolt_now1)
-                    cellvolt_min1=min(cellvolt_now1)
-                    # cellvolt_last1=self._avgvolt_get(i-1)
-                    # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
-                    cellsoc_max1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
-                    cellsoc_min1=np.interp(cellvolt_min1,self.param.LookTab_OCV,self.param.LookTab_SOC)
-                
-                    if (not cellvolt_now1.empty)  and cellsoc_max1<self.param.SocInflexion1-2 and 12<cellsoc_min1:
-                        if firsttime1==1:
-                            dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
-                            deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
-                            time_last1=self.bmstime[i]
-                            firsttime1=0
-                            df_ram_last1.loc[0]=[self.sn,time_last1,deltsoc_last1]    #更新RAM信息
-                        else:
-                            dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
-                            deltsoc_now1, cellsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
-                            time_now1=self.bmstime[i]
-                            df_ram_last1.loc[0]=[self.sn,time_now1,deltsoc_now1]    #更新RAM信息
-
-                            if (time_now1-time_last1).total_seconds()>3600*24:
-                                list_sub1=deltsoc_now1-deltsoc_last1
-                                list_pud1=(0.01*capacity*3600*1000)/(time_now1-time_last1).total_seconds()
-                                leak_current1=list_sub1*list_pud1
-                                # leak_current1=np.array(leak_current1)
-                                leak_current1=np.round(leak_current1,3)
-                                leak_current1=list(leak_current1)
-                                
-                                df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)]  #计算结果存入Dataframe
-                                time_last1=time_now1  #更新时间
-                                deltsoc_last1=deltsoc_now1    #更新soc差
-                                dict_bal1={}
+                    if not cellvolt_now1.empty:
+                        cellvolt_max1=max(cellvolt_now1)
+                        cellvolt_min1=min(cellvolt_now1)
+                        # cellvolt_last1=self._avgvolt_get(i-1)
+                        # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
+                        cellsoc_max1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
+                        cellsoc_min1=np.interp(cellvolt_min1,self.param.LookTab_OCV,self.param.LookTab_SOC)
+                    
+                        if cellsoc_max1<self.param.SocInflexion1-2 and 12<cellsoc_min1:
+                            if firsttime1==1:
+                                dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
+                                deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
+                                time_last1=self.bmstime[i]
+                                firsttime1=0
+                                df_ram_last1.loc[0]=[self.sn,time_last1,deltsoc_last1]    #更新RAM信息
                             else:
-                                pass
-                    else:
-                        pass
+                                dict_baltime1=self._bal_time(dict_bal1)   #获取每个电芯的均衡时间
+                                deltsoc_now1, cellsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
+                                time_now1=self.bmstime[i]
+                                df_ram_last1.loc[0]=[self.sn,time_now1,deltsoc_now1]    #更新RAM信息
+
+                                if (time_now1-time_last1).total_seconds()>3600*24:
+                                    list_sub1=deltsoc_now1-deltsoc_last1
+                                    list_pud1=(0.01*capacity*3600*1000)/(time_now1-time_last1).total_seconds()
+                                    leak_current1=list_sub1*list_pud1
+                                    # leak_current1=np.array(leak_current1)
+                                    leak_current1=np.round(leak_current1,3)
+                                    leak_current1=list(leak_current1)
+                                    
+                                    df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)]  #计算结果存入Dataframe
+                                    time_last1=time_now1  #更新时间
+                                    deltsoc_last1=deltsoc_now1    #更新soc差
+                                    dict_bal1={}
+                                else:
+                                    pass
+                        else:
+                            pass
                 else:   
                     pass
 

+ 34 - 33
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSSafetyWarning.py

@@ -34,9 +34,11 @@ class SafetyWarning:
         time_sp='0000-00-00 00:00:00'
 
         #参数初始化.......................................
-        shortfault=0
+        voltsigmafault=0
         uniformfault=0
+        cellshortfault=0
         volt_rate=[]
+        R2_list=[]
 
         if not self.df_short.empty:
             short_current=self.df_short['short_current']
@@ -62,12 +64,16 @@ class SafetyWarning:
             for i in range(0,len(VoltChange)):
                 VoltChange.loc[i,'time']=(time.mktime(VoltChange.loc[i,'time'].timetuple())-time0)/36000
             
+        #计算漏电流离群度
+        if not self.df_short.empty:
+            self.df_short['cellshort_sigma']=0
+            for i in range(len(self.df_short)):
+                cellshort=eval(self.df_short.loc[i,'short_current'])
+                cellshort_std=np.std(cellshort)
+                cellshort_mean=np.mean(cellshort)
+                self.df_short.loc[i,'cellshort_sigma']=str(list((cellshort-cellshort_mean)/cellshort_std))
+            
     
-        # if not self.df_liplated.empty:
-        #     liplated=self.df_liplated['liplated_amount']
-        #     liplated=liplated.str.replace("[", '')
-        #     liplated=liplated.str.replace("]", '')
-        
         if not self.df_uniform.empty:
             cellvolt_rank=self.df_uniform['cellvolt_rank']
             cellvolt_rank=cellvolt_rank.str.replace("[", '')
@@ -75,58 +81,53 @@ class SafetyWarning:
 
         # plt.figure()
         for i in range(self.param.CellVoltNums):
-
             #漏电流故障判断...........................................................................
             if not self.df_short.empty:
                 self.df_short['cellshort'+str(i+1)]=short_current.map(lambda x:eval(x.split(',')[i]))
-
                 cellshort=self.df_short['cellshort'+str(i+1)]
                 index_list=cellshort[cellshort<self.param.LeakCurrentLv2].index
                 if len(index_list)>1:
                     for j in range(1,len(index_list)):
                         if index_list[j]-index_list[j-1]==1:
-                            shortfault=1
-                            break
+                            cellshort_sigma1=eval(self.df_short.loc[index_list[j],'cellshort_sigma'])
+                            cellshort_sigma2=eval(self.df_short.loc[index_list[j-1],'cellshort_sigma'])
+                            if cellshort_sigma1[i]<-3 or cellshort_sigma2[i]<-3:
+                                cellshortfault=1                       
                         else:
-                            shortfault=0
+                            pass
                 else:
-                    shortfault=0
+                    pass
             
             #电压变化率及电压离群度.................................................................................
             if not self.OutLineVol_Rate.empty and VoltChange.iloc[-1]['time']*36000>18*3600 and len(VoltChange)>5:
 
                 volt3sigma=np.array(Volt_3Sigma[volt_column[i]].map(lambda x:eval(x)))
                 volt3sigma_sum=np.sum(volt3sigma<-3)
-
                 #电压变化率
                 VoltChange[volt_column[i]]=VoltChange[volt_column[i]].map(lambda x:eval(x))
-                a1,b1=np.polyfit(VoltChange['time'].tolist(),VoltChange[volt_column[i]].tolist(),1)
-                y=a1*VoltChange['time']+b1
+                y=VoltChange[volt_column[i]]
+                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)
-                # plt.plot(xtime1,y,label=a1)
+                # plt.plot(xtime1,y1,label=a1)
                 # plt.scatter( xtime1,VoltChange[volt_column[i]],marker='o')
                 # plt.legend(loc='best')
-                # # plt.title(str(a1))
+                # plt.title('单体电压'+str(i+1))
                 # plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
                 # plt.rcParams['axes.unicode_minus']=False #用来正常显示负号  
+                # plt.show()
                 
                 if volt3sigma_sum>len(self.OutLineVol_Rate)/2:
                     voltsigmafault=1
                 else:
                     voltsigmafault=0
             else:
-                voltsigmafault=0
-            
-            #析锂故障判断...............................................................................
-            # if not self.df_liplated.empty:
-            #     self.df_liplated['liplated_amount'+str(i+1)]=liplated.map(lambda x:eval(x.split(',')[i]))
-
-            #     if max(self.df_liplated['liplated_amount'+str(i+1)])>30:
-            #         liplatedfault=1
-            #     else:
-            #         liplatedfault=0
-            # else:
-            #     liplatedfault=0
+                volt_rate.append(0)
+                R2_list.append(0)
 
             #电芯SOC排名判断.............................................................................
             if not self.df_uniform.empty:
@@ -139,15 +140,15 @@ class SafetyWarning:
             else:
                 uniformfault=0
             
-            #电池内短路热失控预警...............................................................................
-            if shortfault==1 and (voltsigmafault==1 or uniformfault==1):
+            #漏电流热失控预警确认........................................................
+            if cellshortfault==1 and (uniformfault==1 or voltsigmafault==1):
                 faultcode=110
                 faultlv=4
                 faultinfo='电芯{}发生热失控安全预警'.format(i+1)
                 faultadvice='1联系用户远离电池,立刻召回电池'
                 df_res.loc[0]=[time_now, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
             else:
-                pass
+                pass       
         
         #电池电压变化率热失控预警...............................................................................
         volt_rate_std=np.std(volt_rate)
@@ -161,7 +162,7 @@ class SafetyWarning:
         else:
             cellsoh_3sigma=[0]*self.param.CellVoltNums
         for i in range(len(volt_rate)):
-            if volt_rate[i]<self.param.TrwVoltRate and volt_rate_3sigma[i]<-3 and abs(cellsoh_3sigma[i])<3:
+            if volt_rate[i]<self.param.TrwVoltRate and volt_rate_3sigma[i]<-3 and abs(cellsoh_3sigma[i])<2.5:
                 faultcode=110
                 faultlv=4
                 faultinfo='电芯{}发生热失控安全预警'.format(i+1)

+ 4 - 4
LIB/MIDDLE/CellStateEstimation/Common/V1_0_1/BatParam.py

@@ -76,7 +76,7 @@ class BatParam:
             self.CellTempDiffLv1=10
             self.CellTempDiffLv2=15
 
-            self.TrwVoltRate=-0.5
+            self.TrwVoltRate=-1
         elif celltype==2: #4840
             self.Capacity = 41
             self.PackFullChrgVolt=69.99
@@ -115,7 +115,7 @@ class BatParam:
             self.CellTempDiffLv1=10
             self.CellTempDiffLv2=15
 
-            self.TrwVoltRate=-0.5
+            self.TrwVoltRate=-1
         elif celltype==3:   #力信50ah三元电芯
             self.Capacity = 51
             self.PackFullChrgVolt=80
@@ -154,7 +154,7 @@ class BatParam:
             self.CellTempDiffLv1=10
             self.CellTempDiffLv2=15  
 
-            self.TrwVoltRate=-0.5          
+            self.TrwVoltRate=-1         
         elif celltype==4:   #CATL 50ah三元电芯
             self.Capacity = 50
             self.PackFullChrgVolt=80
@@ -194,7 +194,7 @@ class BatParam:
             self.CellTempDiffLv1=10
             self.CellTempDiffLv2=15   
 
-            self.TrwVoltRate=-0.5         
+            self.TrwVoltRate=-1        
         elif celltype==99:   #60ah磷酸铁锂电芯
             self.Capacity = 54
             self.PackFullChrgVolt=69.99