|
@@ -1,19 +1,22 @@
|
|
-from coreV0 import *
|
|
|
|
|
|
+from LIB.MIDDLE.InfoChrgDrive.Charge.V1_0_0.coreV0 import *
|
|
import pymysql
|
|
import pymysql
|
|
import datetime
|
|
import datetime
|
|
import pandas as pd
|
|
import pandas as pd
|
|
from LIB.BACKEND import DBManager
|
|
from LIB.BACKEND import DBManager
|
|
|
|
+dbManager = DBManager.DBManager()
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy import create_engine
|
|
from urllib import parse
|
|
from urllib import parse
|
|
import datetime, time
|
|
import datetime, time
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
-from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
|
|
|
|
-#from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
|
|
|
|
-from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
|
|
|
|
+import os
|
|
|
|
+import traceback
|
|
|
|
+import logging
|
|
|
|
+import logging.handlers
|
|
|
|
|
|
#...................................充电技术指标统计函数......................................................................................................................
|
|
#...................................充电技术指标统计函数......................................................................................................................
|
|
def diag_cal():
|
|
def diag_cal():
|
|
global SNnums
|
|
global SNnums
|
|
|
|
+ global kmeans1,kmeans2,kmeans3,kmeans4,kmeans5
|
|
|
|
|
|
start=time.time()
|
|
start=time.time()
|
|
now_time=datetime.datetime.now()
|
|
now_time=datetime.datetime.now()
|
|
@@ -24,9 +27,9 @@ def diag_cal():
|
|
#数据库配置
|
|
#数据库配置
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
- db='qx_cas'
|
|
|
|
- user='qx_read'
|
|
|
|
- password='Qx@123456'
|
|
|
|
|
|
+ db='safety_platform'
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password='qx@123456'
|
|
|
|
|
|
#读取结果库数据......................................................
|
|
#读取结果库数据......................................................
|
|
param='sn,time_st,time_end,status,delta_time,soc_st,soc_end,volt_st,volt_end,diffvolt_st,diffvolt_end, \
|
|
param='sn,time_st,time_end,status,delta_time,soc_st,soc_end,volt_st,volt_end,diffvolt_st,diffvolt_end, \
|
|
@@ -46,8 +49,6 @@ def diag_cal():
|
|
user, parse.quote_plus(password), host, port, db
|
|
user, parse.quote_plus(password), host, port, db
|
|
))
|
|
))
|
|
|
|
|
|
- mylog=log.Mylog('log_info_charge.txt','error')
|
|
|
|
- mylog.logcfg()
|
|
|
|
|
|
|
|
for sn in SNnums:
|
|
for sn in SNnums:
|
|
try:
|
|
try:
|
|
@@ -59,7 +60,7 @@ def diag_cal():
|
|
df_gps = df_data['gps']
|
|
df_gps = df_data['gps']
|
|
|
|
|
|
#读取城市天气数据........................................................................................................................................................
|
|
#读取城市天气数据........................................................................................................................................................
|
|
- gpscity=pd.read_csv('gps.csv')
|
|
|
|
|
|
+ gpscity=pd.read_csv('LIB/MIDDLE/InfoChrgDrive/Charge/gps.csv')
|
|
|
|
|
|
|
|
|
|
#调用主函数................................................................................................................................................................
|
|
#调用主函数................................................................................................................................................................
|
|
@@ -78,11 +79,9 @@ def diag_cal():
|
|
time_end=chrg_last['time_end']
|
|
time_end=chrg_last['time_end']
|
|
|
|
|
|
df_diag_new,df_diag_change=pro_output(df_merge,sn,gpscity,chrg_last)
|
|
df_diag_new,df_diag_change=pro_output(df_merge,sn,gpscity,chrg_last)
|
|
- kmeans1 = joblib.load('kmeans1.pkl')
|
|
|
|
- kmeans2 = joblib.load('kmeans2.pkl')
|
|
|
|
- kmeans3 = joblib.load('kmeans3.pkl')
|
|
|
|
- df_diag_new=prediction(df_diag_new,kmeans1,kmeans2,kmeans3)
|
|
|
|
- df_diag_change=prediction(df_diag_change,kmeans1,kmeans2,kmeans3)
|
|
|
|
|
|
+
|
|
|
|
+ df_diag_new=prediction(df_diag_new,kmeans1,kmeans2,kmeans3,kmeans4,kmeans5)
|
|
|
|
+ df_diag_change=prediction(df_diag_change,kmeans1,kmeans2,kmeans3,kmeans4,kmeans5)
|
|
if not df_diag_change.empty: #需变更的结果非空
|
|
if not df_diag_change.empty: #需变更的结果非空
|
|
cursor.execute("DELETE FROM algo_charge_info WHERE time_end = '{}' and sn='{}'".format(time_end,sn))
|
|
cursor.execute("DELETE FROM algo_charge_info WHERE time_end = '{}' and sn='{}'".format(time_end,sn))
|
|
mysql.commit()
|
|
mysql.commit()
|
|
@@ -96,22 +95,63 @@ def diag_cal():
|
|
print(end-start)
|
|
print(end-start)
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- print(repr(e))
|
|
|
|
- mylog.logopt(e)
|
|
|
|
|
|
+ logger.error(str(e))
|
|
|
|
+ logger.error(traceback.format_exc())
|
|
|
|
|
|
cursor.close()
|
|
cursor.close()
|
|
mysql.close()
|
|
mysql.close()
|
|
|
|
|
|
#...............................................主函数起定时作用.......................................................................................................................
|
|
#...............................................主函数起定时作用.......................................................................................................................
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
|
+ # 日志
|
|
|
|
+ log_path = 'log/'
|
|
|
|
+ if not os.path.exists(log_path):
|
|
|
|
+ os.makedirs(log_path)
|
|
|
|
+ logger = logging.getLogger("main")
|
|
|
|
+ logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
- #excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
|
|
|
|
- excelpath='sn-20210903.xlsx'
|
|
|
|
- dataSOH = pd.read_excel('sn-20210903.xlsx',sheet_name='sn-20210903')
|
|
|
|
- SNnums = list(dataSOH['sn'])
|
|
|
|
|
|
+ # 根据日期滚动(每天产生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()))
|
|
|
|
+
|
|
|
|
+ # # 更新sn列表
|
|
|
|
+ host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
|
|
|
|
+ port=3306
|
|
|
|
+ db='qixiang_oss'
|
|
|
|
+ user='qixiang_oss'
|
|
|
|
+ password='Qixiang2021'
|
|
|
|
+ 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)
|
|
|
|
+ conn.close();
|
|
|
|
|
|
- mylog=log.Mylog('log_info_charge.txt','error')
|
|
|
|
- mylog.logcfg()
|
|
|
|
|
|
+ SNnums = list(df_sn['sn'])
|
|
|
|
+
|
|
|
|
+ kmeans1 = joblib.load('LIB/MIDDLE/InfoChrgDrive/Charge/kmeans1.pkl')
|
|
|
|
+ kmeans2 = joblib.load('LIB/MIDDLE/InfoChrgDrive/Charge/kmeans2.pkl')
|
|
|
|
+ kmeans3 = joblib.load('LIB/MIDDLE/InfoChrgDrive/Charge/kmeans3.pkl')
|
|
|
|
+ kmeans4 = joblib.load('LIB/MIDDLE/InfoChrgDrive/Charge/kmeans4.pkl')
|
|
|
|
+ kmeans5 = joblib.load('LIB/MIDDLE/InfoChrgDrive/Charge/kmeans5.pkl')
|
|
|
|
|
|
diag_cal()
|
|
diag_cal()
|
|
#定时任务.......................................................................................................................................................................
|
|
#定时任务.......................................................................................................................................................................
|
|
@@ -122,5 +162,5 @@ if __name__ == "__main__":
|
|
scheduler.start()
|
|
scheduler.start()
|
|
except Exception as e:
|
|
except Exception as e:
|
|
scheduler.shutdown()
|
|
scheduler.shutdown()
|
|
- print(repr(e))
|
|
|
|
- mylog.logopt(e)
|
|
|
|
|
|
+ logger.error(str(e))
|
|
|
|
+ logger.error(traceback.format_exc())
|