main.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import CBMSBatDiag
  2. import log
  3. import pymysql
  4. from apscheduler.schedulers.blocking import BlockingScheduler
  5. import datetime
  6. import pandas as pd
  7. from LIB.BACKEND import DBManager, Log
  8. import time, datetime
  9. import os
  10. def diag_cal():
  11. filepath=r'D:\Develop\User\Songpengfei\data_analyze_platform\WORK\03hezhong\98Data'
  12. files=os.listdir(filepath)
  13. # now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  14. # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  15. # start_time=now_time-datetime.timedelta(days=30)
  16. # end_time=str(now_time)
  17. # start_time=str(start_time)
  18. #数据库配置
  19. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  20. port=3306
  21. user='hz_dev'
  22. password='Qx@123456'
  23. #读取故障结果库中code==110且end_time='0000-00-00 00:00:00'...............................
  24. db='hz_dev'
  25. mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
  26. cursor = mysql.cursor()
  27. param='algo_id,pack_code,threshold,confirm_time,remove_time,param'
  28. sql = "select %s from %s" %(param,'algo_adjustable_param')
  29. cursor.execute(sql)
  30. res = cursor.fetchall()
  31. df_adjust_param= pd.DataFrame(res,columns=param.split(','))
  32. param='algo_id,is_activate,global_param'
  33. sql = "select %s from %s" %(param,'algo_list')
  34. cursor.execute(sql)
  35. res = cursor.fetchall()
  36. df_algo_param= pd.DataFrame(res,columns=param.split(','))
  37. df_algo_param=df_algo_param.set_index('algo_id')
  38. param='pack_code,param'
  39. sql = "select %s from %s" %(param,'algo_pack_param')
  40. cursor.execute(sql)
  41. res = cursor.fetchall()
  42. df_pack_param= pd.DataFrame(res,columns=param.split(','))
  43. df_pack_param['param']=df_pack_param['param'].map(lambda x:eval(x))
  44. a=df_pack_param['param'].values.tolist()
  45. df_pack_param=pd.DataFrame(a)
  46. cursor.close()
  47. mysql.close()
  48. #log信息配置
  49. mylog=log.Mylog('log.txt','error')
  50. mylog.logcfg()
  51. for filename in files:
  52. try:
  53. df_bms = pd.read_excel(filepath+'\\'+filename)
  54. df_diag_ram=pd.DataFrame(columns=['start_time', 'end_time', 'vin', 'sn', 'model', 'fault_code', 'fault_reason', 'fault_advice', 'fault_location'])
  55. df_soh=pd.DataFrame()
  56. df_sor=pd.DataFrame()
  57. BatDiag=CBMSBatDiag.BatDiag(df_bms)
  58. df_res=BatDiag.diag(df_diag_ram, df_soh, df_sor, df_adjust_param, df_pack_param, df_algo_param)
  59. if not df_res.empty:
  60. with open('故障结果.txt','a') as file:
  61. file.write(str(df_res)+'\n')
  62. except Exception as e:
  63. print(repr(e))
  64. mylog.logopt(e)
  65. pass
  66. if __name__ == "__main__":
  67. scheduler = BlockingScheduler()
  68. scheduler.add_job(diag_cal, 'interval', seconds=60)
  69. try:
  70. scheduler.start()
  71. except:
  72. scheduler.shutdown()