deploy_sta.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. __author__ = 'lmstack'
  2. #coding=utf-8
  3. import os
  4. import datetime
  5. import pandas as pd
  6. from LIB.BACKEND import DBManager, Log
  7. from sqlalchemy import create_engine
  8. from sqlalchemy.orm import sessionmaker
  9. import time, datetime
  10. import dateutil.relativedelta
  11. import traceback
  12. from LIB.MIDDLE.CellStateEstimation.Common import log
  13. from LIB.MIDDLE.SaftyCenter.Offline import offline_alarm_sta
  14. from urllib import parse
  15. import pymysql
  16. from LIB.BACKEND import DBManager
  17. if __name__ == "__main__":
  18. # 更新sn列表
  19. host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
  20. port=3306
  21. db='qixiang_oss'
  22. user='qx_algo_rw'
  23. password='qx@123456'
  24. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  25. cursor = conn.cursor()
  26. cursor.execute("select sn, imei, add_time from app_device where status in (1,2,3)")
  27. res = cursor.fetchall()
  28. df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
  29. df_sn = df_sn.reset_index(drop=True)
  30. cursor.close()
  31. conn.close();
  32. df_sn['factory'] = '骑享'
  33. db = 'qx_cas'
  34. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  35. cursor = conn.cursor()
  36. cursor.execute("select sn, factory from sn_list")
  37. res = cursor.fetchall()
  38. df_sn2 = pd.DataFrame(res, columns=['sn', 'factory'])
  39. df_sn2['imei'] = ""
  40. df_sn2['factory'] = '金茂换电'
  41. df_sn = pd.concat([df_sn, df_sn2], axis=0)
  42. df_sn = df_sn.reset_index(drop=True)
  43. # 日志配置
  44. now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
  45. log_path = 'log_sta/' + now_str
  46. if not os.path.exists(log_path):
  47. os.makedirs(log_path)
  48. log = Log.Mylog(log_name='saftyCenter_offlinesta', log_level = 'info')
  49. log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
  50. log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
  51. logger = log.get_logger()
  52. logger.info("pid is {}".format(os.getpid()))
  53. try:
  54. # 算法参数
  55. host='172.16.121.236'
  56. port=3306
  57. db='fastfun'
  58. user='readonly'
  59. password='Fast1234'
  60. db_iotp_engine = create_engine(
  61. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  62. user, parse.quote_plus(password), host, port, db
  63. ))
  64. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  65. port=3306
  66. db='qx_cas'
  67. user='qx_algo_rw'
  68. password='qx@123456'
  69. db_qxcas_engine = create_engine(
  70. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  71. user, parse.quote_plus(password), host, port, db
  72. ))
  73. db = 'safety_platform'
  74. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  75. db_sp_engine = create_engine(
  76. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  77. user, parse.quote_plus(password), host, port, db
  78. ))
  79. logger.info("pid-{} START!".format(os.getpid()))
  80. offline_alarm_sta.offline_alarm_sta(df_sn, db_iotp_engine, db_qxcas_engine, conn, db_sp_engine)
  81. logger.info("pid-{} DONE!".format(os.getpid()))
  82. except:
  83. logger.error(traceback.format_exc)
  84. logger.error("任务运行错误", exc_info=True)
  85. db_iotp_engine.dispose()
  86. db_qxcas_engine.dispose()
  87. conn.close()