import datetime import pandas as pd from LIB.BACKEND import DBManager, Log import time, datetime from apscheduler.schedulers.blocking import BlockingScheduler import log from pandas.core.frame import DataFrame import chrgr_soc_confrm #...................................电池包电芯安全诊断函数...................................................................................................................... def cell_chrgrsoc_test(): global SNnums global df_chrgrsoc start=time.time() now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S') start_time=now_time-datetime.timedelta(days=3) end_time=str(now_time) start_time=str(start_time) k = 1 for sn in SNnums: if 'PK500' in sn: celltype=1 #6040三元电芯 elif 'PK502' in sn: celltype=2 #4840三元电芯 elif 'K504B' in sn: celltype=99 #60ah林磷酸铁锂电芯 elif 'MGMLXN750' in sn: celltype=3 #力信50ah三元电芯 elif ('MGMCLN750' or 'UD') in sn: celltype=4 #CATL 50ah三元电芯 elif 'TJMCL' in sn: celltype=100 #金茂电芯 else: print('SN:{},未找到对应电池类型!!!'.format(sn)) continue # sys.exit() print('计算的第' + str(k) + '个:' + sn) k = k + 1 #读取原始数据库数据........................................................................................................................................................ start_time = '2021-9-01 00:00:00' end_time = '2021-10-01 00:00:00' dbManager = DBManager.DBManager() df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms']) df_bms = df_data['bms'] df_Diag_chrgrsoc_add = pd.DataFrame() #析锂诊断................................................................................................................................................................ if not df_bms.empty: Diag_chrgrsoc_temp = chrgr_soc_confrm.chrgrsoc_test(sn,celltype,df_bms)#充电SOC df_Diag_chrgrsoc_add = Diag_chrgrsoc_temp.chrgrsoc_detect() if len(df_Diag_chrgrsoc_add) > 0: df_chrgrsoc = df_chrgrsoc.append(df_Diag_chrgrsoc_add) df_chrgrsoc = df_chrgrsoc.drop_duplicates(subset = ['sn','time'], keep = 'first', inplace = False) df_chrgrsoc.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序 df_chrgrsoc.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\03车辆分析\低析锂量电池的充电截止SOC.csv',index=False,encoding='GB18030') end=time.time() print(end-start) #...............................................主函数....................................................................................................................... if __name__ == "__main__": global SNnums global df_chrgrsoc excelpath=r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\00项目sn号\sn-20210903.xlsx' SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060') SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040') SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840') SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255') SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255') SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255') SNnums_6060=SNdata_6060['SN号'].tolist() SNnums_6040=SNdata_6040['SN号'].tolist() SNnums_4840=SNdata_4840['SN号'].tolist() SNnums_L7255=SNdata_L7255['SN号'].tolist() SNnums_C7255=SNdata_C7255['SN号'].tolist() SNnums_U7255=SNdata_U7255['SN号'].tolist() #SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060 # SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038'] # SNnums = ['MGMCLN750N215N155']#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049'] SNnums_data = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果\SNnums_C7255析锂情况析锂排序.csv',encoding='GB18030') snnums_len = len(SNnums_data) SNnums = SNnums_data['sn'][snnums_len-11:snnums_len] mylog=log.Mylog('log_diag.txt','error') mylog.logcfg() #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................ df_chrgrsoc = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\03车辆分析\充电截止SOC.csv',encoding='GB18030') print('----------------输入--------') print('-------计算中-----------') #定时任务....................................................................................................................................................................... scheduler = BlockingScheduler() scheduler.add_job(cell_chrgrsoc_test, 'interval', seconds=10, id='diag_job') try: scheduler.start() except Exception as e: scheduler.shutdown() print(repr(e)) mylog.logopt(e)