123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import pandas as pd
- import numpy as np
- import datetime
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
- class BatBehave:
- def __init__(self,sn,celltype,df_bms): #参数初始化
- self.sn=sn
- self.celltype=celltype
- self.param=BatParam.BatParam(celltype)
- self.df_bms=df_bms
- df_bms['时间戳']=pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
-
- self.packcrnt=df_bms['总电流[A]']*self.param.PackCrntDec
- self.bmstime= df_bms['时间戳']
- self.packsoc=df_bms['SOC[%]']
- self.cellvolt_name=['单体电压'+str(x) for x in range(1,self.param.CellVoltNums+1)]
- # othertemp=['其他温度'+str(x) for x in range(1,self.param.OtherTempNums+1)]
- self.celltemp_name=['单体温度'+str(x) for x in range(1,self.param.CellTempNums+1)]
- # self.celltemp_name=celltemp+othertemp
-
- def behave(self):
- if self.celltype<=50:
- df_res=self._bat_behave()
- return df_res
- else:
- df_res=self._bat_behave()
- return df_res
-
- #寻找当前行数据的所有温度值...................................................................................
- def _celltemp_get(self,num):
- celltemp = list(self.df_bms.loc[num,self.celltemp_name])
- return celltemp
- #获取当前行所有电压数据............................................................................................
- def _cellvolt_get(self,num):
- cellvolt = list(self.df_bms.loc[num,self.cellvolt_name]/1000)
- return cellvolt
-
- #筛选充电数据.......................................................................................................
- def _chrgdata(self):
- self.ComeIn=[]
- self.ChgStart=[]
- self.ChgEnd=[]
- self.ComeOut=[]
- if len(self.df_bms)>10:
- state=0
- for i in range(3, len(self.bmstime) - 3):
- if state==0:
- if abs(self.packcrnt[i])<=0.1:
- self.ComeIn.append(i)
- state=1
- elif state==1:
- if self.packcrnt[i]<=-10 and self.packcrnt[i+1]<=-10:
- self.ChgStart.append(i)
- state=2
- elif self.packcrnt[i]>1:
- state=0
- self.ComeIn.pop()
- else:
- pass
- elif state==2:
- if self.packcrnt[i]>-0.1:
- state=3
- if (self.bmstime[i]-self.bmstime[self.ChgStart[-1]]).total_seconds()>300 and self.packsoc[i]-self.packsoc[self.ChgStart[-1]]>5:
- self.ChgEnd.append(i)
- else:
- state=0
- self.ComeIn.pop()
- self.ChgStart.pop()
- else:
- pass
- else:
- if self.packcrnt[i]>1:
- state=0
- self.ComeOut.append(i)
- else:
- pass
- else:
- pass
- #..........................................电池诊断功能..................................................................
- def _bat_behave(self):
- df_res=pd.DataFrame(columns=['sn','time_in', 'time_st', 'time_sp', 'time_out', 'soc_st', 'soc_sp'])
- self._chrgdata()
- if len(self.ComeOut)>0:
- for i in range(len(self.ChgEnd)):
- df_res.loc[i]=[self.sn, self.bmstime[self.ComeIn[i]], self.bmstime[self.ChgStart[i]], self.bmstime[self.ChgEnd[i]], self.bmstime[self.ComeOut[i]], self.packsoc[self.ChgStart[i]], self.packsoc[self.ChgEnd[i]]]
- return df_res
- else:
- return pd.DataFrame()
|