import CBMSBatDiag import log import pymysql from apscheduler.schedulers.blocking import BlockingScheduler import datetime import pandas as pd from LIB.BACKEND import DBManager, Log import time, datetime import os def diag_cal(): filepath=r'D:\Develop\User\Songpengfei\data_analyze_platform\WORK\03hezhong\98Data' files=os.listdir(filepath) # 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=30) # end_time=str(now_time) # start_time=str(start_time) #数据库配置 host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com' port=3306 user='hz_dev' password='Qx@123456' #读取故障结果库中code==110且end_time='0000-00-00 00:00:00'............................... db='hz_dev' mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db) cursor = mysql.cursor() param='algo_id,pack_code,threshold,confirm_time,remove_time,param' sql = "select %s from %s" %(param,'algo_adjustable_param') cursor.execute(sql) res = cursor.fetchall() df_adjust_param= pd.DataFrame(res,columns=param.split(',')) param='algo_id,is_activate,global_param' sql = "select %s from %s" %(param,'algo_list') cursor.execute(sql) res = cursor.fetchall() df_algo_param= pd.DataFrame(res,columns=param.split(',')) df_algo_param=df_algo_param.set_index('algo_id') param='pack_code,param' sql = "select %s from %s" %(param,'algo_pack_param') cursor.execute(sql) res = cursor.fetchall() df_pack_param= pd.DataFrame(res,columns=param.split(',')) df_pack_param['param']=df_pack_param['param'].map(lambda x:eval(x)) a=df_pack_param['param'].values.tolist() df_pack_param=pd.DataFrame(a) cursor.close() mysql.close() #log信息配置 mylog=log.Mylog('log.txt','error') mylog.logcfg() for filename in files: try: df_bms = pd.read_excel(filepath+'\\'+filename) df_diag_ram=pd.DataFrame(columns=['start_time', 'end_time', 'vin', 'sn', 'model', 'fault_code', 'fault_reason', 'fault_advice', 'fault_location']) df_soh=pd.DataFrame() df_sor=pd.DataFrame() BatDiag=CBMSBatDiag.BatDiag(df_bms) df_res=BatDiag.diag(df_diag_ram, df_soh, df_sor, df_adjust_param, df_pack_param, df_algo_param) if not df_res.empty: with open('故障结果.txt','a') as file: file.write(str(df_res)+'\n') except Exception as e: print(repr(e)) mylog.logopt(e) pass if __name__ == "__main__": scheduler = BlockingScheduler() scheduler.add_job(diag_cal, 'interval', seconds=60) try: scheduler.start() except: scheduler.shutdown()