|
@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
|
|
|
import BatParam
|
|
|
import DBDownload
|
|
|
|
|
|
-class Soh:
|
|
|
+class BatSoh:
|
|
|
def __init__(self,sn,df_bms,df_accum): #参数初始化
|
|
|
|
|
|
self.sn=sn
|
|
@@ -22,7 +22,7 @@ class Soh:
|
|
|
self.df_accum=df_accum
|
|
|
self.accumtime=pd.to_datetime(df_accum['时间戳'], format='%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
- def soh(self):
|
|
|
+ def batsoh(self):
|
|
|
if self.param.celltype==1 or self.param.celltype==2:
|
|
|
df_res=self._ncmsoh_twopoint()
|
|
|
return df_res
|
|
@@ -46,10 +46,10 @@ class Soh:
|
|
|
|
|
|
DBManager=DBDownload.DBDownload(host, port, db, user, password)
|
|
|
with DBManager as DBManager:
|
|
|
- df_soh=DBManager.getdata('sn', 'time', 'bms_soh', 'soh', 'soh_err', tablename='soh_result',st=start_time,sp=end_time)
|
|
|
+ df_soh=DBManager.getdata('sn', 'time', 'bms_soh', 'soh', 'soh_err', tablename='soh_result_old',st=start_time,sp=end_time)
|
|
|
self.df_soh=df_soh[df_soh['sn']==self.sn]
|
|
|
|
|
|
- def np_move_avg(self,a, n, mode="same"): #定义滑动滤波函数
|
|
|
+ def _np_move_avg(self,a, n, mode="same"): #定义滑动滤波函数
|
|
|
return (np.convolve(a, np.ones((n,)) / n, mode=mode))
|
|
|
|
|
|
def _chrgdata(self): #筛选充电数据
|
|
@@ -345,11 +345,7 @@ class Soh:
|
|
|
soh_value=cellsoh[4:4+self.param.CellVoltNums]
|
|
|
soh=min(soh_value)
|
|
|
cellsoh.insert(4,soh)
|
|
|
- if len(df_res)<1:
|
|
|
- df_res.loc[0]=cellsoh
|
|
|
- else:
|
|
|
- df_res.loc[df_res.index.values[-1]+1]=cellsoh
|
|
|
- print(df_res)
|
|
|
+ df_res.loc[len(df_res)]=cellsoh
|
|
|
else:
|
|
|
continue
|
|
|
if df_res.empty:
|
|
@@ -473,7 +469,7 @@ class Soh:
|
|
|
continue
|
|
|
else:
|
|
|
continue
|
|
|
- elif i==len(self.packcrnt)-3 and self.packcrnt[i+1]<-1 and self.packcrnt[i+2]<-1:
|
|
|
+ elif i==len(self.packcrnt)-4 and self.packcrnt[i+1]<-1 and self.packcrnt[i+2]<-1:
|
|
|
charging=0
|
|
|
if len(chrg_start)>len(chrg_end):
|
|
|
cellvolt_now=self._cellvolt_get(i)
|
|
@@ -583,10 +579,7 @@ class Soh:
|
|
|
cellsoh.append(cellsoh_cal)
|
|
|
for j in range(20): #计算每个电芯的SOH值
|
|
|
cellsoh.append(cellsoh_cal)
|
|
|
- if len(df_res)<1:
|
|
|
- df_res.loc[0]=cellsoh
|
|
|
- else:
|
|
|
- df_res.loc[df_res.index.values[-1]+1]=cellsoh
|
|
|
+ df_res.loc[len(df_res)]=cellsoh
|
|
|
else:
|
|
|
continue
|
|
|
else:
|
|
@@ -595,7 +588,7 @@ class Soh:
|
|
|
if chrg_end:
|
|
|
for i in range(len(chrg_end)):
|
|
|
cellvolt_max = self.df_bms['单体电压' + str(cellmaxvolt_number2[i]+1)] / 1000 #获取最大电压
|
|
|
- cellvolt=self.np_move_avg(cellvolt_max, 3, mode="same") #对电压进行滑动平均滤波
|
|
|
+ cellvolt=self._np_move_avg(cellvolt_max, 3, mode="same") #对电压进行滑动平均滤波
|
|
|
|
|
|
Ah = 0 #参数赋初始值
|
|
|
Volt = cellvolt[chrg_start[i]]
|
|
@@ -622,40 +615,40 @@ class Soh:
|
|
|
soc2.append(self.bms_soc[j])
|
|
|
|
|
|
#切片,去除前后10min的数据
|
|
|
- Data1 = pd.DataFrame({'time': time2,
|
|
|
+ df_Data1 = pd.DataFrame({'time': time2,
|
|
|
'SOC': soc2,
|
|
|
'DVDQ': DVDQ,
|
|
|
'Ah_tatal': Ah_tatal[:-1],
|
|
|
'DQ_Ah':DQ_Ah,
|
|
|
'DV_Volt':DV_Volt,
|
|
|
'XVOLT':xvolt})
|
|
|
- start_time=Data1.loc[0,'time']
|
|
|
+ start_time=df_Data1.loc[0,'time']
|
|
|
start_time=start_time+datetime.timedelta(seconds=600)
|
|
|
- end_time=Data1.loc[len(time2)-1,'time']
|
|
|
+ end_time=df_Data1.loc[len(time2)-1,'time']
|
|
|
end_time=end_time-datetime.timedelta(seconds=1200)
|
|
|
if soc2[0]<37:
|
|
|
- Data1=Data1[(Data1['SOC']>39) & (Data1['time']<end_time)]
|
|
|
+ df_Data1=df_Data1[(df_Data1['SOC']>39) & (df_Data1['time']<end_time)]
|
|
|
else:
|
|
|
- Data1=Data1[(Data1['time']>start_time) & (Data1['time']<end_time)]
|
|
|
+ df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['time']<end_time)]
|
|
|
|
|
|
# ax1 = plt.subplot(3, 1, 1)
|
|
|
- # plt.plot(Data1['XVOLT'],Data1['DVDQ'],'r*-')
|
|
|
+ # plt.plot(df_Data1['XVOLT'],df_Data1['DVDQ'],'r*-')
|
|
|
# ax1 = plt.subplot(3, 1, 2)
|
|
|
- # plt.plot(Data1['SOC'],Data1['XVOLT'],'y*-')
|
|
|
+ # plt.plot(df_Data1['SOC'],df_Data1['XVOLT'],'y*-')
|
|
|
# ax1 = plt.subplot(3, 1, 3)
|
|
|
- # plt.plot(Data1['SOC'], Data1['DVDQ'], 'r*-')
|
|
|
+ # plt.plot(df_Data1['SOC'], df_Data1['DVDQ'], 'r*-')
|
|
|
# plt.show()
|
|
|
|
|
|
#寻找峰值并计算Soh和置信度
|
|
|
- if len(Data1['DVDQ'])>1:
|
|
|
- PeakIndex=Data1['DVDQ'].idxmax()
|
|
|
+ if len(df_Data1)>1:
|
|
|
+ PeakIndex=df_Data1['DVDQ'].idxmax()
|
|
|
#筛选峰值点附近±0.5%SOC内的数据
|
|
|
- Data2=Data1[(Data1['SOC']>(Data1['SOC'][PeakIndex]-0.5)) & (Data1['SOC']<(Data1['SOC'][PeakIndex]+0.5))]
|
|
|
+ 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:
|
|
|
- Ah_tatal1 = Data1['Ah_tatal']
|
|
|
- DVDQ = Data1['DVDQ']
|
|
|
- soc2 = Data1['SOC']
|
|
|
- xvolt = Data1['XVOLT']
|
|
|
+ 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:
|
|
|
cellsoh_init=(Ah_tatal[-1]-Ah_tatal1[PeakIndex]) * 100 / ((self.param.FullChrgSoc - self.param.PeakSoc) * 0.01 * self.param.Capacity)
|
|
|
if cellsoh_init<95:
|
|
@@ -665,14 +658,14 @@ class Soh:
|
|
|
else:
|
|
|
continue
|
|
|
else:
|
|
|
- Data1=Data1.drop([PeakIndex])
|
|
|
- PeakIndex = Data1['DVDQ'].idxmax()
|
|
|
- Data2 = Data1[(Data1['SOC'] > (Data1['SOC'][PeakIndex] - 0.5)) & (Data1['SOC'] < (Data1['SOC'][PeakIndex] + 0.5))]
|
|
|
+ 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:
|
|
|
- Ah_tatal1 = Data1['Ah_tatal']
|
|
|
- DVDQ = Data1['DVDQ']
|
|
|
- soc2 = Data1['SOC']
|
|
|
- xvolt = Data1['XVOLT']
|
|
|
+ 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:
|
|
|
cellsoh_init=(Ah_tatal[-1]-Ah_tatal1[PeakIndex]) * 100 / ((self.param.FullChrgSoc - self.param.PeakSoc) * 0.01 * self.param.Capacity)
|
|
|
if cellsoh_init<95:
|
|
@@ -703,10 +696,7 @@ class Soh:
|
|
|
cellsoh.append(cellsoh_cal)
|
|
|
for j in range(20): #计算每个电芯的SOH值
|
|
|
cellsoh.append(cellsoh_cal)
|
|
|
- if len(df_res)<1:
|
|
|
- df_res.loc[0]=cellsoh
|
|
|
- else:
|
|
|
- df_res.loc[df_res.index.values[-1]+1]=cellsoh
|
|
|
+ df_res.loc[len(df_res)]=cellsoh
|
|
|
else:
|
|
|
continue
|
|
|
else:
|