123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- __author__ = 'lmstack'
- #coding=utf-8
- import os
- import pandas as pd
- from LIB.BACKEND import DBManager, Log
- from sqlalchemy import create_engine
- from sqlalchemy.orm import sessionmaker
- import time, datetime
- import traceback
- from LIB.MIDDLE.CellStateEstimation.Common import log
- from LIB.MIDDLE.SaftyCenter.Low_Soc_Alarm import low_soc_alarm_sta
- from urllib import parse
- import pymysql
- from LIB.BACKEND import DBManager
- import logging
- import logging.handlers
- import re
- if __name__ == "__main__":
-
- # 更新sn列表
- host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
- port=3306
- db='qixiang_oss'
- user='qx_algo_rw'
- password='qx@123456'
- conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
- cursor = conn.cursor()
- cursor.execute("select sn, imei, add_time from app_device where status in (1,2,3)")
- res = cursor.fetchall()
- df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
- df_sn = df_sn.reset_index(drop=True)
- cursor.close()
- conn.close();
- df_sn['factory'] = '骑享'
-
- db = 'qx_cas'
- conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
- cursor = conn.cursor()
- cursor.execute("select sn, factory from sn_list")
- res = cursor.fetchall()
- df_sn2 = pd.DataFrame(res, columns=['sn', 'factory'])
- df_sn2['imei'] = ""
- df_sn2['factory'] = '金茂换电'
- df_sn = pd.concat([df_sn, df_sn2], axis=0)
- df_sn = df_sn.reset_index(drop=True)
-
- # 日志
- log_path = 'log_sta/'
- if not os.path.exists(log_path):
- os.makedirs(log_path)
- logger = logging.getLogger("main")
- logger.setLevel(logging.DEBUG)
-
- # 根据日期滚动(每天产生1个文件)
- fh = logging.handlers.TimedRotatingFileHandler(filename='{}/main_info.log'.format(log_path), when="D", interval=1, backupCount=30,
- encoding="utf-8")
- formatter = logging.Formatter("%(asctime)s - %(name)s-%(levelname)s %(message)s")
- fh.suffix = "%Y-%m-%d_%H-%M-%S"
- fh.extMatch = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}")
- fh.setFormatter(formatter)
- fh.setLevel(logging.INFO)
- logger.addHandler(fh)
- fh = logging.handlers.TimedRotatingFileHandler(filename='{}/main_error.log'.format(log_path), when="D", interval=1, backupCount=30,
- encoding="utf-8")
- formatter = logging.Formatter("%(asctime)s - %(name)s-%(levelname)s %(message)s")
- fh.suffix = "%Y-%m-%d_%H-%M-%S"
- fh.extMatch = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}")
- fh.setFormatter(formatter)
- fh.setLevel(logging.ERROR)
- logger.addHandler(fh)
- logger.info("pid is {}".format(os.getpid()))
- try:
- # 算法参数
- host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
- port=3306
- db='qx_cas'
- user='qx_algo_rw'
- password='qx@123456'
- db_qxcas_engine = create_engine(
- "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
- user, parse.quote_plus(password), host, port, db
- ))
- db = 'safety_platform'
- conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
- cursor = conn.cursor()
- db_sp_engine = create_engine(
- "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
- user, parse.quote_plus(password), host, port, db
- ))
- logger.info("pid-{} START!".format(os.getpid()))
- low_soc_alarm_sta.low_soc_alarm_sta(df_sn, db_qxcas_engine, conn, db_sp_engine)
- logger.info("pid-{} DONE!".format(os.getpid()))
-
- except:
- logger.error(traceback.format_exc)
- logger.error("任务运行错误", exc_info=True)
- db_sp_engine.dispose()
- db_qxcas_engine.dispose()
- conn.close()
-
|