CBMSBatInterShort.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import BatParam
  5. class BatInterShort:
  6. def __init__(self,sn,celltype,df_bms,df_volt,df_temp,df_accum): #参数初始化
  7. self.sn=sn
  8. self.celltype=celltype
  9. CellVoltNums=int(df_volt.loc[5,'单体电池总数'])
  10. if CellVoltNums==110:
  11. self.celltype=99
  12. else:
  13. self.celltype==100
  14. self.param=BatParam.BatParam(self.celltype)
  15. self.df_volt=df_volt
  16. self.df_temp=df_temp
  17. self.df_bms=df_bms
  18. self.packcrnt=(df_volt['可充电储能装置电流(A)'].astype('float'))*self.param.PackCrntDec
  19. self.packvolt=df_volt['可充电储能装置电压(V)'].astype('float')
  20. self.bms_soc=df_bms['SOC']
  21. self.bmsstat=df_bms['充电状态']
  22. self.bmstime= pd.to_datetime(df_volt['上报时间'], format='%Y-%m-%d %H:%M:%S')
  23. self.param.CellVoltNums=CellVoltNums
  24. self.param.CellTempNums=int(df_temp.loc[5,'可充电储能温度探针个数'])
  25. def intershort(self):
  26. if self.celltype==1 or self.celltype==2 or self.celltype==3 or self.celltype==4 or self.celltype==100:
  27. df_res=self._ncm_intershort()
  28. return df_res
  29. elif self.celltype==99:
  30. df_res=self._lfp_intershort()
  31. return df_res
  32. else:
  33. return pd.DataFrame()
  34. #定义滑动滤波函数....................................................................................
  35. def _np_move_avg(self,a, n, mode="same"):
  36. return (np.convolve(a, np.ones((n,)) / n, mode=mode))
  37. #寻找当前行数据的最小温度值.............................................................................
  38. def _celltemp_weight(self,num):
  39. celltemp = []
  40. for j in range(1, self.param.CellTempNums+1):
  41. s = str(j)
  42. celltemp.append(self.df_temp.loc[num,s+'.0'])
  43. celltemp=np.mean(celltemp)
  44. self.celltemp=celltemp
  45. if self.celltype==99:
  46. if celltemp>=20:
  47. self.tempweight=1
  48. self.StandardStandingTime=3600
  49. elif celltemp>=10:
  50. self.tempweight=0.6
  51. self.StandardStandingTime=7200
  52. elif celltemp>=5:
  53. self.tempweight=0.
  54. self.StandardStandingTime=7200
  55. else:
  56. self.tempweight=0.1
  57. self.StandardStandingTime=10800
  58. else:
  59. if celltemp>=20:
  60. self.tempweight=1
  61. self.StandardStandingTime=3600
  62. elif celltemp>=10:
  63. self.tempweight=0.8
  64. self.StandardStandingTime=3600
  65. elif celltemp>=5:
  66. self.tempweight=0.6
  67. self.StandardStandingTime=7200
  68. else:
  69. self.tempweight=0.2
  70. self.StandardStandingTime=10800
  71. #获取当前行所有电压数据........................................................................................
  72. def _cellvolt_get(self,num):
  73. cellvolt=[]
  74. for j in range(1, self.param.CellVoltNums+1):
  75. s = str(j)
  76. cellvolt.append(self.df_volt.loc[num, s+'.0'])
  77. return cellvolt
  78. #获取当前行所有soc差...........................................................................................
  79. def _celldeltsoc_get(self,num,dict_baltime,capacity):
  80. cellsoc=[]
  81. celldeltsoc=[]
  82. for j in range(1, self.param.CellVoltNums+1): #获取每个电芯电压对应的SOC值
  83. cellvolt=self.df_volt.loc[num,str(j)+'.0']
  84. ocv_soc=np.interp(cellvolt,self.param.LookTab_OCV,self.param.LookTab_SOC)
  85. if j in dict_baltime.keys():
  86. ocv_soc=ocv_soc+dict_baltime[j]*self.param.BalCurrent/(capacity*3600) #补偿均衡电流
  87. else:
  88. pass
  89. cellsoc.append(ocv_soc)
  90. if self.celltype==1 or self.celltype==2:
  91. consum_num=7
  92. cellsoc1=cellsoc[:self.param.CellVoltNums-consum_num] #切片,将bms耗电的电芯和非耗电的电芯分离开
  93. cellsocmean1=(sum(cellsoc1)-max(cellsoc1)-min(cellsoc1))/(len(cellsoc1)-2)
  94. cellsoc2=cellsoc[self.param.CellVoltNums-consum_num:]
  95. cellsocmean2=(sum(cellsoc2)-max(cellsoc2)-min(cellsoc2))/(len(cellsoc2)-2)
  96. for j in range(len(cellsoc)): #计算每个电芯的soc差
  97. if j<self.param.CellVoltNums-consum_num:
  98. celldeltsoc.append(cellsoc[j]-cellsocmean1)
  99. else:
  100. celldeltsoc.append(cellsoc[j]-cellsocmean2)
  101. return celldeltsoc
  102. else:
  103. cellsocmean=(sum(cellsoc)-max(cellsoc)-min(cellsoc))/(len(cellsoc)-2)
  104. for j in range(len(cellsoc)): #计算每个电芯的soc差
  105. celldeltsoc.append(cellsoc[j]-cellsocmean)
  106. return celldeltsoc
  107. #获取所有电芯的As差
  108. def _cellDeltAs_get(self,chrg_st,chrg_end,dict_baltime):
  109. cellAs=[]
  110. celldeltAs=[]
  111. for j in range(1, self.param.CellVoltNums+1): #获取每个电芯电压>峰值电压的充入As数
  112. if j in dict_baltime.keys(): #补偿均衡电流
  113. As=-self.param.BalCurrent*dict_baltime[j]
  114. else:
  115. As=0
  116. As_tatol=0
  117. symbol=0
  118. for m in range(chrg_st,chrg_end):
  119. As=As-self.packcrnt[m]*(self.bmstime[m]-self.bmstime[m-1]).total_seconds()
  120. if symbol<5:
  121. if self.df_volt.loc[m, str(j)+'.0']/1000>self.param.PeakCellVolt[symbol]:
  122. As_tatol=As_tatol+As
  123. symbol=symbol+1
  124. else:
  125. continue
  126. else:
  127. cellAs.append(As_tatol/5)
  128. break
  129. if cellAs:
  130. cellAsmean=(sum(cellAs)-max(cellAs)-min(cellAs))/(len(cellAs)-2)
  131. for j in range(len(cellAs)): #计算每个电芯的soc差
  132. celldeltAs.append(cellAs[j]-cellAsmean)
  133. return celldeltAs
  134. #计算每个电芯的均衡时长..........................................................................................................................
  135. def _bal_time(self,dict_bal):
  136. dict_baltime={}
  137. dict_baltime1={}
  138. for key in dict_bal:
  139. count=1
  140. x=eval(key)
  141. while x>0:
  142. if x & 1==1: #判断最后一位是否为1
  143. if count in dict_baltime.keys():
  144. dict_baltime[count] = dict_baltime[count] + dict_bal[key]
  145. else:
  146. dict_baltime[count] = dict_bal[key]
  147. else:
  148. pass
  149. count += 1
  150. x >>= 1 #右移一位
  151. dict_baltime=dict(sorted(dict_baltime.items(),key=lambda dict_baltime:dict_baltime[0]))
  152. for key in dict_baltime: #解析均衡的电芯编号
  153. if self.celltype==1: #科易6040
  154. if key<14:
  155. dict_baltime1[key]=dict_baltime[key]
  156. elif key<18:
  157. dict_baltime1[key-1]=dict_baltime[key]
  158. else:
  159. dict_baltime1[key-3]=dict_baltime[key]
  160. elif self.celltype==1: #科易4840
  161. if key<4:
  162. dict_baltime1[key-1]=dict_baltime[key]
  163. elif key<8:
  164. dict_baltime1[key-1]=dict_baltime[key]
  165. elif key<14:
  166. dict_baltime1[key-3]=dict_baltime[key]
  167. elif key<18:
  168. dict_baltime1[key-4]=dict_baltime[key]
  169. else:
  170. dict_baltime1[key-6]=dict_baltime[key]
  171. else:
  172. dict_baltime1=dict_baltime
  173. return dict_baltime1
  174. #三元电池的内短路电流计算...........................................................................................................................................................
  175. def _ncm_intershort(self):
  176. column_name=['time_st', 'time_sp', 'sn', 'method','short_current','baltime']
  177. df_res=pd.DataFrame(columns=column_name)
  178. df_res1=pd.DataFrame()
  179. if not self.df_volt.empty:
  180. capacity=self.param.Capacity
  181. standingtime=0
  182. standingtime1=0
  183. firsttime=1
  184. firsttime1=1
  185. dict_bal={}
  186. dict_bal1={}
  187. for i in range(2,len(self.df_volt)-2):
  188. if firsttime1==0: #满电静置算法--计算均衡状态对应的均衡时间
  189. try:
  190. balstat=int(self.df_bms.loc[i,'单体均衡状态'])
  191. if balstat>0.5:
  192. bal_step=(self.bmstime[i+1]-self.bmstime[i]).total_seconds() #均衡步长
  193. bal_step=int(bal_step)
  194. if str(balstat) in dict_bal1.keys():
  195. dict_bal1[str(balstat)]=dict_bal1[str(balstat)]+bal_step
  196. else:
  197. dict_bal1[str(balstat)]=bal_step
  198. else:
  199. pass
  200. except:
  201. dict_bal1={}
  202. else:
  203. pass
  204. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1 and abs(self.packcrnt[i+1]) < 0.1:
  205. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  206. standingtime=standingtime+delttime
  207. standingtime1=standingtime1+delttime
  208. self._celltemp_weight(i)
  209. #静置法计算内短路-开始.....................................................................................................................................
  210. if firsttime==1:
  211. if standingtime>self.StandardStandingTime: #静置时间满足要求
  212. dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
  213. deltsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
  214. time_last=self.bmstime[i]
  215. firsttime=0
  216. standingtime=0
  217. else:
  218. pass
  219. elif standingtime>3600*12:
  220. cellvolt=self._cellvolt_get(i)
  221. if 3<max(cellvolt)<4.5:
  222. standingtime=0
  223. dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
  224. deltsoc_now=self._celldeltsoc_get(i,dict_baltime,capacity)
  225. time_now=self.bmstime[i]
  226. list_sub=[a-b for a, b in zip(deltsoc_now, deltsoc_last)]
  227. list_pud=[0.01*capacity*3600*1000/(time_now-time_last).total_seconds()]*self.param.CellVoltNums
  228. leak_current=[a*b for a,b in zip(list_sub,list_pud)]
  229. leak_current=np.array(leak_current)
  230. leak_current=np.round(leak_current,3)
  231. leak_current=list(leak_current)
  232. df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)] #计算结果存入Dataframe
  233. df_res1[time_now]=leak_current
  234. time_last=time_now #更新时间
  235. deltsoc_last=deltsoc_now #更新soc差
  236. dict_bal={}
  237. else:
  238. try:
  239. balstat=int(self.df_bms.loc[i,'单体均衡状态'])
  240. if balstat>0.5:
  241. bal_step=(self.bmstime[i+1]-self.bmstime[i]).total_seconds() #均衡步长
  242. bal_step=int(bal_step)
  243. if str(balstat) in dict_bal.keys():
  244. dict_bal[str(balstat)]=dict_bal[str(balstat)]+bal_step
  245. else:
  246. dict_bal[str(balstat)]=bal_step
  247. else:
  248. pass
  249. except:
  250. dict_bal={}
  251. #满电静置法计算内短路-开始.....................................................................................................................................................
  252. if standingtime1>self.StandardStandingTime:
  253. cellvolt=self._cellvolt_get(i)
  254. if 3<max(cellvolt)<4.5:
  255. if abs(self.packcrnt[i+2]) >= 0.1:
  256. standingtime1=0
  257. cellvolt_now1=self._cellvolt_get(i)
  258. cellsoc_now1=np.interp(max(cellvolt_now1),self.param.LookTab_OCV,self.param.LookTab_SOC)
  259. if cellsoc_now1>=self.param.FullChrgSoc-50:
  260. if firsttime1==1:
  261. dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
  262. deltsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
  263. time_last1=self.bmstime[i]
  264. firsttime1=0
  265. else:
  266. dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
  267. time_now1=self.bmstime[i]
  268. if (time_now1-time_last1).total_seconds()>3600*24:
  269. deltsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
  270. list_sub1=[a-b for a, b in zip(deltsoc_now1, deltsoc_last1)]
  271. list_pud1=[0.01*capacity*3600*1000/(time_now1-time_last1).total_seconds()]*self.param.CellVoltNums
  272. leak_current1=[a*b for a,b in zip(list_sub1,list_pud1)]
  273. leak_current1=np.array(leak_current1)
  274. leak_current1=np.round(leak_current1,3)
  275. leak_current1=list(leak_current1)
  276. df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)] #计算结果存入Dataframe
  277. df_res1[time_now1]=leak_current1
  278. time_last1=time_now1 #更新时间
  279. deltsoc_last1=deltsoc_now1 #更新soc差
  280. dict_bal1={}
  281. else:
  282. pass
  283. else:
  284. pass
  285. else:
  286. pass
  287. else:
  288. pass
  289. else:
  290. dict_bal={}
  291. firsttime=1
  292. standingtime=0
  293. standingtime1=0
  294. pass
  295. #内短路结果画图.................................................................................................
  296. if not df_res1.empty:
  297. ax=df_res1.plot(marker='*',figsize=(10,5))
  298. plt.xlabel('电芯序列')
  299. plt.ylabel('内短路指数')
  300. plt.title(str(self.sn))
  301. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  302. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  303. plt.legend()
  304. plt.show()
  305. fig = ax.get_figure()
  306. fig.savefig('./'+str(self.sn)+'漏电流1.png')
  307. if df_res.empty: #返回计算结果
  308. return pd.DataFrame()
  309. else:
  310. return df_res
  311. #磷酸铁锂电池内短路计算程序.............................................................................................................................
  312. def _lfp_intershort(self):
  313. column_name=['time_st', 'time_sp', 'sn', 'method','short_current','baltime']
  314. df_res=pd.DataFrame(columns=column_name)
  315. df_res1=pd.DataFrame()
  316. if not self.df_bms.empty:
  317. capacity=self.param.Capacity
  318. standingtime=0
  319. standingtime1=0
  320. firsttime=1
  321. firsttime1=1
  322. dict_bal={}
  323. dict_bal1={}
  324. chrg_start=[]
  325. chrg_end=[]
  326. dict_bal_list=[]
  327. charging=0
  328. for i in range(3,len(self.df_bms)-3):
  329. #静置法计算内短路..........................................................................................................................
  330. if firsttime1==0: #满电静置算法--计算均衡状态对应的均衡时间
  331. try:
  332. balstat=int(self.df_bms.loc[i,'单体均衡状态'])
  333. if balstat>0.5:
  334. bal_step=(self.bmstime[i+1]-self.bmstime[i]).total_seconds() #均衡步长
  335. bal_step=int(bal_step)
  336. if str(balstat) in dict_bal1.keys():
  337. dict_bal1[str(balstat)]=dict_bal1[str(balstat)]+bal_step
  338. else:
  339. dict_bal1[str(balstat)]=bal_step
  340. else:
  341. pass
  342. except:
  343. dict_bal1={}
  344. else:
  345. pass
  346. if abs(self.packcrnt[i]) < 0.1 and abs(self.packcrnt[i-1]) < 0.1 and abs(self.packcrnt[i+1]) < 0.1:
  347. delttime=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  348. standingtime=standingtime+delttime
  349. standingtime1=standingtime1+delttime
  350. self._celltemp_weight(i)
  351. #静置法计算内短路-开始.....................................................................................................................................
  352. if firsttime==1:
  353. if standingtime>self.StandardStandingTime: #静置时间满足要求
  354. cellvolt=self._cellvolt_get(i)
  355. if max(cellvolt)<self.param.OcvInflexionBelow-0.002 and 3<max(cellvolt)<4.5:
  356. dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
  357. deltsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
  358. time_last=self.bmstime[i]
  359. firsttime=0
  360. standingtime=0
  361. else:
  362. pass
  363. else:
  364. pass
  365. elif standingtime>3600*12:
  366. cellvolt=self._cellvolt_get(i)
  367. if max(cellvolt)<self.param.OcvInflexionBelow-0.002 and 3<max(cellvolt)<4.5:
  368. standingtime=0
  369. dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
  370. deltsoc_now=self._celldeltsoc_get(i, dict_baltime,capacity) #获取每个电芯的SOC差
  371. time_now=self.bmstime[i]
  372. list_sub=[a-b for a, b in zip(deltsoc_now, deltsoc_last)]
  373. list_pud=[0.01*capacity*3600*1000/(time_now-time_last).total_seconds()]*self.param.CellVoltNums
  374. leak_current=[a*b for a,b in zip(list_sub,list_pud)]
  375. leak_current=np.array(leak_current)
  376. leak_current=np.round(leak_current,3)
  377. leak_current=list(leak_current)
  378. df_res.loc[len(df_res)]=[time_last,time_now,self.sn,1,str(leak_current),str(dict_baltime)] #计算结果存入Dataframe
  379. df_res1[time_now]=leak_current
  380. time_last=time_now #更新时间
  381. deltsoc_last=deltsoc_now #更新soc差
  382. dict_bal={}
  383. else:
  384. pass
  385. else:
  386. try:
  387. balstat=int(self.df_bms.loc[i,'单体均衡状态'])
  388. if balstat>0.5:
  389. bal_step=(self.bmstime[i+1]-self.bmstime[i]).total_seconds() #均衡步长
  390. bal_step=int(bal_step)
  391. if str(balstat) in dict_bal.keys():
  392. dict_bal[str(balstat)]=dict_bal[str(balstat)]+bal_step
  393. else:
  394. dict_bal[str(balstat)]=bal_step
  395. else:
  396. pass
  397. except:
  398. dict_bal={}
  399. #非平台区间静置法计算内短路-开始.....................................................................................................................................................
  400. if standingtime1>self.StandardStandingTime:
  401. if abs(self.packcrnt[i+2]) >= 0.1:
  402. standingtime1=0
  403. cellvolt_now1=self._cellvolt_get(i)
  404. if max(cellvolt_now1)<self.param.OcvInflexionBelow-0.002 and 3<max(cellvolt)<4.5:
  405. if firsttime1==1:
  406. dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
  407. deltsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
  408. time_last1=self.bmstime[i]
  409. firsttime1=0
  410. else:
  411. dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
  412. deltsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
  413. time_now1=self.bmstime[i]
  414. time_now1=self.bmstime[i]
  415. if abs(max(deltsoc_now1)-max(deltsoc_last1))<10 and (time_now1-time_last1).total_seconds()>3600*24:
  416. list_sub1=[a-b for a, b in zip(deltsoc_now1, deltsoc_last1)]
  417. list_pud1=[0.01*capacity*3600*1000/(time_now1-time_last1).total_seconds()]*self.param.CellVoltNums
  418. leak_current1=[a*b for a,b in zip(list_sub1,list_pud1)]
  419. leak_current1=np.array(leak_current1)
  420. leak_current1=np.round(leak_current1,3)
  421. leak_current1=list(leak_current1)
  422. df_res.loc[len(df_res)]=[time_last1,time_now1,self.sn,2,str(leak_current1),str(dict_baltime1)] #计算结果存入Dataframe
  423. df_res1[time_now1]=leak_current1
  424. time_last1=time_now1 #更新时间
  425. deltsoc_last1=deltsoc_now1 #更新soc差
  426. dict_bal1={}
  427. else:
  428. pass
  429. else:
  430. pass
  431. else:
  432. pass
  433. else:
  434. pass
  435. else:
  436. dict_bal={}
  437. firsttime=1
  438. standingtime=0
  439. standingtime1=0
  440. pass
  441. #获取充电数据——开始..............................................................................................................
  442. try:
  443. balstat=int(self.df_bms.loc[i,'单体均衡状态']) #统计均衡状态
  444. if balstat>0.5:
  445. bal_step=(self.bmstime[i+1]-self.bmstime[i]).total_seconds() #均衡步长
  446. bal_step=int(bal_step)
  447. if str(balstat) in dict_bal3.keys():
  448. dict_bal3[str(balstat)]=dict_bal3[str(balstat)]+bal_step
  449. else:
  450. dict_bal3[str(balstat)]=bal_step
  451. else:
  452. pass
  453. except:
  454. dict_bal3={}
  455. if charging==0:
  456. if self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.packcrnt[i+2]<=-1 and float(self.bms_soc[i].strip('%'))<40: #判断充电开始
  457. cellvolt_now=self._cellvolt_get(i)
  458. if min(cellvolt_now)<self.param.CellFullChrgVolt-0.15:
  459. charging=1
  460. if len(chrg_start)>len(chrg_end):
  461. chrg_start[-1]=i
  462. else:
  463. chrg_start.append(i)
  464. else:
  465. pass
  466. else:
  467. pass
  468. else: #充电中
  469. if (self.bmstime[i+1]-self.bmstime[i]).total_seconds()>180 or (self.packcrnt[i]>self.param.Capacity/3 and self.packcrnt[i+1]>self.param.Capacity/3): #如果充电过程中时间间隔>180s,则舍弃该次充电
  470. chrg_start.remove(chrg_start[-1])
  471. charging=0
  472. continue
  473. elif self.packcrnt[i]<=-1 and self.packcrnt[i+1]<=-1 and self.packcrnt[i+2]<-1:
  474. cellvolt_now=self._cellvolt_get(i)
  475. if min(cellvolt_now)>self.param.CellFullChrgVolt-0.13: #电压>满充电压-0.13V,即3.37V
  476. self._celltemp_weight(i)
  477. if i-chrg_start[-1]>10 and self.celltemp>10:
  478. chrg_end.append(i+1)
  479. dict_bal_list.append(dict_bal3)
  480. dict_bal3={}
  481. charging=0
  482. continue
  483. else:
  484. chrg_start.remove(chrg_start[-1])
  485. charging=0
  486. continue
  487. else:
  488. pass
  489. else:
  490. pass
  491. #基于充电数据计算单体电芯的漏电流..........................................................................................................
  492. if len(chrg_end)>1:
  493. for i in range(len(chrg_end)):
  494. if i<1:
  495. dict_baltime={}
  496. deltAs_last=self._cellDeltAs_get(chrg_start[i],chrg_end[i],dict_baltime)
  497. time_last=self.bmstime[chrg_end[i]]
  498. else:
  499. dict_baltime=self._bal_time(dict_bal_list[i]) #获取每个电芯的均衡时间
  500. deltAs_now=self._cellDeltAs_get(chrg_start[i],chrg_end[i],dict_baltime) #获取每个电芯的As差
  501. time_now=self.bmstime[chrg_end[i]]
  502. list_sub=[a-b for a, b in zip(deltAs_now, deltAs_last)]
  503. list_pud=[-1000/(time_now-time_last).total_seconds()]*self.param.CellVoltNums
  504. leak_current=[a*b for a,b in zip(list_sub,list_pud)]
  505. leak_current=np.array(leak_current)
  506. leak_current=np.round(leak_current,3)
  507. leak_current=list(leak_current)
  508. df_res.loc[len(df_res)]=[time_last,time_now,self.sn,3,str(leak_current),str(dict_baltime)] #计算结果存入Dataframe
  509. deltAs_last=deltAs_now
  510. time_last=time_now
  511. else:
  512. pass
  513. #漏电流结果画图...........................................................................................
  514. if not df_res1.empty:
  515. ax=df_res1.plot(marker='*',figsize=(10,5))
  516. plt.xlabel('电芯序列')
  517. plt.ylabel('内短路指数')
  518. plt.title(str(self.sn))
  519. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  520. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  521. plt.legend()
  522. plt.show()
  523. fig = ax.get_figure()
  524. fig.savefig('./'+str(self.sn)+'漏电流1.png')
  525. if df_res.empty:
  526. return pd.DataFrame()
  527. else:
  528. return df_res