main.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import datetime
  2. import pandas as pd
  3. from LIB.BACKEND import DBManager, Log
  4. import time, datetime
  5. from apscheduler.schedulers.blocking import BlockingScheduler
  6. import log
  7. from pandas.core.frame import DataFrame
  8. import Li_plated
  9. import vol_sor_est
  10. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
  11. #...................................电池包电芯安全诊断函数......................................................................................................................
  12. def cell_platd_sorvol_test():
  13. global SNnums
  14. global df_Diag_lipltd
  15. global df_diag_sor
  16. global df_diag_vol
  17. global df_diag_volsor
  18. start=time.time()
  19. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  20. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  21. start_time=now_time-datetime.timedelta(days=3)
  22. end_time=str(now_time)
  23. start_time=str(start_time)
  24. for sn in SNnums:
  25. if 'PK500' in sn:
  26. celltype=1 #6040三元电芯
  27. elif 'PK502' in sn:
  28. celltype=2 #4840三元电芯
  29. elif 'K504B' in sn:
  30. celltype=99 #60ah林磷酸铁锂电芯
  31. elif 'MGMLXN750' in sn:
  32. celltype=3 #力信50ah三元电芯
  33. elif 'MGMCLN750' or 'UD' in sn:
  34. celltype=4 #CATL 50ah三元电芯
  35. else:
  36. print('SN:{},未找到对应电池类型!!!'.format(sn))
  37. continue
  38. # sys.exit()
  39. #读取原始数据库数据........................................................................................................................................................
  40. start_time = '2021-11-23 12:00:00'
  41. end_time = '2021-11-24 12:00:00'
  42. dbManager = DBManager.DBManager()
  43. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  44. df_bms = df_data['bms']
  45. df_Diag_lipltd_add = pd.DataFrame(columns = ['sn','time','liplated', 'liplated_amount'])
  46. #析锂诊断................................................................................................................................................................
  47. if not df_bms.empty:
  48. Diag_lipltd_temp = Li_plated.Liplated_test(sn,celltype,df_bms)#析锂检测
  49. df_Diag_lipltd_add = Diag_lipltd_temp.liplated_detect()
  50. # Diag_sorvol_temp = vol_sor_est.vol_sor_est(sn,celltype,df_bms)#电压内阻估计
  51. # [df_diag_sor_add, df_diag_vol_add, df_diag_sorvol_add] = Diag_sorvol_temp.volsor_cal()
  52. if not df_Diag_lipltd_add.empty:
  53. df_Diag_lipltd_temp = df_Diag_lipltd.append(df_Diag_lipltd_add)
  54. df_Diag_lipltd = df_Diag_lipltd_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  55. df_Diag_lipltd.reset_index(drop = True)
  56. df_Diag_lipltd.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  57. df_Diag_lipltd.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\格林美-力信7255\SNnums_6040_liplated_sn.csv',index=False,encoding='GB18030')
  58. # if not df_diag_sor_add.empty:
  59. # df_diag_sor_temp = df_diag_sor.append(df_diag_sor_add)
  60. # df_diag_sor = df_diag_sor_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  61. # df_diag_sor.reset_index(drop = True)
  62. # df_diag_sor.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  63. # df_diag_sor.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\内阻偏离.csv',index=False,encoding='GB18030')
  64. # if not df_diag_vol_add.empty:
  65. # df_diag_vol_temp = df_diag_vol.append(df_diag_vol_add)
  66. # df_diag_vol = df_diag_vol_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  67. # df_diag_vol.reset_index(drop = True)
  68. # df_diag_vol.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  69. # df_diag_vol.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\电压偏离.csv',index=False,encoding='GB18030')
  70. # if not df_diag_sorvol_add.empty:
  71. # df_diag_volsor_temp = df_diag_volsor.append(df_diag_sorvol_add)
  72. # df_diag_volsor = df_diag_volsor_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  73. # df_diag_volsor.reset_index(drop = True)
  74. # df_diag_volsor.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  75. # df_diag_volsor.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\电压内阻偏离.csv',index=False,encoding='GB18030')
  76. end=time.time()
  77. print(end-start)
  78. #...............................................主函数.......................................................................................................................
  79. if __name__ == "__main__":
  80. global SNnums
  81. global df_Diag_lipltd
  82. global df_diag_sor
  83. global df_diag_vol
  84. global df_diag_volsor
  85. excelpath=r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\04故障诊断\01Screen_Problem\sn-20210903.xlsx'
  86. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  87. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  88. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  89. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  90. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  91. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  92. SNnums_6060=SNdata_6060['SN号'].tolist()
  93. SNnums_6040=SNdata_6040['SN号'].tolist()
  94. SNnums_4840=SNdata_4840['SN号'].tolist()
  95. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  96. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  97. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  98. #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  99. SNnums=['MGMCLN750N215N296','MGMCLN750N215N080', 'MGMCLN750N215I108', 'MGMCLN750N215N217']
  100. # SNnums = SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  101. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  102. mylog=log.Mylog('log_diag.txt','error')
  103. mylog.logcfg()
  104. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  105. df_Diag_lipltd=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\格林美-力信7255\析锂.csv',encoding='GB18030')
  106. # df_diag_sor = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\内阻偏离.csv',encoding='GB18030')
  107. # df_diag_vol = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\电压偏离.csv',encoding='GB18030')
  108. # df_diag_volsor = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\02算法检测\判断结果\电压内阻偏离.csv',encoding='GB18030')
  109. print('-------计算中-----------')
  110. #定时任务.......................................................................................................................................................................
  111. scheduler = BlockingScheduler()
  112. scheduler.add_job(cell_platd_sorvol_test, 'interval', seconds=10, id='diag_job')
  113. try:
  114. scheduler.start()
  115. except Exception as e:
  116. scheduler.shutdown()
  117. print(repr(e))
  118. mylog.logopt(e)