CBMSBatUniform.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. import pandas as pd
  2. import numpy as np
  3. import datetime
  4. from LIB.MIDDLE.CellStateEstimation.Common import BatParam
  5. class BatUniform():
  6. def __init__(self,sn,celltype,df_bms,df_uniform,df_last3,df_lfp1): #参数初始化
  7. if (not df_lfp1.empty) and celltype>50:
  8. df_lfp1.drop(['sn'],axis=1)
  9. df_bms=pd.concat([df_lfp1, df_bms], ignore_index=True)
  10. else:
  11. pass
  12. self.sn=sn
  13. self.celltype=celltype
  14. self.param=BatParam.BatParam(celltype)
  15. self.df_bms=df_bms
  16. self.packcrnt=df_bms['总电流[A]']*self.param.PackCrntDec
  17. self.packvolt=df_bms['总电压[V]']
  18. self.bms_soc=df_bms['SOC[%]']
  19. self.bmstime= pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
  20. # df_uniform['time']=pd.to_datetime(df_uniform['time'], format='%Y-%m-%d %H:%M:%S')
  21. self.df_uniform=df_uniform
  22. self.df_last3=df_last3
  23. self.df_lfp1=df_lfp1
  24. self.cellvolt_name=['单体电压'+str(x) for x in range(1,self.param.CellVoltNums+1)]
  25. self.celltemp_name=['单体温度'+str(x) for x in range(1,self.param.CellTempNums+1)]
  26. def batuniform(self):
  27. if self.celltype<50:
  28. df_res, df_ram_last3=self._ncm_uniform()
  29. return df_res, df_ram_last3, self.df_lfp1
  30. else:
  31. df_res, df_ram_last3, df_ram_lfp1=self._lfp_uniform()
  32. return df_res, df_ram_last3, df_ram_lfp1
  33. #定义滑动滤波函数........................................................................................................................................
  34. def _np_move_avg(self,a, n, mode="same"):
  35. return (np.convolve(a, np.ones((n,)) / n, mode=mode))
  36. #寻找当前行数据的最小温度值................................................................................................................................
  37. def _celltemp_weight(self,num):
  38. celltemp = list(self.df_bms.loc[num,self.celltemp_name])
  39. celltemp.remove(min(celltemp))
  40. self.celltemp=celltemp
  41. if self.celltype>50:
  42. if min(celltemp)>=25:
  43. self.tempweight=1
  44. self.StandardStandingTime=2400
  45. elif min(celltemp)>=15:
  46. self.tempweight=0.6
  47. self.StandardStandingTime=3600
  48. elif min(celltemp)>=5:
  49. self.tempweight=0.2
  50. self.StandardStandingTime=4800
  51. else:
  52. self.tempweight=0.1
  53. self.StandardStandingTime=7200
  54. else:
  55. if min(celltemp)>=25:
  56. self.tempweight=1
  57. self.StandardStandingTime=1800
  58. elif min(celltemp)>=15:
  59. self.tempweight=0.8
  60. self.StandardStandingTime=2400
  61. elif min(celltemp)>=5:
  62. self.tempweight=0.6
  63. self.StandardStandingTime=3600
  64. else:
  65. self.tempweight=0.2
  66. self.StandardStandingTime=7200
  67. #获取当前行所有电压数据............................................................................................................................
  68. def _cellvolt_get(self,num):
  69. cellvolt = np.array(self.df_bms.loc[num,self.cellvolt_name])/1000
  70. return cellvolt
  71. #获取单个电压值.................................................................................................
  72. def _singlevolt_get(self,num,series,mode): #mode==1取当前行单体电压值,mode==2取某个单体所有电压值
  73. s=str(series)
  74. if mode==1:
  75. singlevolt=self.df_bms.loc[num,'单体电压' + s]/1000
  76. return singlevolt
  77. else:
  78. singlevolt=self.df_bms['单体电压' + s]/1000
  79. return singlevolt
  80. #寻找DVDQ的峰值点,并返回..........................................................................................................................
  81. def _dvdq_peak(self, time, soc, cellvolt, packcrnt):
  82. cellvolt = self._np_move_avg(cellvolt, 3, mode="same")
  83. Soc = 0
  84. Ah = 0
  85. Volt = cellvolt[0]
  86. DV_Volt = []
  87. DQ_Ah = []
  88. DVDQ = []
  89. time1 = []
  90. soc1 = []
  91. soc2 = []
  92. xvolt=[]
  93. for m in range(1, len(time)):
  94. Step = (time[m] - time[m - 1]).total_seconds()
  95. Soc = Soc - packcrnt[m] * Step * 100 / (3600 * self.param.Capacity)
  96. Ah = Ah - packcrnt[m] * Step / 3600
  97. if (cellvolt[m]-Volt)>0.0019 and Ah>0:
  98. DQ_Ah.append(Ah)
  99. DV_Volt.append(cellvolt[m]-Volt)
  100. DVDQ.append((DV_Volt[-1])/Ah)
  101. xvolt.append(cellvolt[m])
  102. Volt=cellvolt[m]
  103. Ah = 0
  104. soc1.append(Soc)
  105. time1.append(time[m])
  106. soc2.append(soc[m])
  107. #切片,去除前后10min的数据
  108. df_Data1 = pd.DataFrame({'time': time1,
  109. 'SOC': soc2,
  110. 'DVDQ': DVDQ,
  111. 'AhSoc': soc1,
  112. 'DQ_Ah':DQ_Ah,
  113. 'DV_Volt':DV_Volt,
  114. 'XVOLT':xvolt})
  115. start_time=df_Data1.loc[0,'time']
  116. start_time=start_time+datetime.timedelta(seconds=900)
  117. end_time=df_Data1.loc[len(time1)-1,'time']
  118. end_time=end_time-datetime.timedelta(seconds=1200)
  119. if soc2[0]<36:
  120. df_Data1=df_Data1[(df_Data1['SOC']>40) & (df_Data1['SOC']<80)]
  121. else:
  122. df_Data1=df_Data1[(df_Data1['time']>start_time) & (df_Data1['SOC']<80)]
  123. df_Data1=df_Data1[(df_Data1['XVOLT']>self.param.PeakVoltLowLmt) & (df_Data1['XVOLT']<self.param.PeakVoltUpLmt)]
  124. # print(packcrnt[int(len(time)/2)], min(self.celltemp))
  125. # ax1 = plt.subplot(3, 1, 1)
  126. # plt.plot(df_Data1['SOC'],df_Data1['DQ_Ah'],'g*-')
  127. # plt.xlabel('SOC/%')
  128. # plt.ylabel('DQ_Ah')
  129. # plt.legend()
  130. # ax1 = plt.subplot(3, 1, 2)
  131. # plt.plot(df_Data1['SOC'],df_Data1['XVOLT'],'y*-')
  132. # plt.xlabel('SOC/%')
  133. # plt.ylabel('Volt/V')
  134. # plt.legend()
  135. # ax1 = plt.subplot(3, 1, 3)
  136. # plt.plot(df_Data1['SOC'], df_Data1['DVDQ'], 'r*-')
  137. # plt.xlabel('SOC/%')
  138. # plt.ylabel('DV/DQ')
  139. # plt.legend()
  140. # # plt.show()
  141. if len(df_Data1)>2: #寻找峰值点,且峰值点个数>2
  142. PeakIndex = df_Data1['DVDQ'].idxmax()
  143. df_Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
  144. if len(df_Data2) > 2 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.019:
  145. return df_Data1['AhSoc'][PeakIndex]
  146. else:
  147. df_Data1 = df_Data1.drop([PeakIndex])
  148. PeakIndex = df_Data1['DVDQ'].idxmax()
  149. df_Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
  150. if len(df_Data2) > 2 and df_Data1.loc[PeakIndex,'XVOLT']<self.param.PeakVoltUpLmt-0.019:
  151. return df_Data1['AhSoc'][PeakIndex]
  152. else:
  153. return 0
  154. else:
  155. return 0
  156. #三元电池一致性计算.................................................................................................................................
  157. def _ncm_uniform(self):
  158. column_name=['time','sn','cellsoc_diff','cellvolt_diff','cellmin_num','cellmax_num','cellvolt_rank']
  159. df_res=pd.DataFrame(columns=column_name)
  160. df_ram_last3=self.df_last3
  161. if df_ram_last3.empty:
  162. standingtime=0
  163. standingtime1=0
  164. standingtime2=0
  165. else:
  166. standingtime=df_ram_last3.loc[0,'standingtime']
  167. standingtime1=df_ram_last3.loc[0,'standingtime1']
  168. standingtime2=df_ram_last3.loc[0,'standingtime2']
  169. if abs(self.packcrnt[0])<0.01 and standingtime2>1:
  170. standingtime2=standingtime2+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
  171. else:
  172. pass
  173. for i in range(1,len(self.df_bms)-2):
  174. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1 and abs(self.packcrnt[i+1]) < 0.1: #电流为0
  175. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  176. standingtime2=standingtime2+delttime
  177. self._celltemp_weight(i) #获取不同温度对应的静置时间
  178. if standingtime2>self.StandardStandingTime: #静置时间满足要求
  179. if abs(self.packcrnt[i+2]) >= 0.1:
  180. standingtime2=0
  181. cellvolt_now=self._cellvolt_get(i)
  182. cellvolt_min=min(cellvolt_now)
  183. cellvolt_max=max(cellvolt_now)
  184. cellvolt_last=self._cellvolt_get(i-1)
  185. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  186. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  187. cellvolt_sort=np.argsort(cellvolt_now)
  188. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  189. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  190. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  191. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  192. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  193. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  194. cellsoc_diff=cellsoc_max-cellsoc_min
  195. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  196. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  197. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  198. elif standingtime2>3600*6:
  199. standingtime2=0
  200. cellvolt_now=self._cellvolt_get(i)
  201. cellvolt_min=min(cellvolt_now)
  202. cellvolt_max=max(cellvolt_now)
  203. cellvolt_last=self._cellvolt_get(i-1)
  204. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  205. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  206. cellvolt_sort=np.argsort(cellvolt_now)
  207. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  208. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  209. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  210. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  211. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  212. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  213. cellsoc_diff=cellsoc_max-cellsoc_min
  214. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  215. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  216. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  217. elif i>=len(self.df_bms)-3:
  218. standingtime2=0
  219. cellvolt_now=self._cellvolt_get(i)
  220. cellvolt_min=min(cellvolt_now)
  221. cellvolt_max=max(cellvolt_now)
  222. cellvolt_last=self._cellvolt_get(i-1)
  223. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  224. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  225. cellvolt_sort=np.argsort(cellvolt_now)
  226. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  227. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  228. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  229. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  230. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  231. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  232. cellsoc_diff=cellsoc_max-cellsoc_min
  233. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  234. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  235. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  236. break
  237. else:
  238. continue
  239. else:
  240. continue
  241. else:
  242. standingtime2=0
  243. continue
  244. #更新RAM的standingtime
  245. df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1,standingtime2]
  246. if df_res.empty: #返回计算结果
  247. return pd.DataFrame(), df_ram_last3
  248. else:
  249. return df_res, df_ram_last3
  250. #磷酸铁锂电池一致性计算.........................................................................................................................
  251. def _lfp_uniform(self):
  252. column_name=['time','sn','cellsoc_diff','cellvolt_diff','cellmin_num','cellmax_num','cellvolt_rank']
  253. df_res=pd.DataFrame(columns=column_name)
  254. df_ram_lfp1=pd.DataFrame(columns=self.df_bms.columns.tolist())
  255. chrg_start=[]
  256. chrg_end=[]
  257. charging=0
  258. df_ram_last3=self.df_last3
  259. if df_ram_last3.empty:
  260. standingtime=0
  261. standingtime1=0
  262. standingtime2=0
  263. else:
  264. standingtime=df_ram_last3.loc[0,'standingtime']
  265. standingtime1=df_ram_last3.loc[0,'standingtime1']
  266. standingtime2=df_ram_last3.loc[0,'standingtime2']
  267. if abs(self.packcrnt[0])<0.01 and standingtime2>1:
  268. standingtime2=standingtime2+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
  269. else:
  270. pass
  271. for i in range(2,len(self.df_bms)-2):
  272. #静置电压法计算电芯一致性
  273. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1 and abs(self.packcrnt[i+1]) < 0.1: #电流为0
  274. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  275. standingtime2=standingtime2+delttime
  276. self._celltemp_weight(i) #获取不同温度对应的静置时间
  277. if standingtime2>self.StandardStandingTime: #静置时间满足要求
  278. if abs(self.packcrnt[i+2]) >= 0.1:
  279. standingtime2=0
  280. cellvolt_now=self._cellvolt_get(i)
  281. cellvolt_min=min(cellvolt_now)
  282. cellvolt_max=max(cellvolt_now)
  283. cellvolt_last=self._cellvolt_get(i-1)
  284. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  285. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  286. cellvolt_sort=np.argsort(cellvolt_now)
  287. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  288. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  289. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  290. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  291. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  292. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  293. cellsoc_diff=cellsoc_max-cellsoc_min
  294. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  295. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  296. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  297. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  298. # cellvolt_sort=np.argsort(cellvolt_now)
  299. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  300. # if not df_res.empty:
  301. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  302. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  303. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  304. # elif not self.df_uniform.empty:
  305. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  306. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  307. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  308. # else:
  309. # pass
  310. elif standingtime2>3600*6:
  311. standingtime2=0
  312. cellvolt_now=self._cellvolt_get(i)
  313. cellvolt_min=min(cellvolt_now)
  314. cellvolt_max=max(cellvolt_now)
  315. cellvolt_last=self._cellvolt_get(i-1)
  316. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  317. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  318. cellvolt_sort=np.argsort(cellvolt_now)
  319. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  320. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  321. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  322. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  323. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  324. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  325. cellsoc_diff=cellsoc_max-cellsoc_min
  326. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  327. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  328. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  329. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  330. # cellvolt_sort=np.argsort(cellvolt_now)
  331. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  332. # if not df_res.empty:
  333. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  334. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  335. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  336. # elif not self.df_uniform.empty:
  337. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  338. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  339. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  340. # else:
  341. # pass
  342. elif i>=len(self.df_bms)-3:
  343. standingtime2=0
  344. cellvolt_now=self._cellvolt_get(i)
  345. cellvolt_min=min(cellvolt_now)
  346. cellvolt_max=max(cellvolt_now)
  347. cellvolt_last=self._cellvolt_get(i-1)
  348. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  349. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.003:
  350. cellvolt_sort=np.argsort(cellvolt_now)
  351. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  352. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  353. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  354. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  355. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  356. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  357. cellsoc_diff=cellsoc_max-cellsoc_min
  358. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  359. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  360. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  361. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  362. # cellvolt_sort=np.argsort(cellvolt_now)
  363. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  364. # if not df_res.empty:
  365. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  366. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  367. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  368. # elif not self.df_uniform.empty:
  369. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  370. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  371. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  372. # else:
  373. # pass
  374. else:
  375. pass
  376. else:
  377. pass
  378. else:
  379. standingtime2=0
  380. pass
  381. #获取DVDQ算法所需数据——开始............................................................................................................
  382. if charging==0: #判断充电开始
  383. if self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.packcrnt[i+2]<=-1 and self.bms_soc[i]<40: #充电开始
  384. charging=1
  385. if len(chrg_start)>len(chrg_end):
  386. chrg_start[-1]=i
  387. else:
  388. chrg_start.append(i)
  389. else:
  390. pass
  391. else: #充电中
  392. if (self.bmstime[i+1]-self.bmstime[i]).total_seconds()>180 or (self.packcrnt[i]<-self.param.Capacity/2 and self.packcrnt[i+1]<-self.param.Capacity/2): #如果充电过程中时间间隔>180s,则舍弃该次充电
  393. chrg_start.remove(chrg_start[-1])
  394. charging=0
  395. continue
  396. elif self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.packcrnt[i+2]>-1: #判断电流波动时刻
  397. cellvolt_now=self._cellvolt_get(i+1)
  398. if max(cellvolt_now)>self.param.CellFullChrgVolt: #电压>满充电压
  399. chrg_end.append(i+1)
  400. charging=0
  401. continue
  402. else:
  403. pass
  404. elif self.packcrnt[i+1]>-0.1 and self.packcrnt[i+2]>-0.1: #判断充电结束
  405. charging=0
  406. if len(chrg_start)>len(chrg_end):
  407. if self.bms_soc[i]>90:
  408. chrg_end.append(i)
  409. else:
  410. chrg_start.remove(chrg_start[-1])
  411. continue
  412. else:
  413. continue
  414. elif i==len(self.packcrnt)-3 and self.packcrnt[i+1]<-1 and self.packcrnt[i+2]<-1:
  415. charging=0
  416. if len(chrg_start)>len(chrg_end) and self.bms_soc[i]>90: #soc>90
  417. chrg_end.append(i)
  418. continue
  419. else:
  420. df_ram_lfp1=self.df_bms.iloc[chrg_start[-1]:]
  421. df_ram_lfp1['sn']=self.sn
  422. chrg_start.remove(chrg_start[-1])
  423. continue
  424. else:
  425. continue
  426. if chrg_end: #DVDQ方法计算soc差
  427. peaksoc_list=[]
  428. for i in range(len(chrg_end)):
  429. peaksoc_list = []
  430. self._celltemp_weight(chrg_start[i])
  431. if min(self.celltemp)>10:
  432. for j in range(1, self.param.CellVoltNums + 1):
  433. cellvolt = self._singlevolt_get(i,j,2) #取单体电压j的所有电压值
  434. cellvolt = list(cellvolt[chrg_start[i]:chrg_end[i]])
  435. time = list(self.bmstime[chrg_start[i]:chrg_end[i]])
  436. packcrnt = list(self.packcrnt[chrg_start[i]:chrg_end[i]])
  437. soc = list(self.bms_soc[chrg_start[i]:chrg_end[i]])
  438. peaksoc = self._dvdq_peak(time, soc, cellvolt, packcrnt)
  439. if peaksoc>1:
  440. peaksoc_list.append(peaksoc) #计算到达峰值点的累计Soc
  441. else:
  442. pass
  443. if len(peaksoc_list)>self.param.CellVoltNums/2:
  444. peaksoc_max=max(peaksoc_list)
  445. peaksoc_min=min(peaksoc_list)
  446. peaksoc_maxnum=peaksoc_list.index(peaksoc_min)+1
  447. peaksoc_minnum=peaksoc_list.index(peaksoc_max)+1
  448. cellsoc_diff=peaksoc_max-peaksoc_min
  449. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  450. if not df_res.empty:
  451. cellvolt_rank=df_res.iloc[-1]['cellvolt_rank']
  452. df_res.loc[len(df_res)]=[self.bmstime[chrg_start[i]], self.sn, cellsoc_diff, 0, peaksoc_minnum, peaksoc_maxnum, cellvolt_rank]
  453. elif not self.df_uniform.empty:
  454. cellvolt_rank=self.df_uniform.iloc[-1]['cellvolt_rank']
  455. df_res.loc[len(df_res)]=[self.bmstime[chrg_start[i]], self.sn, cellsoc_diff, 0, peaksoc_minnum, peaksoc_maxnum, cellvolt_rank]
  456. else:
  457. pass
  458. else:
  459. pass
  460. else:
  461. pass
  462. #更新RAM的standingtime
  463. df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1,standingtime2]
  464. if df_res.empty:
  465. return pd.DataFrame(), df_ram_last3, df_ram_lfp1
  466. else:
  467. df_res.sort_values(by='time', ascending=True, inplace=True)
  468. return df_res, df_ram_last3, df_ram_lfp1