main.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 chrgr_soc_confrm
  9. #...................................电池包电芯安全诊断函数......................................................................................................................
  10. def cell_chrgrsoc_test():
  11. global SNnums
  12. global df_chrgrsoc
  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-9-01 00:00:00'
  41. end_time = '2021-10-01 00: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_chrgrsoc_add = pd.DataFrame()
  46. #析锂诊断................................................................................................................................................................
  47. if not df_bms.empty:
  48. Diag_chrgrsoc_temp = chrgr_soc_confrm.chrgrsoc_test(sn,celltype,df_bms)#充电SOC
  49. df_Diag_chrgrsoc_add = Diag_chrgrsoc_temp.chrgrsoc_detect()
  50. if len(df_Diag_chrgrsoc_add) > 0:
  51. df_chrgrsoc = df_chrgrsoc.append(df_Diag_chrgrsoc_add)
  52. df_chrgrsoc = df_chrgrsoc.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False)
  53. df_chrgrsoc.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  54. df_chrgrsoc.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\03车辆分析\低析锂量电池的充电截止SOC.csv',index=False,encoding='GB18030')
  55. end=time.time()
  56. print(end-start)
  57. #...............................................主函数.......................................................................................................................
  58. if __name__ == "__main__":
  59. global SNnums
  60. global df_chrgrsoc
  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 = ['MGMCLN750N215N155']#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  77. SNnums_data = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果\SNnums_C7255析锂情况析锂排序.csv',encoding='GB18030')
  78. snnums_len = len(SNnums_data)
  79. SNnums = SNnums_data['sn'][snnums_len-11:snnums_len]
  80. mylog=log.Mylog('log_diag.txt','error')
  81. mylog.logcfg()
  82. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  83. df_chrgrsoc = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\03车辆分析\充电截止SOC.csv',encoding='GB18030')
  84. print('----------------输入--------')
  85. print('-------计算中-----------')
  86. #定时任务.......................................................................................................................................................................
  87. scheduler = BlockingScheduler()
  88. scheduler.add_job(cell_chrgrsoc_test, 'interval', seconds=10, id='diag_job')
  89. try:
  90. scheduler.start()
  91. except Exception as e:
  92. scheduler.shutdown()
  93. print(repr(e))
  94. mylog.logopt(e)