main.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. from pandas.core.frame import DataFrame
  7. import matplotlib as plt
  8. from pylab import*
  9. import sor_est
  10. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
  11. import log
  12. #...................................电池包电芯安全诊断函数......................................................................................................................
  13. def cell_sor_test():
  14. global SNnums
  15. global df_diag_sor
  16. start=time.time()
  17. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  18. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  19. start_time=now_time-datetime.timedelta(days=3)
  20. end_time=str(now_time)
  21. start_time=str(start_time)
  22. k = 1
  23. for sn in SNnums:
  24. if 'PK500' in sn:
  25. celltype=1 #6040三元电芯
  26. elif 'PK502' in sn:
  27. celltype=2 #4840三元电芯
  28. elif 'K504B' in sn:
  29. celltype=99 #60ah林磷酸铁锂电芯
  30. elif 'MGMLXN750' in sn:
  31. celltype=3 #力信50ah三元电芯
  32. elif 'MGMCLN750' in sn:
  33. celltype=4 #CATL 50ah三元电芯
  34. elif 'UD' in sn:
  35. celltype=4 #CATL 50ah三元电芯
  36. elif 'TJMCL' in sn:
  37. celltype=100 #金茂电芯
  38. else:
  39. print('SN:{},未找到对应电池类型!!!'.format(sn))
  40. continue
  41. # sys.exit()
  42. print('计算的第' + str(k) + '个:' + sn)
  43. k = k + 1
  44. #读取原始数据库数据........................................................................................................................................................
  45. start_time = '2021-10-01 00:00:00'
  46. end_time = '2021-11-01 00:00:00'
  47. dbManager = DBManager.DBManager()
  48. df_data = dbManager.get_data(sn = sn, start_time = start_time, end_time = end_time, data_groups = ['bms'])
  49. df_bms = df_data['bms']
  50. # df_sor_add = pd.DataFrame()
  51. param = BatParam.BatParam(celltype)#鹏飞param中为BatParam,学琦为BatteryInfo
  52. #........................................................电压内阻估计.....................................................................
  53. if not df_bms.empty:
  54. Diag_sorvol_temp = sor_est.sor_est(sn,celltype,df_bms)#电压内阻估计
  55. df_sor_add = Diag_sorvol_temp.sor_cal()
  56. if not df_sor_add.empty:
  57. df_diag_sor = df_diag_sor.append(df_sor_add)
  58. df_diag_sor = df_diag_sor.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  59. df_diag_sor.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\01算法开发\内阻估计\测试结果\MGMCLN750N215N049\计算结果\内阻估计.csv',index=False,encoding='GB18030')
  60. end=time.time()
  61. print(end-start)
  62. #...............................................主函数...............................................................................................
  63. if __name__ == "__main__":
  64. global SNnums
  65. global df_diag_sor
  66. excelpath=r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\00项目sn号\sn-20210903.xlsx'
  67. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  68. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  69. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  70. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  71. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  72. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  73. SNnums_6060=SNdata_6060['SN号'].tolist()
  74. SNnums_6040=SNdata_6040['SN号'].tolist()
  75. SNnums_4840=SNdata_4840['SN号'].tolist()
  76. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  77. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  78. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  79. # df_diag_sor = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\01算法开发\内阻估计\测试结果\内阻估计.csv', encoding='GB18030')
  80. # SNums_finish = list(df_diag_sor['sn'])
  81. #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  82. #SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  83. # SNnums = SNnums_U7255#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049'] PK504B00100004003
  84. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  85. # SNnums = list(set(SNnums_U7255).difference(set(SNums_finish)))
  86. SNnums = ['MGMCLN750N215N049']
  87. mylog=log.Mylog('log_diag.txt','error')
  88. mylog.logcfg()
  89. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  90. df_diag_sor = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\05内阻及电压估计\01算法开发\内阻估计\测试结果\MGMCLN750N215N049\计算结果\内阻估计.csv',encoding='GB18030')
  91. print('----------------输入--------')
  92. print('-------计算中-----------')
  93. #定时任务.......................................................................................................................................................................
  94. scheduler = BlockingScheduler()
  95. scheduler.add_job(cell_sor_test, 'interval', seconds=10, id='diag_job')
  96. try:
  97. scheduler.start()
  98. except Exception as e:
  99. scheduler.shutdown()
  100. print(repr(e))
  101. mylog.logopt(e)