|
@@ -7,7 +7,7 @@ import BatParam
|
|
|
import DBDownload
|
|
|
|
|
|
class BatSoh:
|
|
|
- def __init__(self,sn,df_bms,df_accum): #参数初始化
|
|
|
+ def __init__(self,sn,df_bms,df_accum, host, port, db, user, password, tablename): #参数初始化
|
|
|
|
|
|
self.sn=sn
|
|
|
self.param=BatParam.BatParam(sn)
|
|
@@ -22,6 +22,13 @@ class BatSoh:
|
|
|
self.df_accum=df_accum
|
|
|
self.accumtime=pd.to_datetime(df_accum['时间戳'], format='%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
+ self.host=host
|
|
|
+ self.port=port
|
|
|
+ self.db=db
|
|
|
+ self.user=user
|
|
|
+ self.password=password
|
|
|
+ self.tablename=tablename
|
|
|
+
|
|
|
def batsoh(self):
|
|
|
if self.param.celltype==1 or self.param.celltype==2:
|
|
|
df_res=self._ncmsoh_twopoint()
|
|
@@ -32,22 +39,10 @@ class BatSoh:
|
|
|
return df_res
|
|
|
|
|
|
def getdata(self): #获取已有soh结果
|
|
|
- host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
|
- port=3306
|
|
|
- db='qx_cas'
|
|
|
- user='qx_read'
|
|
|
- password='Qx@123456'
|
|
|
-
|
|
|
- now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
- now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
|
|
|
- start_time=now_time-datetime.timedelta(days=60)
|
|
|
- end_time=str(now_time)
|
|
|
- start_time=str(start_time)
|
|
|
-
|
|
|
- DBManager=DBDownload.DBDownload(host, port, db, user, password)
|
|
|
+
|
|
|
+ DBManager=DBDownload.DBDownload(self.host, self.port, self.db, self.user, self.password)
|
|
|
with DBManager as DBManager:
|
|
|
- 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]
|
|
|
+ self.df_soh=DBManager.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename='soh_result', sn=self.sn)
|
|
|
|
|
|
def _np_move_avg(self,a, n, mode="same"): #定义滑动滤波函数
|
|
|
return (np.convolve(a, np.ones((n,)) / n, mode=mode))
|
|
@@ -249,7 +244,7 @@ class BatSoh:
|
|
|
|
|
|
if standingpoint_sp:
|
|
|
self.getdata() #获取已计算的soh
|
|
|
- column_name=['time_st','time_sp','sn','method','soh','cellsoh1','cellsoh2','cellsoh3','cellsoh4','cellsoh5','cellsoh6','cellsoh7','cellsoh8','cellsoh9','cellsoh10','cellsoh11','cellsoh12','cellsoh13','cellsoh14','cellsoh15','cellsoh16','cellsoh17','cellsoh18','cellsoh19','cellsoh20']
|
|
|
+ column_name=['time_st','time_sp','sn','method','soh','cellsoh']
|
|
|
df_res=pd.DataFrame(columns=column_name)
|
|
|
|
|
|
for i in range(len(standingpoint_sp)):
|
|
@@ -313,39 +308,37 @@ class BatSoh:
|
|
|
else:
|
|
|
soh_weight1=soh_weight1
|
|
|
|
|
|
- cellsoh=[timepoint_bms_st, timepoint_bms_sp, self.sn, 1]
|
|
|
- for j in range(20): #计算每个电芯的SOH值
|
|
|
- if j<self.param.CellVoltNums:
|
|
|
- ocv_soc1=np.interp(cellocv_st[j],self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
- ocv_soc2=np.interp(cellocv_sp[j],self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
- delt_ocv_soc=ocv_soc2-ocv_soc1
|
|
|
- delt_ocv_soc_weight=self._deltsoc_weight(abs(delt_ocv_soc))
|
|
|
- soh_weight=soh_weight1*tempweightlist[i]*delt_ocv_soc_weight
|
|
|
- cellsoh_init=ah_accum*100/((ocv_soc2-ocv_soc1)*0.01*self.param.Capacity)
|
|
|
-
|
|
|
- if cellsoh_init>55 and cellsoh_init<120: #判断soh值的有效区间
|
|
|
- if len(df_res)<1:
|
|
|
- if not self.df_soh.empty and self.df_soh.shape[1]>10:
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight + list(self.df_soh['cellsoh'+str(j+1)])[-1]*(1-soh_weight)
|
|
|
- else:
|
|
|
- cellsoh_cal=cellsoh_init
|
|
|
+ cellsoh=[]
|
|
|
+ for j in range(self.param.CellVoltNums): #计算每个电芯的SOH值
|
|
|
+ ocv_soc1=np.interp(cellocv_st[j],self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ ocv_soc2=np.interp(cellocv_sp[j],self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ delt_ocv_soc=ocv_soc2-ocv_soc1
|
|
|
+ delt_ocv_soc_weight=self._deltsoc_weight(abs(delt_ocv_soc))
|
|
|
+ soh_weight=soh_weight1*tempweightlist[i]*delt_ocv_soc_weight
|
|
|
+ cellsoh_init=ah_accum*100/((ocv_soc2-ocv_soc1)*0.01*self.param.Capacity)
|
|
|
+
|
|
|
+ if cellsoh_init>55 and cellsoh_init<120: #判断soh值的有效区间
|
|
|
+ if len(df_res)<1:
|
|
|
+ if not self.df_soh.empty:
|
|
|
+ cellsoh_last=eval(self.df_soh.loc[len(self.df_soh)-1,'cellsoh'])
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last[j]*(1-soh_weight)
|
|
|
else:
|
|
|
- if abs(cellsoh_init-df_res.iloc[-1]['cellsoh'+str(j+1)])<15:
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight*0.5 + df_res.iloc[-1]['cellsoh'+str(j+1)]*(1-soh_weight*0.5)
|
|
|
- else:
|
|
|
- soh_weight=soh_weight*0.2
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight*0.5 + df_res.iloc[-1]['cellsoh'+str(j+1)]*(1-soh_weight*0.5)
|
|
|
- cellsoh.append(cellsoh_cal)
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
|
|
|
else:
|
|
|
- cellsoh=[]
|
|
|
- break
|
|
|
+ cellsoh_last=eval(df_res.loc[len(df_res)-1,'cellsoh'])
|
|
|
+ if abs(cellsoh_init-cellsoh_last[j])<10:
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight*0.5 + cellsoh_last[j]*(1-soh_weight*0.5)
|
|
|
+ else:
|
|
|
+ soh_weight=soh_weight*0.2
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight*0.5 + cellsoh_last[j]*(1-soh_weight*0.5)
|
|
|
+ cellsoh.append(cellsoh_cal)
|
|
|
else:
|
|
|
- cellsoh.append(0)
|
|
|
- if len(cellsoh)>4:
|
|
|
- soh_value=cellsoh[4:4+self.param.CellVoltNums]
|
|
|
- soh=min(soh_value)
|
|
|
- cellsoh.insert(4,soh)
|
|
|
- df_res.loc[len(df_res)]=cellsoh
|
|
|
+ cellsoh=[]
|
|
|
+ break
|
|
|
+ if cellsoh:
|
|
|
+ soh=min(cellsoh)
|
|
|
+ soh_list=[timepoint_bms_st, timepoint_bms_sp, self.sn, 1, soh, str(cellsoh)]
|
|
|
+ df_res.loc[len(df_res)]=soh_list
|
|
|
else:
|
|
|
continue
|
|
|
if df_res.empty:
|
|
@@ -429,7 +422,9 @@ class BatSoh:
|
|
|
|
|
|
#获取DVDQ算法所需数据——开始
|
|
|
if i==3 and self.packcrnt[1]<=-1 and self.packcrnt[2]<=-1 and self.packcrnt[3]<=-1:
|
|
|
+ self._celltemp_weight(i)
|
|
|
chrg_start.append(i)
|
|
|
+ tempweightlist2.append(self.tempweight)
|
|
|
charging=1
|
|
|
elif self.packcrnt[i-1]>-1 and self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.packcrnt[i+2]<=-1: #判断充电开始
|
|
|
if self.bms_soc[i]<45:
|
|
@@ -489,7 +484,7 @@ class BatSoh:
|
|
|
|
|
|
if standingpoint_sp or chrg_end: #开始计算SOH
|
|
|
self.getdata() #获取已计算的soh
|
|
|
- column_name=['time_st','time_sp','sn','method','soh','cellsoh1','cellsoh2','cellsoh3','cellsoh4','cellsoh5','cellsoh6','cellsoh7','cellsoh8','cellsoh9','cellsoh10','cellsoh11','cellsoh12','cellsoh13','cellsoh14','cellsoh15','cellsoh16','cellsoh17','cellsoh18','cellsoh19','cellsoh20']
|
|
|
+ column_name=['time_st','time_sp','sn','method','soh','cellsoh']
|
|
|
df_res=pd.DataFrame(columns=column_name)
|
|
|
|
|
|
if standingpoint_sp: #两点法计算SOH
|
|
@@ -556,7 +551,6 @@ class BatSoh:
|
|
|
else:
|
|
|
soh_weight=soh_weight
|
|
|
|
|
|
- cellsoh=[timepoint_bms_st, timepoint_bms_sp, self.sn]
|
|
|
delt_ocv_soc=ocv_soc2-ocv_soc1
|
|
|
delt_ocv_soc_weight=self._deltsoc_weight(abs(delt_ocv_soc))
|
|
|
soh_weight=soh_weight*tempweightlist1[i]*delt_ocv_soc_weight*0.5
|
|
@@ -564,22 +558,20 @@ class BatSoh:
|
|
|
|
|
|
if cellsoh_init>65 and cellsoh_init<115: #判断soh值的有效区间
|
|
|
if len(df_res)<1:
|
|
|
- if not self.df_soh.empty and self.df_soh.shape[1]>10:
|
|
|
+ if not self.df_soh.empty:
|
|
|
cellsoh_cal=cellsoh_init*soh_weight + list(self.df_soh['soh'])[-1]*(1-soh_weight)
|
|
|
else:
|
|
|
- cellsoh_cal=cellsoh_init
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
|
|
|
else:
|
|
|
- if abs(cellsoh_init-df_res.iloc[-1]['soh'])<10:
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight + df_res.iloc[-1]['soh']*(1-soh_weight)
|
|
|
+ cellsoh_last=df_res.loc[len(df_res)-1,'soh']
|
|
|
+ if abs(cellsoh_init-cellsoh_last)<10:
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
|
|
|
else:
|
|
|
soh_weight=soh_weight*0.1
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight + df_res.iloc[-1]['soh']*(1-soh_weight)
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
|
|
|
|
|
|
- cellsoh.append(1)
|
|
|
- cellsoh.append(cellsoh_cal)
|
|
|
- for j in range(20): #计算每个电芯的SOH值
|
|
|
- cellsoh.append(cellsoh_cal)
|
|
|
- df_res.loc[len(df_res)]=cellsoh
|
|
|
+ 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:
|
|
|
continue
|
|
|
else:
|
|
@@ -677,26 +669,23 @@ class BatSoh:
|
|
|
else:
|
|
|
continue
|
|
|
|
|
|
- cellsoh=[self.bmstime[chrg_start[i]], self.bmstime[chrg_end[i]], self.sn]
|
|
|
soh_weight=tempweightlist2[i]*0.5
|
|
|
if cellsoh_init>65 and cellsoh_init<115: #判断soh值的有效区间
|
|
|
if len(df_res)<1:
|
|
|
if not self.df_soh.empty and self.df_soh.shape[1]>10:
|
|
|
cellsoh_cal=cellsoh_init*soh_weight + list(self.df_soh['soh'])[-1]*(1-soh_weight)
|
|
|
else:
|
|
|
- cellsoh_cal=cellsoh_init
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight+100*(1-soh_weight)
|
|
|
else:
|
|
|
- if abs(cellsoh_init-df_res.iloc[-1]['soh'])<10:
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight + df_res.iloc[-1]['soh']*(1-soh_weight)
|
|
|
+ cellsoh_last=df_res.loc[len(df_res)-1,'soh']
|
|
|
+ if abs(cellsoh_init-cellsoh_last)<10:
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
|
|
|
else:
|
|
|
soh_weight=soh_weight*0.2
|
|
|
- cellsoh_cal=cellsoh_init*soh_weight + df_res.iloc[-1]['soh']*(1-soh_weight)
|
|
|
+ cellsoh_cal=cellsoh_init*soh_weight + cellsoh_last*(1-soh_weight)
|
|
|
|
|
|
- cellsoh.append(2)
|
|
|
- cellsoh.append(cellsoh_cal)
|
|
|
- for j in range(20): #计算每个电芯的SOH值
|
|
|
- cellsoh.append(cellsoh_cal)
|
|
|
- df_res.loc[len(df_res)]=cellsoh
|
|
|
+ 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
|
|
|
else:
|
|
|
continue
|
|
|
else:
|