import pandas as pd import numpy as np import bisect import datetime import matplotlib.pyplot as plt import matplotlib.dates as mdates import BatParam class BatChrg: def __init__(self,sn,celltype,df_bms,df_volt,df_temp,df_accum): #参数初始化 self.sn=sn self.celltype=celltype self.param=BatParam.BatParam(celltype) self.df_volt=df_volt self.df_temp=df_temp self.df_bms=df_bms self.packcrnt=(df_volt['可充电储能装置电流(A)'].astype('float'))*self.param.PackCrntDec self.packvolt=df_volt['可充电储能装置电压(V)'].astype('float') self.bms_soc=df_bms['SOC'] self.bmsstat=df_bms['充电状态'] self.bmstime= pd.to_datetime(df_volt['上报时间'], format='%Y-%m-%d %H:%M:%S') self.param.CellVoltNums=int(df_volt.loc[5,'单体电池总数']) self.param.CellTempNums=int(df_temp.loc[5,'可充电储能温度探针个数']) self.param.PackVoltOvLv1=self.param.CellOvLv1*self.param.CellVoltNums self.param.PackVoltOvLv2=self.param.CellOvLv2*self.param.CellVoltNums self.param.PackVoltUvLv1=self.param.CellUvLv1*self.param.CellVoltNums self.param.PackVoltUvLv2=self.param.CellUvLv2*self.param.CellVoltNums def chrg(self): if self.celltype==1 or self.celltype==2 or self.celltype==3 or self.celltype==4 or self.celltype==100: df_res=self._ncm_chrg() return df_res elif self.celltype==99: df_res=self._lfp_diag() return df_res else: return pd.DataFrame() #定义滑动滤波函数............................................................................................. def _np_move_avg(self,a, n, mode="same"): return (np.convolve(a, np.ones((n,)) / n, mode=mode)) #寻找当前行数据的所有温度值................................................................................... def _celltemp_get(self,num): celltemp = [] for j in range(1, self.param.CellTempNums+1): celltemp.append(self.df_temp.loc[num,str(j)+'.0']) return celltemp #获取当前行所有电压数据........................................................................................ def _cellvolt_get(self,num): cellvolt=[] for j in range(1, self.param.CellVoltNums+1): cellvolt.append(self.df_volt.loc[num, str(j)+'.0']) return cellvolt #筛选充电数据.............................................................................................................................. def _chrgdata(self): self.ChgStart=[] self.ChgEnd=[] if len(self.packvolt)>100: charging=0 for i in range(3, len(self.bmstime) - 3): if charging==0: if i==3 and self.bmsstat[i]=='停车充电' and self.bmsstat[i+1]=='停车充电': self.ChgStart.append(i) charging=1 elif self.bmsstat[i-1]!='停车充电' and self.bmsstat[i]=='停车充电': self.ChgStart.append(i) charging=1 else: pass else: if (self.bmsstat[i-1]=='停车充电' or '充电完成') and self.packcrnt[i]>0: self.ChgEnd.append(i) charging=0 elif i == (len(self.bmstime) - 4) and (self.bmsstat[i] == '停车充电' or '充电完成') and self.packcrnt[i]<-1: self.ChgEnd.append(len(self.bmstime)-2) charging=0 #dvdq方法计算soh........................................................................................................................... def _dvdq_soh(self, chrg_st, chrg_end,cellvolt): Ah = 0 #参数赋初始值 Volt = cellvolt[chrg_st] DV_Volt=[] DQ_Ah = [] DVDQ = [] time2 = [] soc2 = [] Ah_tatal=[0] xvolt=[] #计算DV和DQ值 for j in range(chrg_st,chrg_end): Step=(self.bmstime[j+1]-self.bmstime[j]).total_seconds() Ah=Ah-self.packcrnt[j]*Step/3600 if (cellvolt[j]-Volt)>0.002 and Ah>0: Ah_tatal.append(Ah_tatal[-1]+Ah) DQ_Ah.append(Ah) DV_Volt.append(cellvolt[j]-Volt) DVDQ.append((DV_Volt[-1])/DQ_Ah[-1]) xvolt.append(cellvolt[j]) Volt=cellvolt[j] Ah = 0 time2.append(self.bmstime[j]) soc2.append(float(self.bms_soc[j].strip('%'))) #切片,去除前后10min的数据 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=df_Data1.loc[0,'time'] start_time=start_time+datetime.timedelta(seconds=900) end_time=df_Data1.loc[len(time2)-1,'time'] end_time=end_time-datetime.timedelta(seconds=600) # if soc2[0]<36: # df_Data1=df_Data1[(df_Data1['SOC']>40) & (df_Data1['SOC']<80)] # else: df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['time']self.param.PeakVoltLowLmt) & (df_Data1['XVOLT']