Przeglądaj źródła

更新热失控预警代码,1.更改预警结束策略;2.修复预警bug

qingfeng 3 lat temu
rodzic
commit
0846c4d797

+ 36 - 28
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSBatInterShort.py

@@ -202,8 +202,7 @@ class BatInterShort():
 
     #三元电池的内短路电流计算...........................................................................................................................................................
     def _ncm_intershort(self):
-        column_name=['time_st', 'time_sp', 'sn', 'method','short_current','baltime']
-        df_res=pd.DataFrame(columns=column_name)
+        df_res=pd.DataFrame(columns=['time_st', 'time_sp', 'sn', 'method','short_current','baltime'])
         df_ram_last=self.df_last
         df_ram_last1=self.df_last1
         df_ram_last3=self.df_last3
@@ -217,31 +216,35 @@ class BatInterShort():
             capacity=self.param.Capacity*batsoh/100
 
         #参数初始化
-        if self.df_last.empty:  
+        if df_ram_last.empty:  
             firsttime=1
             dict_bal={}
         else:
-            deltsoc_last=self.df_last.loc[0,'deltsoc']
-            cellsoc_last=self.df_last.loc[0,'cellsoc']
-            time_last=self.df_last.loc[0,'time']
+            deltsoc_last=df_ram_last.loc[0,'deltsoc']
+            cellsoc_last=df_ram_last.loc[0,'cellsoc']
+            time_last=df_ram_last.loc[0,'time']
             firsttime=0
             dict_bal={}
-        if self.df_last1.empty:
+        if df_ram_last1.empty:
             firsttime1=1
             dict_bal1={}
         else:
-            deltsoc_last1=self.df_last1.loc[0,'deltsoc1']
-            time_last1=self.df_last1.loc[0,'time1']
+            deltsoc_last1=df_ram_last1.loc[0,'deltsoc1']
+            time_last1=df_ram_last1.loc[0,'time1']
             firsttime1=0
             dict_bal1={}
-        if self.df_last3.empty:
+        if df_ram_last3.empty:
             standingtime=0
             standingtime1=0
         else:
-            standingtime=self.df_last3.loc[0,'standingtime']
-            standingtime1=self.df_last3.loc[0,'standingtime1']
-            firsttime1=0
+            standingtime=df_ram_last3.loc[0,'standingtime']
+            standingtime1=df_ram_last3.loc[0,'standingtime1']
             dict_bal1={}
+            if abs(self.packcrnt[0])<0.01 and standingtime>1 and standingtime1>1:
+                standingtime=standingtime+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
+                standingtime1=standingtime1+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
+            else:
+                pass
 
         for i in range(1,len(self.df_bms)-1):
 
@@ -380,7 +383,7 @@ class BatInterShort():
                 pass
         
         #更新RAM的standingtime
-        df_ram_last3.loc[0]=[self.sn,standingtime,standingtime1]
+        df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1]
 
         #返回计算结果
         if df_res.empty:    
@@ -406,40 +409,45 @@ class BatInterShort():
             batsoh=self.df_soh.loc[len(self.df_soh)-1,'soh']
             capacity=self.param.Capacity*batsoh/100
         #参数初始化
-        if self.df_last.empty:  
+        if df_ram_last.empty:  
             firsttime=1
             dict_bal={}
         else:
-            deltsoc_last=self.df_last.loc[0,'deltsoc']
-            cellsoc_last=self.df_last.loc[0,'cellsoc']
-            time_last=self.df_last.loc[0,'time']
+            deltsoc_last=df_ram_last.loc[0,'deltsoc']
+            cellsoc_last=df_ram_last.loc[0,'cellsoc']
+            time_last=df_ram_last.loc[0,'time']
             firsttime=0
             dict_bal={}
-        if self.df_last1.empty:
+        if df_ram_last1.empty:
             firsttime1=1
             dict_bal1={}
         else:
-            deltsoc_last1=self.df_last1.loc[0,'deltsoc1']
-            time_last1=self.df_last1.loc[0,'time1']
+            deltsoc_last1=df_ram_last1.loc[0,'deltsoc1']
+            time_last1=df_ram_last1.loc[0,'time1']
             firsttime1=0
             dict_bal1={}
-        if self.df_last2.empty:
+        if df_ram_last2.empty:
             firsttime2=1
             charging=0
             dict_bal2={}
         else:
-            deltAs_last2=self.df_last2.loc[0,'deltAs2']
-            time_last2=self.df_last2.loc[0,'time2']
+            deltAs_last2=df_ram_last2.loc[0,'deltAs2']
+            time_last2=df_ram_last2.loc[0,'time2']
             firsttime2=0
             charging=0
             dict_bal2={}
-        if self.df_last3.empty:
+        if df_ram_last3.empty:
             standingtime=0
             standingtime1=0
         else:
-            standingtime=self.df_last3.loc[0,'standingtime']
-            standingtime1=self.df_last3.loc[0,'standingtime1']
+            standingtime=df_ram_last3.loc[0,'standingtime']
+            standingtime1=df_ram_last3.loc[0,'standingtime1']
             dict_bal1={}
+            if abs(self.packcrnt[0])<0.01 and standingtime>1 and standingtime1>1:
+                standingtime=standingtime+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
+                standingtime1=standingtime1+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
+            else:
+                pass
 
         for i in range(1,len(self.df_bms)-1):
 
@@ -657,7 +665,7 @@ class BatInterShort():
 
     
         #更新RAM
-        df_ram_last3.loc[0]=[self.sn,standingtime,standingtime1]
+        df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1]
 
         #返回结果
         if df_res.empty:    

+ 11 - 18
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSSafetyWarning.py

@@ -4,7 +4,7 @@ import datetime
 from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
 
 class SafetyWarning:
-    def __init__(self,sn,celltype,df_short,df_liplated,df_uniform,df_diag_ram):  #参数初始化
+    def __init__(self,sn,celltype,df_short,df_liplated,df_uniform):  #参数初始化
 
         self.sn=sn
         self.celltype=celltype
@@ -12,8 +12,6 @@ class SafetyWarning:
         self.df_short=df_short
         self.df_liplated=df_liplated
         self.df_uniform=df_uniform
-        self.df_diag_ram=df_diag_ram
-
     
     def diag(self):
         if self.celltype<=50:
@@ -47,10 +45,10 @@ class SafetyWarning:
                 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
+                index_list=cellshort[cellshort<self.param.LeakCurrentLv2].index
                 if len(index_list)==2 and (index_list[1]-index_list[0])==1:
                     shortfault=1
-                elif len(index_list)>2:
+                elif len(index_list)>3:
                     shortfault=1
                 else:
                     shortfault=0
@@ -79,18 +77,13 @@ class SafetyWarning:
                 uniformfault=0
             
             #电池热安全预警
-            if not 110 in list(self.df_diag_ram['code']):  #当前故障中没有该故障,则判断是否发生该故障
-                if shortfault==1 and (liplatedfault==1 or uniformfault==1):
-                    faultcode=110
-                    faultlv=4
-                    faultinfo='电芯{}热失控安全预警'.format(i+1)
-                    faultadvice='联系用户远离电池,立刻召回电池'
-                    self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
-                else:
-                    pass
+            if shortfault==1 and (liplatedfault==1 or uniformfault==1):
+                faultcode=110
+                faultlv=4
+                faultinfo='电芯{}发生热失控安全预警'.format(i+1)
+                faultadvice='联系用户远离电池,立刻召回电池'
+                df_res.loc[0]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
             else:
-                if shortfault==0 and liplatedfault==0:
-                    time=self.bmstime[i]
-                    self.df_diag_ram[self.df_diag_ram[self.df_diag_ram['faultcode']==110].index, 'time_sp'] = time
+                pass
             
-        return self.df_diag_ram
+        return df_res

+ 24 - 15
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/main.py

@@ -16,7 +16,8 @@ def saftywarning_cal():
     global df_warning_ram2
     global df_warning_ram3
     global df_lfp_ram
-    
+    global now_time
+
     now_time=datetime.datetime.now()
     start_time=now_time-datetime.timedelta(hours=12)
     start_time1=now_time-datetime.timedelta(days=7)
@@ -125,24 +126,29 @@ def saftywarning_cal():
         DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
         with DBRead as DBRead:
             df_short=DBRead.getdata('time_sp,sn,short_current', tablename=tablename1, sn=sn, timename='time_sp', st=start_time1, sp=end_time)
-            df_liplated=DBRead.getdata('time,sn,liplated,lipltd_amount', tablename=tablename2, sn=sn, timename='time_sp', st=start_time2, sp=end_time)
+            df_liplated=DBRead.getdata('time,sn,liplated,liplated_amount', tablename=tablename2, sn=sn, timename='time', st=start_time2, sp=end_time)
             df_uniform=DBRead.getdata('time,sn,cellsoc_diff,cellmin_num', tablename=tablename3, sn=sn, timename='time', st=start_time1, sp=end_time)
         
         #获取sn的故障RAM
         df_fault_ram_sn=df_fault_ram[df_fault_ram['product_id']==sn]
         
         #热安全预警
-        BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform,df_fault_ram_sn)
-        df_warning_res=BatWarning.diag()
-
-        df_warning_end=df_warning_res[df_warning_res['end_time'] != '0000-00-00 00:00:00']
-        if not df_warning_end.empty:    #df_warning_end历史故障筛选并更改数据库故障结束时间
-            pass   
-        elif df_fault_ram_sn.empty and (not df_warning_res.empty):
-            with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a') as file:
-                file.write(str(tuple(df_warning_res.iloc[-1]))+'\n')
+        if df_fault_ram_sn.empty:
+            BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform)
+            df_warning_res=BatWarning.diag()
+            #当前热失控故障写入数据库
+            if not df_warning_res.empty:
+                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a') as file:
+                    file.write(str(tuple(df_warning_res.iloc[-1]))+'\n')
+        
         else:
-            pass
+            fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
+            if (now_time-fault_time).total_seconds()>24*3600:   #df_warning_end历史故障筛选并更改数据库故障结束时间
+                df_fault_ram_sn['end_time']=end_time
+                df_fault_ram_sn['Batpos']=1
+                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a') as file:
+                    file.write(str(tuple(df_warning_res.iloc[-1]))+'\n')
+
 
 #...............................................主函数起定时作用.......................................................................................................................
 if __name__ == "__main__":
@@ -161,7 +167,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=['MGMCLN750N215N099','PK504B10100004425']
+    SNnums=['MGMCLN750N215N155']
     
     mylog=log.Mylog('log_warning.txt','error')
     mylog.logcfg()
@@ -170,12 +176,15 @@ if __name__ == "__main__":
     df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
     df_warning_ram1=pd.DataFrame(columns=['sn','time1','deltsoc1'])
     df_warning_ram2=pd.DataFrame(columns=['sn','time2','deltAs2'])
-    df_warning_ram3=pd.DataFrame(columns=['sn','standingtime','standingtime1'])
+    df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1'])
     df_lfp_ram=pd.DataFrame()
 
+    now_time='2021-10-15 00:00:00'
+    now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
+
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()
-    scheduler.add_job(saftywarning_cal, 'interval', seconds=5)
+    scheduler.add_job(saftywarning_cal, 'interval', hours=12)
 
     try:  
         scheduler.start()

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

@@ -72,9 +72,9 @@ class BatParam:
             self.PackChgOc=-40
             self.PackDisOc=200
 
-            self.LeakCurrentLv1=10
-            self.LeakCurrentLv2=20
-            self.LeakCurrentLv3=50
+            self.LeakCurrentLv1=-10
+            self.LeakCurrentLv2=-20
+            self.LeakCurrentLv3=-50
 
         elif celltype==2: #4840
             self.Capacity = 41
@@ -104,9 +104,9 @@ class BatParam:
             self.PackChgOc=-40
             self.PackDisOc=200
 
-            self.LeakCurrentLv1=10
-            self.LeakCurrentLv2=20
-            self.LeakCurrentLv3=50
+            self.LeakCurrentLv1=-10
+            self.LeakCurrentLv2=-20
+            self.LeakCurrentLv3=-50
 
         elif celltype==3:   #力信50ah三元电芯
             self.Capacity = 51
@@ -136,9 +136,9 @@ class BatParam:
             self.PackChgOc=-40
             self.PackDisOc=200
 
-            self.LeakCurrentLv1=10
-            self.LeakCurrentLv2=20
-            self.LeakCurrentLv3=50
+            self.LeakCurrentLv1=-10
+            self.LeakCurrentLv2=-20
+            self.LeakCurrentLv3=-50
 
         elif celltype==4:   #CATL 50ah三元电芯
             self.Capacity = 50
@@ -169,9 +169,9 @@ class BatParam:
             self.PackChgOc=-40
             self.PackDisOc=200
 
-            self.LeakCurrentLv1=10
-            self.LeakCurrentLv2=20
-            self.LeakCurrentLv3=50
+            self.LeakCurrentLv1=-10
+            self.LeakCurrentLv2=-20
+            self.LeakCurrentLv3=-50
 
         elif celltype==99:   #60ah磷酸铁锂电芯
             self.Capacity = 54
@@ -212,9 +212,9 @@ class BatParam:
             self.PackChgOc=-40
             self.PackDisOc=200
 
-            self.LeakCurrentLv1=20
-            self.LeakCurrentLv2=50
-            self.LeakCurrentLv3=100
+            self.LeakCurrentLv1=-20
+            self.LeakCurrentLv2=-50
+            self.LeakCurrentLv3=-100
         else:
             print('未找到对应电池编号!!!')
             # sys.exit()