Browse Source

更新电池类别辨识至main中

qingfeng 3 years ago
parent
commit
082ef60db5

+ 18 - 20
LIB/MIDDLE/CellStateEstimation/SOH/V1_0_0/BatParam.py

@@ -1,29 +1,27 @@
 
 #定义电池参数
-
 from types import CellType
 import sys
 
-
 class BatParam:
 
-    def __init__(self,sn):
+    def __init__(self,celltype):
 
-        if 'PK500' in sn:
-            self.celltype=1 #6040三元电芯
-        elif 'PK502' in sn:
-            self.celltype=2 #4840三元电芯
-        elif 'PK504' in sn:
-            self.celltype=99    #60ah林磷酸铁锂电芯
-        elif 'MGMLXN750' in sn:
-            self.celltype=3 #力信50ah三元电芯
-        elif 'MGMCLN750' in sn: 
-            self.celltype=4 #CATL 50ah三元电芯
-        else:
-            print('未找到对应电池编号!!!')
-            sys.exit()
+        # if 'PK500' in sn:
+        #     self.celltype=1 #6040三元电芯
+        # elif 'PK502' in sn:
+        #     self.celltype=2 #4840三元电芯
+        # elif 'PK504' in sn:
+        #     self.celltype=99    #60ah林磷酸铁锂电芯
+        # elif 'MGMLXN750' in sn:
+        #     self.celltype=3 #力信50ah三元电芯
+        # elif 'MGMCLN750' in sn: 
+        #     self.celltype=4 #CATL 50ah三元电芯
+        # else:
+        #     print('未找到对应电池编号!!!')
+        #     sys.exit()
 
-        if self.celltype==1: #6040
+        if celltype==1: #6040
             self.Capacity = 41
             self.PackFullChrgVolt=69.99
             self.CellFullChrgVolt=4.2
@@ -34,7 +32,7 @@ class BatParam:
             self.LookTab_SOC = [0,	    3.5348,	8.3581,	13.181,	18.004,	22.827,	27.651,	32.474,	37.297,	42.120,	46.944,	51.767,	56.590,	61.413,	66.237,	71.060,	75.883,	80.707,	85.530,	90.353,	95.176,	100]
             self.LookTab_OCV = [3.3159,	3.4384,	3.4774,	3.5156,	3.5478,	3.5748,	3.6058,	3.6238,	3.638,	3.6535,	3.6715,	3.6951,	3.7279,	3.7757,	3.8126,	3.8529,	3.8969,	3.9446,	3.9946,	4.0491,	4.109,	4.183]
         
-        elif self.celltype==2: #4840
+        elif celltype==2: #4840
             self.Capacity = 41
             self.PackFullChrgVolt=69.99
             self.CellFullChrgVolt=4.2
@@ -45,7 +43,7 @@ class BatParam:
             self.LookTab_SOC = [0,	    3.5348,	8.3581,	13.181,	18.004,	22.827,	27.651,	32.474,	37.297,	42.120,	46.944,	51.767,	56.590,	61.413,	66.237,	71.060,	75.883,	80.707,	85.530,	90.353,	95.176,	100]
             self.LookTab_OCV = [3.3159,	3.4384,	3.4774,	3.5156,	3.5478,	3.5748,	3.6058,	3.6238,	3.638,	3.6535,	3.6715,	3.6951,	3.7279,	3.7757,	3.8126,	3.8529,	3.8969,	3.9446,	3.9946,	4.0491,	4.109,	4.183]
        
-        elif self.celltype==99:   #60ah磷酸铁锂电芯
+        elif celltype==99:   #60ah磷酸铁锂电芯
             self.Capacity = 54
             self.PackFullChrgVolt=69.99
             self.CellFullChrgVolt=3.5
@@ -60,7 +58,7 @@ class BatParam:
             self.LookTab_SOC = [0.00, 	2.40, 	6.38, 	10.37, 	14.35, 	18.33, 	22.32, 	26.30, 	30.28, 	35.26, 	40.24, 	45.22, 	50.20, 	54.19, 	58.17, 	60.16, 	65.14, 	70.12, 	75.10, 	80.08, 	84.06, 	88.05, 	92.03, 	96.02, 	100.00]
             self.LookTab_OCV = [2.7151,	3.0298,	3.1935,	3.2009,	3.2167,	3.2393,	3.2561,	3.2703,	3.2843,	3.2871,	3.2874,	3.2868,	3.2896,	3.2917,	3.2967,	3.3128,	3.3283,	3.3286,	3.3287,	3.3288,	3.3289,	3.3296,	3.3302,	3.3314,	3.3429]
         
-        elif self.celltype==3:
+        elif celltype==3:
             self.Capacity = 51
             self.PackFullChrgVolt=80
             self.CellFullChrgVolt=4.2

+ 21 - 20
LIB/MIDDLE/CellStateEstimation/SOH/V1_0_0/CBMSBatSoh.py

@@ -7,10 +7,11 @@ import BatParam
 import DBDownload
 
 class BatSoh:
-    def __init__(self,sn,df_bms,df_accum, host, port, db, user, password, tablename):  #参数初始化
+    def __init__(self,sn,celltype,df_bms,df_accum, host, port, db, user, password, tablename):  #参数初始化
 
         self.sn=sn
-        self.param=BatParam.BatParam(sn)
+        self.celltype=celltype
+        self.param=BatParam.BatParam(celltype)
         self.df_bms=df_bms
         self.packcrnt=df_bms['总电流[A]']
         self.packvolt=df_bms['总电压[V]']
@@ -30,11 +31,11 @@ class BatSoh:
         self.tablename=tablename
 
     def batsoh(self):
-        if self.param.celltype==1 or self.param.celltype==2:
+        if self.celltype==1 or self.celltype==2:
             df_res=self._ncmsoh_twopoint()
             return df_res
             
-        elif self.param.celltype==99:
+        elif self.celltype==99:
             df_res=self._lfpsoh()
             return df_res
 
@@ -67,7 +68,7 @@ class BatSoh:
             s = str(j)
             celltemp.append(self.df_bms.loc[num,'单体温度' + s])
         celltemp.remove(min(celltemp))
-        if self.param.celltype==99:
+        if self.celltype==99:
             if min(celltemp)>=20:
                 self.tempweight=1
                 self.StandardStandingTime=1800
@@ -75,10 +76,10 @@ class BatSoh:
                 self.tempweight=0.6
                 self.StandardStandingTime=3600
             elif min(celltemp)>=5:
-                self.tempweight=0.
+                self.tempweight=0.1
                 self.StandardStandingTime=7200
             else:
-                self.tempweight=0.1
+                self.tempweight=0
                 self.StandardStandingTime=10800
         else:
             if min(celltemp)>=20:
@@ -88,10 +89,10 @@ class BatSoh:
                 self.tempweight=0.8
                 self.StandardStandingTime=1200
             elif min(celltemp)>=5:
-                self.tempweight=0.6
+                self.tempweight=0.3
                 self.StandardStandingTime=1800
             else:
-                self.tempweight=0.2
+                self.tempweight=0.1
                 self.StandardStandingTime=3600
 
     def _deltsoc_weight(self,deltsoc):   #获取SOC差对应的SOH权重值
@@ -279,7 +280,7 @@ class BatSoh:
                 if delt_days<=1: #两次时间间隔对计算结果的影响
                     soh_weight1=1
                 elif delt_days<=2:
-                    soh_weight1=0.9
+                    soh_weight1=0.7
                 elif delt_days<=3:
                     soh_weight1=0.4
                 else:
@@ -288,7 +289,7 @@ class BatSoh:
                 if ah_packcrnt_dis<self.param.Capacity: #放电ah数对结果的影响
                     soh_weight1=(1-ah_packcrnt_dis/self.param.Capacity*1.5)*soh_weight1
                 else:
-                    soh_weight1=0
+                    soh_weight1=0.1
             
                 if self.param.Capacity**0.7*0.4 < abs(ah_accum_tatol) < self.param.Capacity:    #累计量的权重
                     if abs(ah_accum_tatol-ah_packcrnt)<self.param.Capacity/20:
@@ -615,11 +616,11 @@ class BatSoh:
                                             'DV_Volt':DV_Volt,
                                             'XVOLT':xvolt})
                     start_time=df_Data1.loc[0,'time']
-                    start_time=start_time+datetime.timedelta(seconds=600)
+                    start_time=start_time+datetime.timedelta(seconds=900)
                     end_time=df_Data1.loc[len(time2)-1,'time']
-                    end_time=end_time-datetime.timedelta(seconds=1200)
-                    if soc2[0]<37:
-                        df_Data1=df_Data1[(df_Data1['SOC']>39) & (df_Data1['time']<end_time)]
+                    end_time=end_time-datetime.timedelta(seconds=1500)
+                    if soc2[0]<40:
+                        df_Data1=df_Data1[(df_Data1['SOC']>43) & (df_Data1['time']<end_time)]
                     else:
                         df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['time']<end_time)]
             
@@ -635,13 +636,13 @@ class BatSoh:
                     if len(df_Data1)>1:
                         PeakIndex=df_Data1['DVDQ'].idxmax()
                         #筛选峰值点附近±0.5%SOC内的数据
-                        Data2=df_Data1[(df_Data1['SOC']>(df_Data1['SOC'][PeakIndex]-0.5)) & (df_Data1['SOC']<(df_Data1['SOC'][PeakIndex]+0.5))]
-                        if len(Data2)>2:
+                        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)>2:
                             Ah_tatal1 = df_Data1['Ah_tatal']
                             DVDQ = df_Data1['DVDQ']
                             soc2 = df_Data1['SOC']
                             xvolt = df_Data1['XVOLT']
-                            if soc2[PeakIndex]>40 and soc2[PeakIndex]<90:
+                            if soc2[PeakIndex]>43 and soc2[PeakIndex]<90:
                                 cellsoh_init=(Ah_tatal[-1]-Ah_tatal1[PeakIndex]) * 100 / ((self.param.FullChrgSoc - self.param.PeakSoc) * 0.01 * self.param.Capacity)
                                 if cellsoh_init<95:
                                     cellsoh_init=cellsoh_init*0.3926+58.14
@@ -652,8 +653,8 @@ class BatSoh:
                         else:
                             df_Data1=df_Data1.drop([PeakIndex])
                             PeakIndex = df_Data1['DVDQ'].idxmax()
-                            Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
-                            if len(Data2) > 2:
+                            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) > 2:
                                 Ah_tatal1 = df_Data1['Ah_tatal']
                                 DVDQ = df_Data1['DVDQ']
                                 soc2 = df_Data1['SOC']

+ 16 - 2
LIB/MIDDLE/CellStateEstimation/SOH/main.py

@@ -2,6 +2,7 @@ import CBMSBatSoh
 import log
 #coding=utf-8
 import os
+import sys
 import datetime
 import pandas as pd
 from LIB.BACKEND import DBManager, Log
@@ -44,14 +45,27 @@ if __name__ == "__main__":
 
     for sn in SNnums:
         try:
+            if 'PK500' in sn:
+                celltype=1 #6040三元电芯
+            elif 'PK502' in sn:
+                celltype=2 #4840三元电芯
+            elif 'PK504' in sn:
+                celltype=99    #60ah林磷酸铁锂电芯
+            elif 'MGMLXN750' in sn:
+                celltype=3 #力信50ah三元电芯
+            elif 'MGMCLN750' in sn: 
+                celltype=4 #CATL 50ah三元电芯
+            else:
+                print('未找到对应电池编号!!!')
+                sys.exit()
             dbManager = DBManager.DBManager()
-            df_data = dbManager.get_data(sn='PK50001A100000022', start_time=start_time, end_time=end_time, data_groups=['bms','accum'])
+            df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms','accum'])
             df_bms = df_data['bms']
             df_accum=df_data['accum']
             # df_bms.to_csv('BMS_'+sn+'.csv')
             # df_accum.to_csv('BMS_accum_'+sn+'.csv')
 
-            BatSoh=CBMSBatSoh.BatSoh(sn,df_bms,df_accum,host, port, db, user, password, tablename)
+            BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,host, port, db, user, password, tablename)
             df_res=BatSoh.batsoh()
             df_res.to_csv('BMS_SOH_'+sn+'.csv',encoding='GB18030')