CBMSBatDiag copy.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import pandas as pd
  2. import numpy as np
  3. class BatDiag:
  4. def __init__(self, df_bms, df_soh, df_sor): #参数初始化
  5. self.df_bms=df_bms
  6. self.vin=df_bms['VIN']
  7. self.model=df_bms['VehModel']
  8. self.sn=df_bms['SN']
  9. self.end_time='0000-00-00 00:00:00'
  10. self.cellvolt_name=['CellVolt'+str(x) for x in range(1,self.param.CellVoltNums+1)]
  11. self.celltemp_name=['CellTemp'+str(x) for x in range(1,self.param.CellTempNums+1)]
  12. #电芯电压无效故障........................................................................................................................................................
  13. def cellvoltvalid(self,df_ram,df_param):
  14. # df_res=pd.DataFrame(columns=['start_time', 'end_time', 'vin', 'sn', 'model', 'fault_code', 'fault_reason', 'fault_advice', 'fault_location'])
  15. df_volt=self.df_bms[['Time']+self.cellvolt_name]
  16. volt_mean=df_volt[self.cellvolt_name].mean(axis=1)
  17. volt_std=df_volt[self.cellvolt_name].std(axis=1)
  18. volt_std = volt_std.replace(0,0.000001)
  19. df_stray=df[self.cellvolt_name].sub(volt_mean,axis=0).div(volt_std,axis=0)
  20. if df_ram.empty:
  21. #电压断线
  22. df=df_volt[((df_volt[self.cellvolt_name]<2.5).any(1)) & ((df_volt[self.cellvolt_name]>4.5).any(1))]
  23. if not df.empty:
  24. list_of_df = np.split(df, np.flatnonzero(np.diff(df.index) != 1) + 1)
  25. df=max(list_of_df, key=len, default='')
  26. if df.iloc[-1]['Time']-df.iloc[0]['Time']>df_param:
  27. cellvolt=np.array(df.iloc[0][self.cellvolt_name])
  28. cellvoltmin_index=cellvolt.index(min(cellvolt))+1
  29. cellvoltmax_index=cellvolt.index(max(cellvolt))+1
  30. if abs(cellvoltmax_index-cellvoltmin_index)==1:
  31. time=df.iloc[0]['Time']
  32. faultcode='C309'
  33. faultlv=3
  34. faultinfo='电芯电压无效'
  35. reason='电芯电压采样线断线'
  36. faultlocation='电芯{}'.format([cellvoltmin_index,cellvoltmax_index])
  37. faultadvice='召回电池包,进行检修'
  38. influence='失去对电芯电压监测'
  39. df_ram.loc[0]=[time, self.end_time, self.vin, self.sn, self.model, faultcode, reason, faultadvice, faultlocation]
  40. else:
  41. pass
  42. else:
  43. pass
  44. else:
  45. pass
  46. #电压超限
  47. if df_ram.empty:
  48. df=df_volt[((df_volt[self.cellvolt_name]<1).any(1)) | ((df_volt[self.cellvolt_name]>5).any(1))]
  49. if not df.empty:
  50. list_of_df = np.split(df, np.flatnonzero(np.diff(df.index) != 1) + 1)
  51. df=max(list_of_df, key=len, default='')
  52. if df.iloc[-1]['Time']-df.iloc[0]['Time']>df_param:
  53. cellvolt=np.array(df.iloc[0][self.cellvolt_name])
  54. time=df.iloc[0]['Time']
  55. faultcode='C309'
  56. faultlv=3
  57. faultinfo='电芯电压无效'
  58. reason='电芯电压采样电路异常'
  59. faultlocation='电芯{}'.format(list(np.argwhere(cellvolt)<1+1)+list(np.argwhere(cellvolt)>5+1))
  60. faultadvice='召回电池包,进行检修'
  61. influence='失去对电芯电压监测'
  62. df_ram.loc[0]=[time, self.vin, self.sn, self.model, faultcode, reason, faultadvice, faultlocation]
  63. else:
  64. pass
  65. else:
  66. pass
  67. else:
  68. pass
  69. #电压采样松动
  70. if df_ram.empty:
  71. df=df_stray[((df_stray[self.cellvolt_name]<-4).any(1)) & ((df_stray[self.cellvolt_name]>4).any(1))]
  72. if not df.empty:
  73. list_of_df = np.split(df, np.flatnonzero(np.diff(df.index) != 1) + 1)
  74. df=max(list_of_df, key=len, default='')
  75. if df.iloc[-1]['Time']-df.iloc[0]['Time']>df_param:
  76. cellvolt=np.array(df.iloc[0][self.cellvolt_name])
  77. time=df.iloc[0]['Time']
  78. faultcode='C309'
  79. faultlv=3
  80. faultinfo='电芯电压无效'
  81. reason='电芯电压采样线松动'
  82. faultlocation='电芯{}'.format(list(np.argwhere(cellvolt)<1+1)+list(np.argwhere(cellvolt)>5+1))
  83. faultadvice='召回电池包,进行检修'
  84. influence='失去对电芯电压监测'
  85. df_ram.loc[0]=[time, self.vin, self.sn, self.model, faultcode, reason, faultadvice, faultlocation]
  86. else:
  87. pass
  88. else:
  89. pass
  90. else:
  91. pass
  92. return df_ram