CBMSBatBehave.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import pandas as pd
  2. import numpy as np
  3. import datetime
  4. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
  5. class BatBehave:
  6. def __init__(self,sn,celltype,df_bms): #参数初始化
  7. self.sn=sn
  8. self.celltype=celltype
  9. self.param=BatParam.BatParam(celltype)
  10. self.df_bms=df_bms
  11. df_bms['时间戳']=pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
  12. self.packcrnt=df_bms['总电流[A]']*self.param.PackCrntDec
  13. self.bmstime= df_bms['时间戳']
  14. self.packsoc=df_bms['SOC[%]']
  15. self.cellvolt_name=['单体电压'+str(x) for x in range(1,self.param.CellVoltNums+1)]
  16. # othertemp=['其他温度'+str(x) for x in range(1,self.param.OtherTempNums+1)]
  17. self.celltemp_name=['单体温度'+str(x) for x in range(1,self.param.CellTempNums+1)]
  18. # self.celltemp_name=celltemp+othertemp
  19. def behave(self):
  20. if self.celltype<=50:
  21. df_res=self._bat_behave()
  22. return df_res
  23. else:
  24. df_res=self._bat_behave()
  25. return df_res
  26. #寻找当前行数据的所有温度值...................................................................................
  27. def _celltemp_get(self,num):
  28. celltemp = list(self.df_bms.loc[num,self.celltemp_name])
  29. return celltemp
  30. #获取当前行所有电压数据............................................................................................
  31. def _cellvolt_get(self,num):
  32. cellvolt = list(self.df_bms.loc[num,self.cellvolt_name]/1000)
  33. return cellvolt
  34. #筛选充电数据.......................................................................................................
  35. def _chrgdata(self):
  36. self.ComeIn=[]
  37. self.ChgStart=[]
  38. self.ChgEnd=[]
  39. self.ComeOut=[]
  40. if len(self.df_bms)>10:
  41. state=0
  42. for i in range(3, len(self.bmstime) - 3):
  43. if state==0:
  44. if abs(self.packcrnt[i])<=0.1:
  45. self.ComeIn.append(i)
  46. state=1
  47. elif state==1:
  48. if self.packcrnt[i]<=-10 and self.packcrnt[i+1]<=-10:
  49. self.ChgStart.append(i)
  50. state=2
  51. elif self.packcrnt[i]>1:
  52. state=0
  53. self.ComeIn.pop()
  54. else:
  55. pass
  56. elif state==2:
  57. if self.packcrnt[i]>-0.1:
  58. state=3
  59. if (self.bmstime[i]-self.bmstime[self.ChgStart[-1]]).total_seconds()>300 and self.packsoc[i]-self.packsoc[self.ChgStart[-1]]>5:
  60. self.ChgEnd.append(i)
  61. else:
  62. state=0
  63. self.ComeIn.pop()
  64. self.ChgStart.pop()
  65. else:
  66. pass
  67. else:
  68. if self.packcrnt[i]>1:
  69. state=0
  70. self.ComeOut.append(i)
  71. else:
  72. pass
  73. else:
  74. pass
  75. #..........................................电池诊断功能..................................................................
  76. def _bat_behave(self):
  77. df_res=pd.DataFrame(columns=['sn','time_in', 'time_st', 'time_sp', 'time_out', 'soc_st', 'soc_sp'])
  78. self._chrgdata()
  79. if len(self.ComeOut)>0:
  80. for i in range(len(self.ChgEnd)):
  81. df_res.loc[i]=[self.sn, self.bmstime[self.ComeIn[i]], self.bmstime[self.ChgStart[i]], self.bmstime[self.ChgEnd[i]], self.bmstime[self.ComeOut[i]], self.packsoc[self.ChgStart[i]], self.packsoc[self.ChgEnd[i]]]
  82. return df_res
  83. else:
  84. return pd.DataFrame()