main.py 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #...................................电池包电芯安全诊断函数......................................................................................................................
  10. def cell_platd_test():
  11. global SNnums
  12. global df_Diag_lipltd
  13. start=time.time()
  14. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  15. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  16. start_time=now_time-datetime.timedelta(days=3)
  17. end_time=str(now_time)
  18. start_time=str(start_time)
  19. for sn in SNnums:
  20. if 'PK500' in sn:
  21. celltype=1 #6040三元电芯
  22. elif 'PK502' in sn:
  23. celltype=2 #4840三元电芯
  24. elif 'K504B' in sn:
  25. celltype=99 #60ah林磷酸铁锂电芯
  26. elif 'MGMLXN750' in sn:
  27. celltype=3 #力信50ah三元电芯
  28. elif 'MGMCLN750' or 'UD' in sn:
  29. celltype=4 #CATL 50ah三元电芯
  30. else:
  31. print('SN:{},未找到对应电池类型!!!'.format(sn))
  32. continue
  33. # sys.exit()
  34. #读取原始数据库数据........................................................................................................................................................
  35. start_time = '2021-11-15 12:00:00'
  36. end_time = '2021-11-18 12:00:00'
  37. dbManager = DBManager.DBManager()
  38. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  39. df_bms = df_data['bms']
  40. df_Diag_lipltd_add = pd.DataFrame(columns = ['sn','time','liplated', 'liplated_amount'])
  41. #析锂诊断................................................................................................................................................................
  42. if not df_bms.empty:
  43. Diag_lipltd_temp = Li_plated.Liplated_test(sn,celltype,df_bms)#析锂检测
  44. df_Diag_lipltd_add = Diag_lipltd_temp.liplated_detect()
  45. if not df_Diag_lipltd_add.empty:
  46. df_Diag_lipltd_temp = df_Diag_lipltd.append(df_Diag_lipltd_add)
  47. df_Diag_lipltd = df_Diag_lipltd_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  48. df_Diag_lipltd.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  49. 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')
  50. end=time.time()
  51. print(end-start)
  52. #...............................................主函数.......................................................................................................................
  53. if __name__ == "__main__":
  54. global SNnums
  55. global df_Diag_lipltd
  56. excelpath=r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\04故障诊断\01Screen_Problem\sn-20210903.xlsx'
  57. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  58. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  59. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  60. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  61. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  62. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  63. SNnums_6060=SNdata_6060['SN号'].tolist()
  64. SNnums_6040=SNdata_6040['SN号'].tolist()
  65. SNnums_4840=SNdata_4840['SN号'].tolist()
  66. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  67. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  68. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  69. #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  70. # SNnums=['MGMCLN750N215I005','PK504B10100004341','PK504B00100004172','MGMLXN750N2189014']
  71. SNnums = SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  72. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  73. mylog=log.Mylog('log_diag.txt','error')
  74. mylog.logcfg()
  75. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  76. df_Diag_lipltd=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\01下载数据\格林美-力信7255\析锂.csv',encoding='GB18030')
  77. print('----------------输入--------')
  78. print('-------计算中-----------')
  79. #定时任务.......................................................................................................................................................................
  80. scheduler = BlockingScheduler()
  81. scheduler.add_job(cell_platd_test, 'interval', seconds=10, id='diag_job')
  82. try:
  83. scheduler.start()
  84. except Exception as e:
  85. scheduler.shutdown()
  86. print(repr(e))
  87. mylog.logopt(e)