main.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_statics_pack
  9. import soc_total
  10. #...................................电池包电芯安全诊断函数......................................................................................................................
  11. def chrgr_statics():
  12. global SNnums
  13. global df_chrgr_static
  14. start=time.time()
  15. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  16. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  17. start_time=now_time-datetime.timedelta(days=3)
  18. end_time=str(now_time)
  19. start_time=str(start_time)
  20. k = 1
  21. for sn in SNnums[0:3]:
  22. if 'PK500' in sn:
  23. celltype=1 #6040三元电芯
  24. elif 'PK502' in sn:
  25. celltype=2 #4840三元电芯
  26. elif 'K504B' in sn:
  27. celltype=99 #60ah林磷酸铁锂电芯
  28. elif 'MGMLXN750' in sn:
  29. celltype=3 #力信50ah三元电芯
  30. elif ('MGMCLN750' or 'UD') in sn:
  31. celltype=4 #CATL 50ah三元电芯
  32. elif 'TJMCL' in sn:
  33. celltype=100 #金茂电芯
  34. else:
  35. print('SN:{},未找到对应电池类型!!!'.format(sn))
  36. continue
  37. # sys.exit()
  38. print('计算的第' + str(k) + '个:' + sn)
  39. k = k + 1
  40. #读取原始数据库数据........................................................................................................................................................
  41. start_time = '2021-12-01 00:00:00'
  42. end_time = '2021-12-31 00:00:00'
  43. dbManager = DBManager.DBManager()
  44. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  45. df_bms = df_data['bms']
  46. df_Diag_chrgr_add = pd.DataFrame(columns = ['sn', 'crntstrt_time', 'splicestrt_time', 'crntend_time', 'spliceend_time', 'strt_soc', 'end_soc', 'delta_soc', 'state'])
  47. #充电统计................................................................................................................................................................
  48. if not df_bms.empty:
  49. chrgr_statics_temp = chrgr_statics_pack.cell_statistic(sn,celltype,df_bms)#析锂检测
  50. df_Diag_chrgr_add = chrgr_statics_temp.chrgr_sta()
  51. if not df_Diag_chrgr_add.empty:
  52. df_chrgr_static = df_chrgr_static.append(df_Diag_chrgr_add)
  53. df_chrgr_static = df_chrgr_static.drop_duplicates(subset = ['sn','splicestrt_time'], keep = 'first', inplace = False)
  54. # df_chrgr_static.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  55. df_chrgr_static.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\04充电行为\金茂充电统计\充电行为.csv',index=False,encoding='GB18030')
  56. end=time.time()
  57. print(end-start)
  58. #...............................................主函数.......................................................................................................................
  59. if __name__ == "__main__":
  60. global SNnums
  61. global df_chrgr_static
  62. excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\lzx\01算法开发\00项目sn号\sn-20210903.xlsx'
  63. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  64. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  65. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  66. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  67. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  68. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  69. SNnums_6060=SNdata_6060['SN号'].tolist()
  70. SNnums_6040=SNdata_6040['SN号'].tolist()
  71. SNnums_4840=SNdata_4840['SN号'].tolist()
  72. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  73. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  74. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  75. # SNums_file = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果\SNnums_C7255析锂情况析锂排序.csv',encoding='GB18030')
  76. # SNums_sn = SNums_file['sn']
  77. # liplated_high = SNums_sn.iloc[7:10]
  78. # liplated_low = SNums_sn.iloc[-11:-1]
  79. # cal_sn = liplated_high.append(liplated_low)
  80. #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
  81. # SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  82. # SNnums = list(cal_sn)#['MGMCLN750N215N049']#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  83. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  84. SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  85. mylog=log.Mylog('log_diag.txt','error')#'TJMCL120502305010','TJMCL120502305012',
  86. mylog.logcfg()
  87. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  88. df_chrgr_static = pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\04充电行为\金茂充电统计\充电行为.csv',encoding='GB18030')
  89. print('----------------输入--------')
  90. print('-------计算中-----------')
  91. #定时任务.......................................................................................................................................................................
  92. scheduler = BlockingScheduler()
  93. scheduler.add_job(chrgr_statics, 'interval', seconds=10, id='diag_job')
  94. try:
  95. scheduler.start()
  96. except Exception as e:
  97. scheduler.shutdown()
  98. print(repr(e))
  99. mylog.logopt(e)