CBMSBatUniform.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. import pandas as pd
  2. import numpy as np
  3. import datetime
  4. 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_bms=pd.concat([df_lfp1, df_bms], ignore_index=True)
  9. df_bms.reset_index(inplace=True,drop=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['PackCrnt']*self.param.PackCrntDec
  17. self.packvolt=df_bms['PackVolt']
  18. self.bms_soc=df_bms['PackSOC']
  19. self.bmstime= pd.to_datetime(df_bms['time'], 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=['CellVolt'+str(x) for x in range(1,self.param.CellVoltNums+1)]
  25. self.celltemp_name=['CellTemp'+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])
  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,'CellVolt' + s]
  76. return singlevolt
  77. else:
  78. singlevolt=self.df_bms['CellVolt' + s]
  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) > 1 and min(df_Data1['SOC'])+0.5<df_Data1['SOC'][PeakIndex]<max(df_Data1['SOC'])-1:
  145. return df_Data1['AhSoc'][PeakIndex]
  146. else:
  147. if min(df_Data1['SOC'])+0.5<df_Data1['SOC'][PeakIndex]<max(df_Data1['SOC'])-1:
  148. df_Data1=df_Data1.drop([PeakIndex])
  149. elif df_Data1['SOC'][PeakIndex]>max(df_Data1['SOC'])-1:
  150. df_Data1=df_Data1[df_Data1['SOC']<(df_Data1['SOC'][PeakIndex]-1)]
  151. else:
  152. df_Data1=df_Data1[df_Data1['SOC']>(df_Data1['SOC'][PeakIndex]+0.5)]
  153. if len(df_Data1)>2:
  154. PeakIndex = df_Data1['DVDQ'].idxmax()
  155. df_Data2 = df_Data1[(df_Data1['SOC'] > (df_Data1['SOC'][PeakIndex] - 0.5)) & (df_Data1['SOC'] < (df_Data1['SOC'][PeakIndex] + 0.5))]
  156. if len(df_Data2) > 1 and min(df_Data1['SOC'])+0.5<df_Data1['SOC'][PeakIndex]<max(df_Data1['SOC'])-1:
  157. return df_Data1['AhSoc'][PeakIndex]
  158. else:
  159. return 0
  160. else:
  161. return 0
  162. else:
  163. return 0
  164. #三元电池一致性计算.................................................................................................................................
  165. def _ncm_uniform(self):
  166. column_name=['time','sn','cellsoc_diff','cellvolt_diff','cellmin_num','cellmax_num','cellvolt_rank']
  167. df_res=pd.DataFrame(columns=column_name)
  168. df_ram_last3=self.df_last3
  169. if df_ram_last3.empty:
  170. standingtime=0
  171. standingtime1=0
  172. standingtime2=0
  173. else:
  174. standingtime=df_ram_last3.loc[0,'standingtime']
  175. standingtime1=df_ram_last3.loc[0,'standingtime1']
  176. standingtime2=df_ram_last3.loc[0,'standingtime2']
  177. if abs(self.packcrnt[0])<0.01 and standingtime2>1:
  178. standingtime2=standingtime2+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
  179. else:
  180. pass
  181. for i in range(1,len(self.df_bms)-1):
  182. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1: #电流为0
  183. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  184. standingtime2=standingtime2+delttime
  185. self._celltemp_weight(i) #获取不同温度对应的静置时间
  186. if standingtime2>self.StandardStandingTime: #静置时间满足要求
  187. if abs(self.packcrnt[i+1]) >= 0.1:
  188. standingtime2=0
  189. cellvolt_now=self._cellvolt_get(i)
  190. cellvolt_min=min(cellvolt_now)
  191. cellvolt_max=max(cellvolt_now)
  192. cellvolt_last=self._cellvolt_get(i-1)
  193. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  194. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  195. cellvolt_sort=np.argsort(cellvolt_now)
  196. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  197. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  198. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  199. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  200. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  201. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  202. cellsoc_diff=cellsoc_max-cellsoc_min
  203. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  204. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  205. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  206. elif standingtime2>3600:
  207. cellvolt_now=self._cellvolt_get(i)
  208. cellvolt_min=min(cellvolt_now)
  209. cellvolt_max=max(cellvolt_now)
  210. cellvolt_last=self._cellvolt_get(i-1)
  211. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  212. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  213. standingtime2=0
  214. cellvolt_sort=np.argsort(cellvolt_now)
  215. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  216. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  217. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  218. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  219. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  220. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  221. cellsoc_diff=cellsoc_max-cellsoc_min
  222. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  223. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  224. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  225. elif i>=len(self.df_bms)-2:
  226. cellvolt_now=self._cellvolt_get(i)
  227. cellvolt_min=min(cellvolt_now)
  228. cellvolt_max=max(cellvolt_now)
  229. cellvolt_last=self._cellvolt_get(i-1)
  230. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  231. if 3<cellvolt_min<4.5 and 3<cellvolt_max<4.5 and deltvolt<0.005:
  232. standingtime2=0
  233. cellvolt_sort=np.argsort(cellvolt_now)
  234. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  235. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  236. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  237. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  238. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  239. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  240. cellsoc_diff=cellsoc_max-cellsoc_min
  241. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  242. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  243. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  244. break
  245. else:
  246. continue
  247. else:
  248. continue
  249. else:
  250. standingtime2=0
  251. continue
  252. #更新RAM的standingtime
  253. df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1,standingtime2]
  254. if df_res.empty: #返回计算结果
  255. return pd.DataFrame(), df_ram_last3
  256. else:
  257. return df_res, df_ram_last3
  258. #磷酸铁锂电池一致性计算.........................................................................................................................
  259. def _lfp_uniform(self):
  260. column_name=['time','sn','cellsoc_diff','cellvolt_diff','cellmin_num','cellmax_num','cellvolt_rank']
  261. df_res=pd.DataFrame(columns=column_name)
  262. df_ram_lfp1=pd.DataFrame(columns=self.df_bms.columns.tolist())
  263. chrg_start=[]
  264. chrg_end=[]
  265. charging=0
  266. df_ram_last3=self.df_last3
  267. if df_ram_last3.empty:
  268. standingtime=0
  269. standingtime1=0
  270. standingtime2=0
  271. else:
  272. standingtime=df_ram_last3.loc[0,'standingtime']
  273. standingtime1=df_ram_last3.loc[0,'standingtime1']
  274. standingtime2=df_ram_last3.loc[0,'standingtime2']
  275. if abs(self.packcrnt[0])<0.01 and standingtime2>1:
  276. standingtime2=standingtime2+(self.bmstime[0]-df_ram_last3.loc[0,'time3']).total_seconds()
  277. else:
  278. pass
  279. for i in range(1,len(self.df_bms)-1):
  280. #静置电压法计算电芯一致性
  281. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1: #电流为0
  282. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  283. standingtime2=standingtime2+delttime
  284. self._celltemp_weight(i) #获取不同温度对应的静置时间
  285. if standingtime2>self.StandardStandingTime: #静置时间满足要求
  286. if abs(self.packcrnt[i+1]) >= 0.1:
  287. standingtime2=0
  288. cellvolt_now=self._cellvolt_get(i)
  289. cellvolt_min=min(cellvolt_now)
  290. cellvolt_max=max(cellvolt_now)
  291. cellvolt_last=self._cellvolt_get(i-1)
  292. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  293. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  294. cellvolt_sort=np.argsort(cellvolt_now)
  295. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  296. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  297. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  298. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  299. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  300. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  301. cellsoc_diff=cellsoc_max-cellsoc_min
  302. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  303. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  304. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  305. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  306. # cellvolt_sort=np.argsort(cellvolt_now)
  307. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  308. # if not df_res.empty:
  309. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  310. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  311. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  312. # elif not self.df_uniform.empty:
  313. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  314. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  315. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  316. # else:
  317. # pass
  318. elif standingtime2>3600*6:
  319. cellvolt_now=self._cellvolt_get(i)
  320. cellvolt_min=min(cellvolt_now)
  321. cellvolt_max=max(cellvolt_now)
  322. cellvolt_last=self._cellvolt_get(i-1)
  323. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  324. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  325. standingtime2=0
  326. cellvolt_sort=np.argsort(cellvolt_now)
  327. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  328. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  329. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  330. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  331. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  332. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  333. cellsoc_diff=cellsoc_max-cellsoc_min
  334. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  335. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  336. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  337. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  338. # cellvolt_sort=np.argsort(cellvolt_now)
  339. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  340. # if not df_res.empty:
  341. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  342. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  343. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  344. # elif not self.df_uniform.empty:
  345. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  346. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  347. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  348. # else:
  349. # pass
  350. elif i>=len(self.df_bms)-2:
  351. standingtime2=0
  352. cellvolt_now=self._cellvolt_get(i)
  353. cellvolt_min=min(cellvolt_now)
  354. cellvolt_max=max(cellvolt_now)
  355. cellvolt_last=self._cellvolt_get(i-1)
  356. deltvolt=max(abs(cellvolt_now-cellvolt_last))
  357. if 2 < cellvolt_max < self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and deltvolt<0.003:
  358. cellvolt_sort=np.argsort(cellvolt_now)
  359. cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  360. cellmin_num=list(cellvolt_now).index(cellvolt_min)+1
  361. cellmax_num=list(cellvolt_now).index(cellvolt_max)+1
  362. cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
  363. cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
  364. cellvolt_diff=(cellvolt_max-cellvolt_min)*1000
  365. cellsoc_diff=cellsoc_max-cellsoc_min
  366. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  367. cellvolt_diff=eval(format(cellvolt_diff,'.0f'))
  368. df_res.loc[len(df_res)]=[self.bmstime[i], self.sn, cellsoc_diff, cellvolt_diff, cellmin_num, cellmax_num, str(cellvolt_rank)]
  369. # elif 2<cellvolt_max<4.5 and 2<cellvolt_min<4.5 and deltvolt<0.005:
  370. # cellvolt_sort=np.argsort(cellvolt_now)
  371. # cellvolt_rank=list(np.argsort(cellvolt_sort)+1)
  372. # if not df_res.empty:
  373. # df_res.loc[len(df_res)]=df_res.loc[len(df_res)-1]
  374. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  375. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  376. # elif not self.df_uniform.empty:
  377. # df_res.loc[len(df_res)]=self.df_uniform.iloc[-1]
  378. # df_res.loc[len(df_res)-1,'cellvolt_rank']=str(cellvolt_rank)
  379. # df_res.loc[len(df_res)-1,'time']=self.bmstime[i]
  380. # else:
  381. # pass
  382. else:
  383. pass
  384. else:
  385. pass
  386. else:
  387. standingtime2=0
  388. pass
  389. if i==len(self.df_bms)-2 and abs(self.packcrnt[i+1]) < 0.1: #数据中断后仍在静置,将最后一条数据写入RAM
  390. df_ram_lfp1.loc[0]=self.df_bms.iloc[-1]
  391. else:
  392. pass
  393. #获取DVDQ算法所需数据——开始............................................................................................................
  394. if charging==0: #判断充电开始
  395. if self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.bms_soc[i]<40: #充电开始
  396. charging=1
  397. if len(chrg_start)>len(chrg_end):
  398. chrg_start[-1]=i
  399. else:
  400. chrg_start.append(i)
  401. else:
  402. pass
  403. else: #充电中
  404. if (self.bmstime[i+1]-self.bmstime[i]).total_seconds()>180 or (self.packcrnt[i]<-self.param.Capacity and self.packcrnt[i+1]<-self.param.Capacity): #如果充电过程中时间间隔>180s,则舍弃该次充电
  405. chrg_start.remove(chrg_start[-1])
  406. charging=0
  407. continue
  408. elif self.packcrnt[i]<=-1 and self.packcrnt[i-1]<=-1 and self.packcrnt[i+1]>-1: #判断电流波动时刻
  409. cellvolt_now=self._cellvolt_get(i+1)
  410. if max(cellvolt_now)>self.param.CellFullChrgVolt-0.1: #电压>满充电压
  411. chrg_end.append(i+1)
  412. charging=0
  413. continue
  414. else:
  415. pass
  416. elif self.packcrnt[i+1]>-0.1 and self.packcrnt[i]>-0.1: #判断充电结束
  417. charging=0
  418. if len(chrg_start)>len(chrg_end):
  419. if self.bms_soc[i]>90:
  420. chrg_end.append(i)
  421. else:
  422. chrg_start.remove(chrg_start[-1])
  423. continue
  424. else:
  425. continue
  426. elif i==len(self.packcrnt)-2 and self.packcrnt[i+1]<-1 and self.packcrnt[i]<-1:
  427. charging=0
  428. if len(chrg_start)>len(chrg_end) and self.bms_soc[i]>90: #soc>90
  429. chrg_end.append(i)
  430. continue
  431. else:
  432. df_ram_lfp1=self.df_bms.iloc[chrg_start[-1]:]
  433. chrg_start.remove(chrg_start[-1])
  434. continue
  435. else:
  436. continue
  437. if chrg_end: #DVDQ方法计算soc差
  438. peaksoc_list=[]
  439. for i in range(len(chrg_end)):
  440. peaksoc_list = []
  441. self._celltemp_weight(chrg_start[i])
  442. if min(self.celltemp)>10:
  443. for j in range(1, self.param.CellVoltNums + 1):
  444. cellvolt = self._singlevolt_get(i,j,2) #取单体电压j的所有电压值
  445. cellvolt = list(cellvolt[chrg_start[i]:chrg_end[i]])
  446. time = list(self.bmstime[chrg_start[i]:chrg_end[i]])
  447. packcrnt = list(self.packcrnt[chrg_start[i]:chrg_end[i]])
  448. soc = list(self.bms_soc[chrg_start[i]:chrg_end[i]])
  449. peaksoc = self._dvdq_peak(time, soc, cellvolt, packcrnt)
  450. if peaksoc>1:
  451. peaksoc_list.append(peaksoc) #计算到达峰值点的累计Soc
  452. else:
  453. pass
  454. if len(peaksoc_list)>self.param.CellVoltNums/2:
  455. peaksoc_max=max(peaksoc_list)
  456. peaksoc_min=min(peaksoc_list)
  457. peaksoc_maxnum=peaksoc_list.index(peaksoc_min)+1
  458. peaksoc_minnum=peaksoc_list.index(peaksoc_max)+1
  459. cellsoc_diff=peaksoc_max-peaksoc_min
  460. cellsoc_diff=eval(format(cellsoc_diff,'.1f'))
  461. if not df_res.empty:
  462. cellvolt_rank=df_res.iloc[-1]['cellvolt_rank']
  463. df_res.loc[len(df_res)]=[self.bmstime[chrg_start[i]], self.sn, cellsoc_diff, 0, peaksoc_minnum, peaksoc_maxnum, cellvolt_rank]
  464. elif not self.df_uniform.empty:
  465. cellvolt_rank=self.df_uniform.iloc[-1]['cellvolt_rank']
  466. df_res.loc[len(df_res)]=[self.bmstime[chrg_start[i]], self.sn, cellsoc_diff, 0, peaksoc_minnum, peaksoc_maxnum, cellvolt_rank]
  467. else:
  468. pass
  469. else:
  470. pass
  471. else:
  472. pass
  473. #更新RAM的standingtime
  474. df_ram_last3.loc[0]=[self.sn,self.bmstime[len(self.bmstime)-1],standingtime,standingtime1,standingtime2]
  475. if df_res.empty:
  476. return pd.DataFrame(), df_ram_last3, df_ram_lfp1
  477. else:
  478. df_res.sort_values(by='time', ascending=True, inplace=True)
  479. return df_res, df_ram_last3, df_ram_lfp1