SC_SamplingSafty.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 pymysql import NULL
  11. from LIB.BACKEND import DBManager
  12. import datetime
  13. import time
  14. import string
  15. import re
  16. class SamplingSafty:
  17. def __init__(self):
  18. pass
  19. def main(sn,param,bms_info,df_Diag_Ram_in):
  20. df_Diag_Ram_Update_inside=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
  21. df_Diag_Ram_Update_inside=df_Diag_Ram_Update_inside.append(df_Diag_Ram_in)
  22. global QuitErrCount
  23. VolStarkCount=[0 for i in range(param.CellVoltNums)]
  24. VolCount=0
  25. QuitErrCount=[0 for i in range(param.FaultCount)]
  26. df_Diag_Ram=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
  27. st_tp=[]
  28. #--------------该电池的所有当前故障-------------
  29. VoltageNum=['单体电压'+str(i) for i in range(1,param.CellVoltNums+1)]#单体电压替换cellvolt_
  30. CellVoltage=bms_info[VoltageNum]/1000
  31. CellMaxVoltage=CellVoltage.max(axis=1)
  32. CellMinVoltage=CellVoltage.min(axis=1)
  33. InVMaxBatNo=CellVoltage[CellVoltage>=param.CellOVlmt].dropna(axis=0,how='all',inplace=False)
  34. InVMinBatNo=CellVoltage[CellVoltage<=param.CellUVlmt].dropna(axis=0,how='all',inplace=False)
  35. #date替换为'时间戳'
  36. if len(InVMaxBatNo):
  37. indexValue=InVMaxBatNo.index.values
  38. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[0],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'单体电压大于{:.2f}V,采样无效'.format(param.CellOVlmt),'建议返厂维修']
  39. for i in range(1,len(indexValue)):
  40. if indexValue[i]- indexValue[i-1]>10:
  41. df_Diag_Ram.loc[len(df_Diag_Ram)-1,'end_time']=bms_info.loc[indexValue[i-1],'时间戳']
  42. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[i],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'单体电压大于{:.2f}V,采样无效'.format(param.CellOVlmt),'建议返厂维修']
  43. if len(InVMinBatNo):
  44. indexValue=InVMinBatNo.index.values
  45. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[0],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电压小于{:.2f}V,采样无效'.format(param.CellUVlmt),'建议返厂维修']
  46. for i in range(1,len(indexValue)):
  47. if indexValue[i]- indexValue[i-1]>10:
  48. df_Diag_Ram.loc[len(df_Diag_Ram)-1,'end_time']=bms_info.loc[indexValue[i-1],'时间戳']
  49. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[i],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电压小于{:.2f}V,采样无效'.format(param.CellUVlmt),'建议返厂维修']
  50. MedianVol=CellVoltage.median(axis=1).tolist()
  51. MediaVolGap=abs(CellVoltage.sub(MedianVol,axis=0))
  52. OutlineVol=MediaVolGap[MediaVolGap>=param.AvgVolGap][CellMaxVoltage<param.CellOVlmt][CellMinVoltage>param.CellUVlmt][abs(bms_info['总电流[A]'])<1].dropna(axis=0,how='all',inplace=False)
  53. #OutlineVol=OutlineVol[CellMaxVoltage<param.CellOVlmt][CellMinVoltage>param.CellUVlmt].dropna(axis=0,how='all',inplace=False)
  54. if len(OutlineVol):
  55. indexValue=OutlineVol.index.values
  56. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[0],'时间戳'],'0000-00-00 00:00:00',sn,50,3,sn,10,3,'电池电压发生偏移或发生断线','建议返厂维修']
  57. for i in range(1,len(indexValue)):
  58. if indexValue[i]- indexValue[i-1]>10:
  59. df_Diag_Ram.loc[len(df_Diag_Ram)-1,'end_time']=bms_info.loc[indexValue[i-1],'时间戳']
  60. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[i],'时间戳'],'0000-00-00 00:00:00',sn,10,3,'电池电压发生偏移或发生断线','建议返厂维修']
  61. CellTemp=bms_info['单体温度1']
  62. InVMaxTempBatNo=CellTemp[CellTemp>=param.PackOTlmt].dropna(axis=0,how='all',inplace=False)
  63. InVMinTempBatNo=CellTemp[CellTemp<=param.PackUTlmt].dropna(axis=0,how='all',inplace=False)
  64. if len(InVMaxTempBatNo):
  65. indexValue=InVMaxTempBatNo.index.values
  66. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[0],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电池温度大于{:.0f}摄氏度,采样无效'.format(param.PackOTlmt),'请立即确认状态']
  67. for i in range(1,len(indexValue)):
  68. if indexValue[i]- indexValue[i-1]>10:
  69. df_Diag_Ram.loc[len(df_Diag_Ram)-1,'end_time']=bms_info.loc[indexValue[i-1],'时间戳']
  70. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[i],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电池温度大于{:.0f}摄氏度,采样无效'.format(param.PackOTlmt),'请立即确认状态']
  71. if len(InVMinTempBatNo):
  72. indexValue=InVMinTempBatNo.index.values
  73. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[0],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电池温度小于{:.0f}摄氏度,采样无效'.format(param.PackUTlmt),'建议返厂维修']
  74. for i in range(1,len(indexValue)):
  75. if indexValue[i]- indexValue[i-1]>10:
  76. df_Diag_Ram.loc[len(df_Diag_Ram)-1,'end_time']=bms_info.loc[indexValue[i-1],'时间戳']
  77. df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_info.loc[indexValue[i],'时间戳'],'0000-00-00 00:00:00',sn,50,3,'电池温度小于{:.0f}摄氏度,采样无效'.format(param.PackUTlmt),'建议返厂维修']
  78. return df_Diag_Ram