SC_CtrlSafty.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import sys
  2. import numpy as np
  3. import pandas as pd
  4. import string
  5. import os
  6. from pandas import Series
  7. from matplotlib import pyplot as plt
  8. from pandas.core.frame import DataFrame
  9. from pandas.core.indexes.base import Index
  10. from LIB.BACKEND import DBManager
  11. import datetime
  12. import time
  13. import string
  14. import re
  15. class CtrlSafty:
  16. def __init__(self):
  17. pass
  18. def main(sn,param,bms_info,df_Diag_Ram_in):
  19. df_Diag_Ram_Update_inside=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
  20. df_Diag_Ram_Update_inside=df_Diag_Ram_Update_inside.append(df_Diag_Ram_in)
  21. global QuitErrCount
  22. VolStarkCount=[0 for i in range(param.CellVoltNums)]
  23. VolCount=0
  24. QuitErrCount=[0 for i in range(param.FaultCount)]
  25. #--------------该电池的所有当前故障-------------
  26. df_Diag_Ram_Update_inside=CtrlSafty.TempCtrlDiag(sn,bms_info,param,df_Diag_Ram_Update_inside)
  27. return df_Diag_Ram_Update_inside
  28. def TempCtrlDiag(sn,bms_info,param,df_Diag_Ram):
  29. ErrorFlg=0
  30. CellTempMax=0
  31. OtherTempMax=0
  32. CellTempNum=['单体温度'+str(i) for i in range(1,param.CellTempNums+1)]
  33. if 'MXMLX' in sn:
  34. OtherTempNum=['其他温度1','其他温度3','其他温度4','其他温度5']
  35. else:
  36. OtherTempNum=['其他温度'+str(i) for i in range(1,param.OtherTempNums+1)]
  37. CellTempMax=bms_info[bms_info[CellTempNum]>(param.CellMaxUSBTemp-5)]
  38. CellTempMax=CellTempMax[CellTempMax<(param.CellMaxUSBTemp+5)].dropna(axis=0,how='all')
  39. OtherTempMax=bms_info[bms_info[OtherTempNum]>(param.OtherOTlmt-10)]
  40. OtherTempMax=OtherTempMax[OtherTempMax[OtherTempNum]<(param.OtherOTlmt+5)].dropna(axis=0,how='all')
  41. if len(CellTempMax) and len(OtherTempMax):
  42. QuitErrCount[57]=0
  43. if not 57 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
  44. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[len(bms_info)-1,'时间戳'],'0000-00-00 00:00:00',sn,57,4,'电芯温度高','立即联系用户确认电池状态']
  45. ErrorFlg=1
  46. else:#如果故障发生当前故障中有该故障,则不进行操作
  47. pass
  48. else:
  49. if 57 in df_Diag_Ram['code'].values.tolist():
  50. QuitErrCount[57]=QuitErrCount[57]+1
  51. if QuitErrCount[57]>3:
  52. QuitErrCount[57]=4
  53. end_time=datetime.datetime.now()
  54. end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
  55. df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==57].index,['end_time']]=end_time
  56. else:
  57. pass
  58. else:
  59. pass
  60. return df_Diag_Ram