deploy_sta.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.Low_Soc_Alarm import low_soc_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_lowsocsta', 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='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  56. port=3306
  57. db='qx_cas'
  58. user='qx_algo_rw'
  59. password='qx@123456'
  60. db_qxcas_engine = create_engine(
  61. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  62. user, parse.quote_plus(password), host, port, db
  63. ))
  64. db = 'safety_platform'
  65. conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
  66. cursor = conn.cursor()
  67. db_sp_engine = create_engine(
  68. "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
  69. user, parse.quote_plus(password), host, port, db
  70. ))
  71. logger.info("pid-{} START!".format(os.getpid()))
  72. low_soc_alarm_sta.low_soc_alarm_sta(df_sn, db_qxcas_engine, conn, db_sp_engine)
  73. logger.info("pid-{} DONE!".format(os.getpid()))
  74. except:
  75. logger.error(traceback.format_exc)
  76. logger.error("任务运行错误", exc_info=True)
  77. db_sp_engine.dispose()
  78. db_qxcas_engine.dispose()
  79. conn.close()