main.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. k = 1
  20. for sn in SNnums:
  21. if 'PK500' in sn:
  22. celltype=1 #6040三元电芯
  23. elif 'PK502' in sn:
  24. celltype=2 #4840三元电芯
  25. elif 'K504B' in sn:
  26. celltype=99 #60ah林磷酸铁锂电芯
  27. elif 'MGMLXN750' in sn:
  28. celltype=3 #力信50ah三元电芯
  29. elif ('MGMCLN750' or 'UD') in sn:
  30. celltype=4 #CATL 50ah三元电芯
  31. elif 'TJMCL' in sn:
  32. celltype=100 #金茂电芯
  33. else:
  34. print('SN:{},未找到对应电池类型!!!'.format(sn))
  35. continue
  36. # sys.exit()
  37. print('计算的第' + str(k) + '个:' + sn)
  38. k = k + 1
  39. #读取原始数据库数据........................................................................................................................................................
  40. start_time = '2021-12-01 00:00:00'
  41. end_time = '2021-12-08 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. if not df_Diag_lipltd_add.empty:
  51. df_Diag_lipltd_temp = df_Diag_lipltd.append(df_Diag_lipltd_add)
  52. df_Diag_lipltd = df_Diag_lipltd_temp.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  53. df_Diag_lipltd.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  54. df_Diag_lipltd.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\析锂.csv',index=False,encoding='GB18030')
  55. end=time.time()
  56. print(end-start)
  57. #...............................................主函数.......................................................................................................................
  58. if __name__ == "__main__":
  59. global SNnums
  60. global df_Diag_lipltd
  61. # excelpath=r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\00项目sn号\sn-20210903.xlsx'
  62. # SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  63. # SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  64. # SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  65. # SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  66. # SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  67. # SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  68. # SNnums_6060=SNdata_6060['SN号'].tolist()
  69. # SNnums_6040=SNdata_6040['SN号'].tolist()
  70. # SNnums_4840=SNdata_4840['SN号'].tolist()
  71. # SNnums_L7255=SNdata_L7255['SN号'].tolist()
  72. # SNnums_C7255=SNdata_C7255['SN号'].tolist()
  73. # SNnums_U7255=SNdata_U7255['SN号'].tolist()
  74. #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  75. # SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  76. SNnums = ['PK50201A000002053']#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  77. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  78. # mylog=log.Mylog('log_diag.txt','error')
  79. # mylog.logcfg()
  80. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  81. # df_Diag_lipltd=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\析锂.csv',encoding='GB18030')
  82. print('----------------输入--------')
  83. print('-------计算中-----------')
  84. cell_platd_test()
  85. #定时任务.......................................................................................................................................................................
  86. scheduler = BlockingScheduler()
  87. # scheduler.add_job(cell_platd_test, 'interval', seconds=10, id='diag_job')
  88. try:
  89. scheduler.start()
  90. except Exception as e:
  91. scheduler.shutdown()
  92. print(repr(e))
  93. # mylog.logopt(e)