CBMSBatDiag.py 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. import pandas as pd
  2. import numpy as np
  3. import datetime
  4. from USER.SPF.alibaba.Common import BatParam
  5. class BatDiag:
  6. def __init__(self,sn,celltype,df_bms,df_soh,df_soc,df_uniform,df_diag_ram): #参数初始化
  7. self.sn=sn
  8. self.celltype=celltype
  9. self.param=BatParam.BatParam(celltype)
  10. self.df_bms=df_bms
  11. self.df_soh=df_soh
  12. self.df_soc=df_soc
  13. self.df_uniform=df_uniform
  14. self.df_diag_ram=df_diag_ram.copy()
  15. self.packcrnt=df_bms['PackCrnt']*self.param.PackCrntDec
  16. self.packvolt=df_bms['PackVolt']
  17. self.bms_soc=df_bms['PackSOC']
  18. self.bmstime= pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
  19. self.cellvolt_name=['CellVolt'+str(x) for x in range(1,self.param.CellVoltNums+1)]
  20. self.celltemp_name=['CellTemp'+str(x) for x in range(1,self.param.CellTempNums+1)]
  21. def diag(self):
  22. if len(self.df_bms)>1:
  23. if self.celltype<=50:
  24. df_res=self._ncm_diag()
  25. return df_res
  26. else:
  27. df_res=self._ncm_diag()
  28. return df_res
  29. else:
  30. return pd.DataFrame()
  31. #定义滑动滤波函数.............................................................................................
  32. def _np_move_avg(self,a, n, mode="same"):
  33. return (np.convolve(a, np.ones((n,)) / n, mode=mode))
  34. #寻找当前行数据的所有温度值...................................................................................
  35. def _celltemp_get(self,num):
  36. celltemp = list(self.df_bms.loc[num,self.celltemp_name])
  37. return celltemp
  38. #获取当前行所有电压数据............................................................................................
  39. def _cellvolt_get(self,num):
  40. cellvolt = list(self.df_bms.loc[num,self.cellvolt_name])
  41. return cellvolt
  42. #..........................................三元电池诊断功能..................................................................
  43. def _ncm_diag(self):
  44. #参数初始化
  45. bmssoc_st=float(self.bms_soc[0]) #SOC卡滞初始参数
  46. ah_accum=0 #SOC卡滞初始参数
  47. as_chg=0 #过流诊断初始参数
  48. as_dis=0 #过流诊断初始参数
  49. time1=self.bmstime[0] #温升速率初始参数
  50. temp1=np.array(self._celltemp_get(0)) #温升速率初始参数
  51. temprate_cnt=0
  52. ot_time=0
  53. ut_time=0
  54. dt_time=0
  55. cov_time=0
  56. cuv_time=0
  57. cdv_time=0
  58. pov_time=0
  59. puv_time=0
  60. vv_time=0
  61. tv_time=0
  62. time_sp='0000-00-00 00:00:00'
  63. for i in range(1,len(self.df_bms)):
  64. time=self.bmstime[i]
  65. #温度诊断功能.............................................................................................................
  66. celltemp0=self._celltemp_get(i-1)
  67. celltemp1=self._celltemp_get(i)
  68. celltempmin0=min(celltemp0)
  69. celltempmin1=min(celltemp1)
  70. celltempmax0=max(celltemp0)
  71. celltempmax1=max(celltemp1)
  72. #温度有效性判断............................................................................................
  73. if not 2 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  74. if celltempmax0>self.param.CellTempUpLmt or celltempmin0<self.param.CellTempLwLmt:
  75. tv_time=tv_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  76. if tv_time>55:
  77. celltempvalid=0
  78. faultcode=2
  79. faultlv=2
  80. cellnum1=np.where(np.array(celltemp1)<self.param.CellTempLwLmt)[0]+1
  81. cellnum2=np.where(np.array(celltemp1)>self.param.CellTempUpLmt)[0]+1
  82. cellnum=list(cellnum1)+list(cellnum2)
  83. faultinfo='电芯温度{}无效'.format(cellnum)
  84. faultadvice='丢失温度信息,无法全面监控电池安全;请停止充放电,并检修电池采样系统及数据传输系统'
  85. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  86. else:
  87. pass
  88. else: #不作处理
  89. celltempvalid=1
  90. tv_time=0
  91. else: #ram当前故障中有该故障,则判断是否退出该故障
  92. if celltempmax0<self.param.CellTempUpLmt-10 and celltempmin0>self.param.CellTempLwLmt+10:
  93. celltempvalid=1
  94. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==2].index[0], 'time_sp'] = time
  95. else:
  96. celltempvalid=0
  97. if celltempvalid==1:
  98. #过温判断.............................................................................................................
  99. if not 4 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  100. if celltempmax0>self.param.CellTempHighLv2 and celltempmax1>self.param.CellTempHighLv2: #二级高温进入
  101. ot_time=ot_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  102. if ot_time>self.param.temp_time:
  103. faultcode=4
  104. faultlv=3
  105. cellnum=np.where(np.array(celltemp1)>self.param.CellTempHighLv2)[0]+1
  106. faultinfo='电芯温度{}过温'.format(list(cellnum))
  107. faultadvice='高温下充放电,会导致容量衰减过快,并存在热失控风险;请停止充放电,开启电池冷却功能,并通知电池技术人员介入分析'
  108. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  109. else:
  110. pass
  111. else:
  112. ot_time=0
  113. else: #ram当前故障中有该故障,则判断是否退出该故障
  114. if celltempmax0<self.param.CellTempHighLv1-5 and celltempmax1<self.param.CellTempHighLv1-5: #二级高温恢复
  115. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==4].index[0], 'time_sp'] = time
  116. else:
  117. pass
  118. #欠温判断.................................................................................................................
  119. if not 6 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  120. if celltempmin0<self.param.CellTempLowLv2 and celltempmin1<self.param.CellTempLowLv2: #二级低温进入
  121. ut_time=ut_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  122. if ut_time>self.param.temp_time:
  123. faultcode=6
  124. faultlv=3
  125. cellnum=np.where(np.array(celltemp1)<self.param.CellTempLowLv2)[0]+1
  126. faultinfo='电芯温度{}过低'.format(list(cellnum))
  127. faultadvice='低温下充电,会导致析锂,存在电池安全与寿命衰减过快风险;请停止充放电,并开启电池加热功能'
  128. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  129. else:
  130. pass
  131. else:
  132. ut_time=0
  133. else: #ram当前故障中有该故障,则判断是否退出该故障
  134. if celltempmax0>self.param.CellTempLowLv1+2 and celltempmax1>self.param.CellTempLowLv1+2: #二级高温恢复
  135. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==6].index[0], 'time_sp'] = time
  136. else:
  137. pass
  138. #温差判断.............................................................................................................................
  139. if not 8 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  140. if (celltempmax0-celltempmin0)>self.param.CellTempDiffLv2 and (celltempmax1-celltempmax0)>self.param.CellTempDiffLv2: #二级温差进入
  141. dt_time=dt_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  142. if dt_time>self.param.temp_time:
  143. faultcode=8
  144. faultlv=3
  145. faultinfo='电芯温度{}和{}温差大'.format(celltemp1.index(celltempmax1)+1,celltemp1.index(celltempmin1)+1)
  146. faultadvice='存在电芯的老化速率不一致的风险;请检查电池温度采样系统'
  147. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  148. else:
  149. pass
  150. else:
  151. dt_time=0
  152. else: #ram当前故障中有该故障,则判断是否退出该故障
  153. if (celltempmax0-celltempmin0)<self.param.CellTempDiffLv1-2 and (celltempmax1-celltempmax0)>self.param.CellTempDiffLv1-2: #二级温差恢复
  154. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==8].index[0], 'time_sp'] = time
  155. else:
  156. pass
  157. #温升判断
  158. time2=self.bmstime[i]
  159. delttime=(time2-time1).total_seconds()
  160. if delttime>20:
  161. temp2=np.array(self._celltemp_get(i))
  162. celltemp_rate=(max(temp2-temp1)*60)/delttime #计算最大温升速率
  163. temp1=temp2 #更新初始温度
  164. time1=time2 #更新初始时间
  165. if not 9 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  166. if celltemp_rate>self.param.CellTempRate:
  167. temprate_cnt=temprate_cnt+1
  168. if temprate_cnt>2: #温升故障进入
  169. faultcode=9
  170. faultlv=3
  171. faultinfo='电芯温升速率过快:{}℃/min'.format(celltemp_rate)
  172. faultadvice='温升速率过快,存在热失控风险;禁止充放电,并通知电池技术人员介入分析'
  173. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  174. else:
  175. pass
  176. else: #ram当前故障中有该故障,则判断是否退出该故障
  177. pass
  178. else:
  179. if celltemp_rate<self.param.CellTempRate-1: #温升故障恢复
  180. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==9].index[0], 'time_sp'] = time
  181. else:
  182. pass
  183. else:
  184. ot_time=0
  185. ut_time=0
  186. dt_time=0
  187. #电压诊断功能.................................................................................................
  188. cellvolt0=self._cellvolt_get(i-1)
  189. cellvolt1=self._cellvolt_get(i)
  190. cellvoltmin0=min(cellvolt0)
  191. cellvoltmax0=max(cellvolt0)
  192. cellvoltmin1=min(cellvolt1)
  193. cellvoltmax1=max(cellvolt1)
  194. cellvoltmin_index0=cellvolt0.index(cellvoltmin0)
  195. cellvoltmax_index0=cellvolt0.index(cellvoltmax0)
  196. cellvoltmin_index1=cellvolt1.index(cellvoltmin1)
  197. cellvoltmax_index1=cellvolt1.index(cellvoltmax1)
  198. #电压断线诊断...................................................................................................
  199. if not 10 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  200. if (cellvoltmin0<2 and cellvoltmax0>4.5 and abs(cellvoltmax_index0-cellvoltmin_index0)==1) and (cellvoltmin1<2 and cellvoltmax1>4.5 and abs(cellvoltmax_index1-cellvoltmin_index1)==1): #电压断线故障进入
  201. vv_time=vv_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  202. if vv_time>55:
  203. cellvoltvalid=0
  204. faultcode=10
  205. faultlv=2
  206. faultinfo='{}号电芯和{}号电芯电压采样断线'.format(cellvolt0.index(cellvoltmax0)+1,cellvolt0.index(cellvoltmin0)+1)
  207. faultadvice='丢失部分电压信息,无法全面监控电池安全;禁止充放电,请检查电池电压采样系统'
  208. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  209. else:
  210. pass
  211. else:
  212. cellvoltvalid=1
  213. vv_time=0
  214. else: #ram当前故障中有该故障,则判断是否退出该故障
  215. if cellvoltmin0>2 and cellvoltmax0<4.5: #电压断线故障恢复
  216. cellvoltvalid=1
  217. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==10].index[0], 'time_sp'] = time
  218. else:
  219. cellvoltvalid=0
  220. #电压无效诊断.......................................................................................................
  221. if not 11 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  222. if (cellvoltmin0<0.5 and cellvoltmin1<0.5) or (cellvoltmax0>4.5 and cellvoltmax1>4.5):
  223. cellvoltvalid=0
  224. faultcode=11
  225. faultlv=2
  226. cellnum1=np.where(np.array(cellvolt1)<0.5)[0]+1
  227. cellnum2=np.where(np.array(cellvolt1)>4.5)[0]+1
  228. cellnum=list(cellnum1)+list(cellnum2)
  229. faultinfo='电芯电压{}采样无效'.format(cellnum)
  230. faultadvice='丢失电压信息,无法全面监控电池安全;禁止充放电,请检查电池电压采样系统'
  231. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  232. else:
  233. cellvoltvalid=1
  234. else:
  235. if cellvoltmin0>2 and cellvoltmax0<4.5 and cellvoltmin1>2 and cellvoltmax1<4.5: #电压断线故障恢复
  236. cellvoltvalid=1
  237. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==11].index[0], 'time_sp'] = time
  238. else:
  239. cellvoltvalid=0
  240. if cellvoltvalid==1:
  241. #过压诊断.............................................................................................................
  242. if not 12 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  243. if cellvoltmax0>self.param.CellOvLv2 and cellvoltmax1>self.param.CellOvLv2 and self.packcrnt[i]<-0.5: #二级过压进入
  244. cov_time=cov_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  245. if cov_time>self.param.volt_time:
  246. faultcode=12
  247. faultlv=3
  248. cellnum=np.where(np.array(cellvolt1)>self.param.CellOvLv2)[0]+1
  249. faultinfo='{}号电芯过压'.format(list(cellnum))
  250. faultadvice='过压可能导致电池析锂,存在电池安全与寿命衰减过快风险;禁止充电,若持续>10min,请通知电池技术人员介入分析'
  251. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  252. else:
  253. pass
  254. else:
  255. cov_time=0
  256. else: #ram当前故障中有该故障,则判断是否退出该故障
  257. if cellvoltmax0<self.param.CellOvLv1-0.05 and cellvoltmax1<self.param.CellOvLv1-0.05: #二级过压故障恢复
  258. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==12].index[0], 'time_sp'] = time
  259. else:
  260. pass
  261. #欠压诊断.................................................................................................................
  262. if not 14 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  263. if cellvoltmin0<self.param.CellUvLv2 and cellvoltmin1<self.param.CellUvLv2: #二级欠压
  264. cuv_time=cuv_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  265. if cuv_time>self.param.volt_time:
  266. faultcode=14
  267. faultlv=3
  268. cellnum=np.where(np.array(cellvolt1)<self.param.CellUvLv2)[0]+1
  269. faultinfo='{}号电芯欠压'.format(list(cellnum))
  270. faultadvice='欠压可能导致电池过放;禁止放电,请充电,若欠压持续>10min,通知电池技术人员介入分析'
  271. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  272. else:
  273. pass
  274. else:
  275. cuv_time=0
  276. else:
  277. if cellvoltmin0>self.param.CellUvLv1+0.1 and cellvoltmin1>self.param.CellUvLv1+0.1:
  278. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==14].index[0], 'time_sp'] = time
  279. else:
  280. pass
  281. #电芯压差大.....................................................................................................................................................
  282. if not 16 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  283. if (cellvoltmax0-cellvoltmin0)>self.param.CellVoltDiffLv2 and (cellvoltmax1-cellvoltmin1)>self.param.CellVoltDiffLv2: #二级电芯压差
  284. cdv_time=cdv_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  285. if cdv_time>self.param.volt_time:
  286. faultcode=16
  287. faultlv=3
  288. faultinfo='{}号电芯和{}号电芯压差大'.format(cellvolt1.index(cellvoltmax1)+1,cellvolt1.index(cellvoltmin1)+1)
  289. faultadvice='容量/内阻不一致;请均衡电池,若均衡无法解决问题,请通知电池技术人员介入分析'
  290. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  291. else:
  292. pass
  293. else:
  294. cdv_time=0
  295. else:
  296. if (cellvoltmax0-cellvoltmin0)<self.param.CellVoltDiffLv1-0.05 and (cellvoltmax1-cellvoltmin1)<self.param.CellVoltDiffLv1-0.05: #二级欠压恢复
  297. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==16].index[0], 'time_sp'] = time
  298. else:
  299. pass
  300. else:
  301. cov_time=0
  302. cuv_time=0
  303. cdv_time=0
  304. #电池包诊断.....................................................................................................................................
  305. if self.packvolt[i-1]>2*self.param.CellVoltNums and self.packvolt[i]<4.5*self.param.CellVoltNums: #电池包电压有效性
  306. packvoltvalid=1
  307. else:
  308. packvoltvalid=0
  309. if packvoltvalid==1:
  310. if not 18 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  311. if self.packvolt[i-1]>self.param.PackVoltOvLv2 and self.packvolt[i]>self.param.PackVoltOvLv2 and self.packcrnt[i]<-0.5: #电池包过压二级进入
  312. pov_time=pov_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  313. if pov_time>self.param.volt_time:
  314. faultcode=18
  315. faultlv=3
  316. faultinfo='电池包过压'
  317. faultadvice='过压会导致电池析锂,存在电池安全与寿命衰减过快风险;请停止充电,若过压持续>10min,通知电池技术人员介入分析'
  318. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  319. else:
  320. pass
  321. else:
  322. pov_time=0
  323. else:
  324. if self.packvolt[i-1]<self.param.PackVoltOvLv1 and self.packvolt[i]<self.param.PackVoltOvLv1: #电池包过压二级恢复
  325. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==18].index[0], 'time_sp'] = time
  326. else:
  327. pass
  328. if not 20 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  329. if self.packvolt[i-1]<self.param.PackVoltUvLv2 and self.packvolt[i]<self.param.PackVoltUvLv2: #电池包二级欠压进入
  330. puv_time=puv_time+(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  331. if puv_time>self.param.volt_time:
  332. faultcode=20
  333. faultlv=3
  334. faultinfo='电池包欠压'
  335. faultadvice='欠压可能导致电池过放;请停止放电,并充电,若欠压持续>10min,请通知电池技术人员介入分析'
  336. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  337. else:
  338. pass
  339. else:
  340. puv_time=0
  341. else:
  342. if self.packvolt[i-1]>self.param.PackVoltUvLv1 and self.packvolt[i]>self.param.PackVoltUvLv1: #电池包二级欠压恢复
  343. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==20].index[0], 'time_sp'] = time
  344. else:
  345. pass
  346. else:
  347. pov_time=0
  348. puv_time=0
  349. #电流过流诊断.......................................................................................................................
  350. step=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  351. if step<60 and self.packcrnt[i]>self.param.PackDisOc and self.packcrnt[i-1]>self.param.PackDisOc:
  352. as_dis=as_dis+(self.packcrnt[i]-self.param.self.PackDisOc)*step #ah累计
  353. elif step<60 and self.packcrnt[i]<self.param.PackChgOc and self.packcrnt[i-1]<self.param.PackChgOc:
  354. as_chg=as_chg+(self.param.PackChgOc-self.packcrnt[i])*step #ah累计
  355. else:
  356. as_dis=0
  357. as_chg=0
  358. if not 22 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  359. if as_dis>100:
  360. faultcode=22
  361. faultlv=3
  362. faultinfo='电池包放电过流'
  363. faultadvice='长时间过流会导致电池欠压及温升过快;请停止放电,若持续>5min,断开继电器,并通知电池技术人员介入分析'
  364. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  365. else:
  366. pass
  367. else:
  368. if self.packcrnt[i-1]<self.param.PackDisOc-10 and self.packcrnt[i]<self.param.PackDisOc-10:
  369. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==22].index[0], 'time_sp'] = time
  370. else:
  371. pass
  372. if not 21 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  373. if as_chg>100:
  374. faultcode=21
  375. faultlv=3
  376. faultinfo='电池包充电过流'
  377. faultadvice='过流会导致电池析锂,存在电池安全与寿命衰减过快风险;请停止充电,若持续>5min,断开继电器,并通知电池技术人员介入分析'
  378. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  379. else:
  380. pass
  381. else:
  382. if self.packcrnt[i-1]>self.param.PackChgOc+10 and self.packcrnt[i]>self.param.PackChgOc+10:
  383. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==21].index[0], 'time_sp'] = time
  384. else:
  385. pass
  386. #SOC卡滞、跳变诊断................................................................................................
  387. step=(self.bmstime[i]-self.bmstime[i-1]).total_seconds()
  388. if step<120:
  389. ah_accum=ah_accum-self.packcrnt[i]*step/3600 #ah累计
  390. else:
  391. pass
  392. #SOC卡滞............................................................................................................
  393. if abs(ah_accum)>self.param.Capacity*0.1:
  394. bmssoc_now=float(self.bms_soc[i])
  395. if not 27 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  396. if abs(bmssoc_now-bmssoc_st)<self.param.SocClamp: #SOC卡滞故障进入
  397. faultcode=27
  398. faultlv=1
  399. faultinfo='电池SOC卡滞'
  400. faultadvice='请通知电池供应商检查电池BMS软件是否正常'
  401. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  402. else:
  403. pass
  404. else:
  405. if abs(bmssoc_now-bmssoc_st)>self.param.SocClamp: #SOC卡滞故障退出
  406. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==27].index[0], 'time_sp'] = time
  407. else:
  408. pass
  409. bmssoc_st=bmssoc_now
  410. ah_accum=0
  411. else:
  412. pass
  413. #SOC跳变....................................................................................................................
  414. bmssoc_last=float(self.bms_soc[i-1])
  415. bmssoc_now=float(self.bms_soc[i])
  416. if not 28 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  417. if step<30 and abs(bmssoc_now-bmssoc_last)>self.param.SocJump and 1<bmssoc_now<=100 and 1<bmssoc_last<=100: #SOC跳变进入
  418. faultcode=28
  419. faultlv=1
  420. faultinfo='电池SOC跳变'
  421. faultadvice='请通知电池供应商检查电池BMS软件是否正常'
  422. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  423. else:
  424. pass
  425. else:
  426. if abs(bmssoc_now-bmssoc_st)<self.param.SocJump: #SOC跳变故障退出
  427. time=self.bmstime[i]
  428. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==28].index[0], 'time_sp'] = time
  429. else:
  430. pass
  431. # #BMS故障报警........................................................................................................
  432. # if not 1 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  433. # if self.bmsfault1[i-1] is None or self.bmsfault1[i] is None:
  434. # self.bmsfault1[i-1]=0
  435. # self.bmsfault1[i]=0
  436. # if self.bmsfault1[i-1]>0 or self.bmsfault1[i]>0: #BMS故障进入
  437. # time=self.bmstime[0]
  438. # faultcode=1
  439. # faultlv=2
  440. # faultinfo='BMS故障报警:{}'.format(self.bmsfault1[i-1])
  441. # faultadvice='检修电池'
  442. # self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  443. # else:
  444. # pass
  445. # else:
  446. # if self.bmsfault1[i-1]==0 and self.bmsfault1[i]==0: #BMS故恢复
  447. # time=self.bmstime[i]
  448. # self.df_diag_ram[self.df_diag_ram[self.df_diag_ram['faultcode']==1].index[0], 'time_sp'] = time
  449. #SOC过低故障报警............................................................................................................
  450. if not self.df_soc.empty:
  451. if not 26 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  452. if self.df_soc.loc[0, 'packsoc']<self.param.SocLow: #SOC过低故障进入
  453. time=self.df_soc.loc[0, 'time']
  454. faultcode=26
  455. faultlv=1
  456. faultinfo='电池包电量过低'
  457. faultadvice='电量过低会引起电池过放;请停止放电,并充电'
  458. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  459. else:
  460. pass
  461. else:
  462. if self.df_soc.loc[0, 'packsoc']>self.param.SocLow: #SOC过低故障退出
  463. time=self.df_soc.loc[0, 'time']
  464. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==26].index[0], 'time_sp'] = time
  465. else:
  466. pass
  467. else:
  468. pass
  469. #SOC一致性故障报警..........................................................................................................
  470. if not self.df_uniform.empty:
  471. cellsoc_diff=self.df_uniform.loc[0,'cellsoc_diff']
  472. if not 25 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  473. if cellsoc_diff>self.param.SocDiff: #SOC一致性差故障进入
  474. time=self.bmstime[0]
  475. faultcode=25
  476. faultlv=1
  477. faultinfo='电芯{}和{}SOC差过大:{}'.format(self.df_uniform.loc[0,'cellmin_num'],self.df_uniform.loc[0,'cellmax_num'],cellsoc_diff)
  478. faultadvice='请均衡电池,若无法解决,请通知电池技术人员介入分析'
  479. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  480. else:
  481. pass
  482. else:
  483. if cellsoc_diff<self.param.SocDiff: #SOC一致性差故障恢复
  484. time=self.bmstime[0]
  485. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==25].index[0], 'time_sp'] = time
  486. else:
  487. cellsoc_diff=3
  488. #容量过低和一致性故障报警................................................................................................
  489. if not self.df_soh.empty:
  490. soh=self.df_soh.loc[0,'soh']
  491. cellsoh=eval(self.df_soh.loc[0,'cellsoh'])
  492. cellsoh=np.array(cellsoh)
  493. cellsoh_lowindex=np.argwhere(cellsoh<self.param.SohLow)
  494. cellsoh_lowindex=cellsoh_lowindex+1
  495. cellsoh_diff=max(cellsoh)-min(cellsoh)
  496. if not 23 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  497. if soh<self.param.SohLow: #soh过低故障进入
  498. time=self.bmstime[0]
  499. faultcode=23
  500. faultlv=1
  501. faultinfo='电池包容量过低:{}号电芯'.format(cellsoh_lowindex)
  502. faultadvice='电池容量过低,会导致电池放电电量不足;建议更换容量过低的电芯或模组'
  503. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  504. else:
  505. pass
  506. else:
  507. if soh>self.param.SohLow+2: #soh过低故障恢复
  508. time=self.bmstime[0]
  509. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==23].index[0], 'time_sp'] = time
  510. else:
  511. pass
  512. if not 24 in list(self.df_diag_ram['faultcode']): #当前故障中没有该故障,则判断是否发生该故障
  513. cellsohmin=min(cellsoh)
  514. cellsohmax=max(cellsoh)
  515. if cellsoh_diff>self.param.SohDiff:
  516. time=self.bmstime[0]
  517. faultcode=24
  518. faultlv=1
  519. faultinfo='电池包容量一致性差:{}号和{}号电芯'.format(list(cellsoh).index(cellsohmin)+1,list(cellsoh).index(cellsohmax)+1)
  520. faultadvice='电池容量不一致性差,会导致电池放电电量不足;建议更换容量过低的电芯或模组'
  521. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  522. else:
  523. pass
  524. else:
  525. if cellsoh_diff<self.param.SohDiff-2:
  526. time=self.bmstime[0]
  527. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==24].index[0], 'time_sp'] = time
  528. else:
  529. pass
  530. #soh长时间未标定
  531. if not 100 in list(self.df_diag_ram['faultcode']):
  532. time=self.bmstime[0]
  533. if (time-self.df_soh.loc[0,'time_st']).total_seconds()>30*24*3600:
  534. faultcode=100
  535. faultlv=1
  536. faultinfo='电池包状态长时间未标定'
  537. faultadvice='电池长时间未标定,存在电池状态估算不准确风险,请对电池进行:放电至SOC<10%-静置>1h-充满,操作'
  538. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  539. else:
  540. pass
  541. else:
  542. time=self.bmstime[0]
  543. if (time-self.df_soh.loc[0,'time_st']).total_seconds()<29*24*3600:
  544. self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['faultcode']==100].index[0], 'time_sp'] = time
  545. else:
  546. pass
  547. else:
  548. #soh长时间未标定
  549. if not 100 in list(self.df_diag_ram['faultcode']):
  550. time=self.bmstime[0]
  551. faultcode=100
  552. faultlv=1
  553. faultinfo='电池包状态长时间未标定'
  554. faultadvice='电池长时间未标定,存在电池状态估算不准确风险,请对电池进行:放电至SOC<10%-静置>1h-充满,操作'
  555. self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, time_sp, self.sn, faultcode, faultlv, faultinfo, faultadvice]
  556. else:
  557. pass
  558. #电池健康度评分.....................................................................................................
  559. column_name=['time', 'sn', 'healthstate', 'healthadvice']
  560. df_health=pd.DataFrame(columns=column_name)
  561. healthstate=100
  562. healthadvice=''
  563. df_fault_now=self.df_diag_ram[self.df_diag_ram['time_sp']=='0000-00-00 00:00:00']
  564. df_fault_now.drop(df_fault_now.index[df_fault_now['falut_code']==100],inplace=True)
  565. df_fault_now.reset_index(inplace=True,drop=True)
  566. fault_num=len(df_fault_now)
  567. fltlv=df_fault_now['faultlv']
  568. fltlv1=np.sum(fltlv<1.5)
  569. fltlv2=np.sum(fltlv<2.5)-fltlv1
  570. fltlv3=np.sum(fltlv<3.5)-fltlv1-fltlv2
  571. fltlv4=np.sum(fltlv<4.5)-fltlv1-fltlv2-fltlv3
  572. fltlv5=np.sum(fltlv<5.5)-fltlv1-fltlv2-fltlv3-fltlv4
  573. if fltlv5>0:
  574. healthstate=healthstate-fltlv1*10-fltlv2*20-fltlv3*30-fltlv4*50-fltlv5*100
  575. healthadvice=healthadvice+',电池发生{}个故障'.format(fault_num)
  576. elif fltlv4>0:
  577. healthstate=healthstate-50
  578. healthadvice=healthadvice+',电池发生{}个故障'.format(fault_num)
  579. elif fltlv3>0:
  580. healthstate=healthstate-30
  581. healthadvice=healthadvice+',电池发生{}个故障'.format(fault_num)
  582. elif fltlv2>0:
  583. healthstate=healthstate-15
  584. healthadvice=healthadvice+',电池发生{}个故障'.format(fault_num)
  585. elif fltlv1>0:
  586. healthstate=healthstate-5
  587. healthadvice=healthadvice+',电池发生{}个故障'.format(fault_num)
  588. #电池寿命
  589. if not self.df_soh.empty:
  590. if soh>85:
  591. pass
  592. elif soh>=80:
  593. healthstate=healthstate-5
  594. healthadvice=healthadvice+',电池SOH较低'
  595. elif soh>=70:
  596. healthstate=healthstate-15
  597. healthadvice=healthadvice+',电池SOH过低'
  598. else:
  599. healthstate=healthstate-30
  600. healthadvice=healthadvice+',电池寿命用尽'
  601. #电池寿命一致性
  602. if cellsoh_diff>15:
  603. healthstate=healthstate-10
  604. healthadvice=healthadvice+',电池SOH一致性很差'
  605. elif cellsoh_diff>10:
  606. healthstate=healthstate-5
  607. healthadvice=healthadvice+',电池SOH一致性较差'
  608. elif cellsoh_diff>5:
  609. healthstate=healthstate-1
  610. else:
  611. pass
  612. #SOC一致性
  613. if not self.df_uniform.empty:
  614. if cellsoc_diff>20:
  615. healthstate=healthstate-10
  616. healthadvice=healthadvice+',电池SOC一致性很差'
  617. elif cellsoc_diff>10:
  618. healthstate=healthstate-5
  619. healthadvice=healthadvice+',电池SOC一致性较差'
  620. elif cellsoc_diff>5:
  621. healthstate=healthstate-1
  622. else:
  623. pass
  624. if healthstate<0:
  625. healthstate=0
  626. elif healthstate>100:
  627. healthstate=100
  628. else:
  629. pass
  630. healthstate=int(healthstate)
  631. if len(healthadvice)>0.5:
  632. healthadvice=healthadvice[1:]
  633. else:
  634. healthadvice='电池运行状态良好'
  635. df_health.loc[0]=[self.bmstime[len(self.bmstime)-1], self.sn, healthstate, healthadvice]
  636. #返回诊断结果...........................................................................................................
  637. df_res=self.df_diag_ram
  638. if not df_res.empty:
  639. pass
  640. else:
  641. df_res=pd.DataFrame()
  642. if not df_health.empty:
  643. pass
  644. else:
  645. df_health=pd.DataFrame()
  646. return df_res, df_health