Browse Source

1.表单丰富,2.SOH结果滤波优化

qingfeng 3 years ago
parent
commit
abf2aadb6b

+ 1 - 1
LIB/MIDDLE/CellStateEstimation/InterShort/V1_0_0/CBMSBatInterShort.py

@@ -40,7 +40,7 @@ class BatInterShort:
     def getdata(self):  
         DBManager=DBDownload.DBDownload(self.host, self.port, self.db, self.user, self.password)
         with DBManager as DBManager:
-            self.df_soh=DBManager.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename='soh_result', sn=self.sn)
+            self.df_soh=DBManager.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename='cellstateestimation_soh', sn=self.sn)
 
     #定义滑动滤波函数....................................................................................
     def _np_move_avg(self,a, n, mode="same"): 

BIN
LIB/MIDDLE/CellStateEstimation/InterShort/V1_0_0/InterShort表单.xlsx


+ 41 - 52
LIB/MIDDLE/CellStateEstimation/SOH/V1_0_0/CBMSBatSoh.py

@@ -46,7 +46,7 @@ class BatSoh:
     def getdata(self):  
         DBManager=DBDownload.DBDownload(self.host, self.port, self.db, self.user, self.password)
         with DBManager as DBManager:
-            self.df_soh=DBManager.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename='soh_result', sn=self.sn)
+            self.df_soh=DBManager.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename='cellstateestimation_soh', sn=self.sn)
     
     #定义滑动滤波函数.........................................................................................................................
     def _np_move_avg(self,a, n, mode="same"):
@@ -165,7 +165,7 @@ class BatSoh:
         end_time=df_Data1.loc[len(time2)-1,'time']
         end_time=end_time-datetime.timedelta(seconds=1200)
         if soc2[0]<36:
-            df_Data1=df_Data1[(df_Data1['SOC']>39.5) & (df_Data1['SOC']<80)]
+            df_Data1=df_Data1[(df_Data1['SOC']>40) & (df_Data1['SOC']<80)]
         else:
             df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['SOC']<80)]
         df_Data1=df_Data1[(df_Data1['XVOLT']>self.param.PeakVoltLowLmt) & (df_Data1['XVOLT']<self.param.PeakVoltUpLmt)]
@@ -600,7 +600,7 @@ class BatSoh:
         #开始计算SOH.............................................................................................................................................
         if standingpoint_sp or chrg_end:       
             self.getdata()  #获取已计算的soh
-            column_name=['time_st','time_sp','sn','method','soh','cellsoh']
+            column_name=['time_st','time_sp','sn','method','soh','cellsoh','weight']
             df_res=pd.DataFrame(columns=column_name)
         
             #两点法计算SOH........................................................................................................................................
@@ -670,32 +670,10 @@ class BatSoh:
                     cellsoh_init=ah_accum*100/((ocv_soc2-ocv_soc1)*0.01*self.param.Capacity)
 
                     if cellsoh_init>60 and cellsoh_init<115:    #判断soh值的有效区间
-                        if len(df_res)<1:
-                            if not self.df_soh.empty and 60<self.df_soh.loc[len(self.df_soh)-1,'soh']<115:
-                                cellsoh_last=self.df_soh.loc[len(self.df_soh)-1,'soh']
-                                if soh_weight>1/abs(cellsoh_init-cellsoh_last):
-                                    soh_weight=1/abs(cellsoh_init-cellsoh_last)
-                                    cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                                else:
-                                    cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                            else:
-                                cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
-                        else:
-                            cellsoh_last=df_res.loc[len(df_res)-1,'soh']
-                            if soh_weight>1/abs(cellsoh_init-cellsoh_last):
-                                soh_weight=1/abs(cellsoh_init-cellsoh_last)
-                                cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                            else:
-                                cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                        
-                        if 60<cellsoh_cal<115:
-                            cellsoh_cal=eval(format(cellsoh_cal,'.1f'))
-                            soh_list=[timepoint_bms_st, timepoint_bms_sp, self.sn, 1, cellsoh_cal, str(cellsoh_cal)]
-                            df_res.loc[len(df_res)]=soh_list
-                        else:
-                            pass
+                        soh_list=[timepoint_bms_st, timepoint_bms_sp, self.sn, 1, cellsoh_init, cellsoh_init,soh_weight]
+                        df_res.loc[len(df_res)]=soh_list
                     else:
-                        continue
+                        pass
             else:
                 pass
 
@@ -709,39 +687,50 @@ class BatSoh:
 
                     soh_weight=tempweightlist2[i]*0.25
                     if cellsoh_init>60 and cellsoh_init<115:    #判断soh值的有效区间
-                        if len(df_res)<1:
-                            if not self.df_soh.empty and 60<self.df_soh.loc[len(self.df_soh)-1,'soh']<115:
-                                cellsoh_last=self.df_soh.loc[len(self.df_soh)-1,'soh']
-                                if soh_weight>1/abs(cellsoh_init-cellsoh_last):
-                                    soh_weight=1/abs(cellsoh_init-cellsoh_last)
-                                    cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                                else:
-                                    cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                            else:
-                                cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
-                        else:
-                            cellsoh_last=df_res.loc[len(df_res)-1,'soh']
+                        soh_list=[self.bmstime[chrg_start[i]], self.bmstime[chrg_end[i]], self.sn, 2, cellsoh_init, str(cellsoh_init),soh_weight]
+                        df_res.loc[len(df_res)]=soh_list
+                    else:
+                        pass
+            
+            #对SOH结果进行滤波处理................................................................................................................................
+            if df_res.empty:
+                return pd.DataFrame()
+            else:
+                df_res=df_res.sort_values(by='time_st',ascending=True)
+                df_res.index=range(len(df_res))
+                for i in range(len(df_res)):
+                    cellsoh_init=df_res.loc[i,'soh']
+                    soh_weight=df_res.loc[i,'weight']
+                    if i<1:
+                        if not self.df_soh.empty and 60<self.df_soh.loc[len(self.df_soh)-1,'soh']<115:
+                            cellsoh_last=self.df_soh.loc[len(self.df_soh)-1,'soh']
                             if soh_weight>1/abs(cellsoh_init-cellsoh_last):
                                 soh_weight=1/abs(cellsoh_init-cellsoh_last)
                                 cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
                             else:
                                 cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
-                        
+                        else:
+                            cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
                         if 60<cellsoh_cal<115:
-                            cellsoh_cal=eval(format(cellsoh_cal,'.1f'))
-                            soh_list=[self.bmstime[chrg_start[i]], self.bmstime[chrg_end[i]], self.sn, 2, cellsoh_cal, str(cellsoh_cal)]
-                            df_res.loc[len(df_res)]=soh_list
+                            df_res.loc[i,'soh']=cellsoh_cal
+                            df_res.loc[i,'cellsoh']=str(cellsoh_cal)
                         else:
-                            pass
+                            df_res=df_res.drop(i,axis=0)
                     else:
-                        continue
-            else:
-                pass
-
-            if df_res.empty:
-                return pd.DataFrame()
-            else:
+                        cellsoh_last=df_res.loc[i-1,'soh']
+                        if soh_weight>1/abs(cellsoh_init-cellsoh_last):
+                            soh_weight=1/abs(cellsoh_init-cellsoh_last)
+                            cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
+                        else:
+                            cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
+                        if 60<cellsoh_cal<115:
+                            df_res.loc[i,'soh']=cellsoh_cal
+                            df_res.loc[i,'cellsoh']=str(cellsoh_cal)
+                        else:
+                            df_res=df_res.drop(i,axis=0)
+                df_res=df_res.drop('weight',axis=1)
                 return df_res
+
         return pd.DataFrame()
 
 

BIN
LIB/MIDDLE/CellStateEstimation/SOH/V1_0_0/SOH表单.xlsx


+ 5 - 5
LIB/MIDDLE/CellStateEstimation/Uniform/V1_0_0/CBMSBatUniform.py

@@ -118,7 +118,7 @@ class BatUniform:
         end_time=df_Data1.loc[len(time1)-1,'time']
         end_time=end_time-datetime.timedelta(seconds=1200)
         if soc2[0]<36:
-            df_Data1=df_Data1[(df_Data1['SOC']>39.5) & (df_Data1['SOC']<80)]
+            df_Data1=df_Data1[(df_Data1['SOC']>40) & (df_Data1['SOC']<80)]
         else:
             df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['SOC']<80)]
         df_Data1=df_Data1[(df_Data1['XVOLT']>self.param.PeakVoltLowLmt) & (df_Data1['XVOLT']<self.param.PeakVoltUpLmt)]
@@ -139,18 +139,18 @@ class BatUniform:
         # plt.xlabel('SOC/%')
         # plt.ylabel('DV/DQ')
         # plt.legend()
-        # # plt.show()
+        # plt.show()
 
         if len(df_Data1)>2:     #寻找峰值点,且峰值点个数>2
             PeakIndex = df_Data1['DVDQ'].idxmax()
             df_Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
-            if len(df_Data2) > 1 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.015:
+            if len(df_Data2) > 2 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.019:
                 return df_Data1['AhSoc'][PeakIndex]
             else:
                 df_Data1 = df_Data1.drop([PeakIndex])
                 PeakIndex = df_Data1['DVDQ'].idxmax()
                 df_Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
-                if len(df_Data2) > 1 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.015:
+                if len(df_Data2) > 2 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.019:
                     return df_Data1['AhSoc'][PeakIndex]
                 else:
                     return 0
@@ -359,7 +359,7 @@ class BatUniform:
                         df_res.loc[len(df_res)]=[self.bmstime[chrg_start[i]], self.sn, cellsoc_diff, 0, peaksoc_minnum, peaksoc_maxnum]
                     else:
                         pass
-                    # plt.show()
+                    plt.show()
                 else:
                     pass
 

BIN
LIB/MIDDLE/CellStateEstimation/Uniform/V1_0_0/Uniform表单.xlsx