|
@@ -2,12 +2,16 @@
|
|
|
#预测及异常预警
|
|
|
|
|
|
from LIB.BACKEND import DBManager
|
|
|
+
|
|
|
dbManager = DBManager.DBManager()
|
|
|
-from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
|
+import datetime
|
|
|
+
|
|
|
+import joblib
|
|
|
import pandas as pd
|
|
|
+import pymysql
|
|
|
+from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
|
+
|
|
|
from anomalyPCA import *
|
|
|
-import joblib
|
|
|
-import datetime
|
|
|
|
|
|
dataSOH = pd.read_excel('sn-20210903.xlsx',sheet_name='sn-20210903')
|
|
|
fileNames = dataSOH['sn']
|
|
@@ -23,13 +27,34 @@ start_time=str(start_time)
|
|
|
mylog=log.Mylog('log.txt','error')
|
|
|
mylog.logcfg()
|
|
|
|
|
|
+#数据库配置
|
|
|
+host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
|
+port=3306
|
|
|
+user='qx_algo_readonly'
|
|
|
+password = 'qx@123456'
|
|
|
+
|
|
|
+#读取故障结果库中code==119且end_time='0000-00-00 00:00:00'...............................
|
|
|
+db='safety_platform'
|
|
|
+mysql = pymysql.connect (host=host, port=port, user=user, password=password, database=db)
|
|
|
+cursor = mysql.cursor()
|
|
|
+param='start_time,end_time,product_id,code,level,info,advice'
|
|
|
+tablename='all_fault_info'
|
|
|
+sql = "select %s from %s where code='C493' and end_time='0000-00-00 00:00:00'" %(param,tablename)
|
|
|
+cursor.execute(sql)
|
|
|
+res = cursor.fetchall()
|
|
|
+df_diag_ram= pd.DataFrame(res,columns=param.split(','))
|
|
|
+cursor.close()
|
|
|
+mysql.close()
|
|
|
+
|
|
|
anomalies=pd.DataFrame()
|
|
|
+df_res=pd.DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice'])
|
|
|
for k in range(l):
|
|
|
try:
|
|
|
sn = fileNames[k]
|
|
|
+ df_diag_ram_sn=df_diag_ram[df_diag_ram['product_id']==sn]
|
|
|
df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
|
|
|
data_test = df_data['bms']
|
|
|
-
|
|
|
+ data_test=data_test[data_test['SOC[%]']>20]
|
|
|
if len(data_test)>0:
|
|
|
pca1 = joblib.load('pca1_'+sn+'.m')
|
|
|
pca2 = joblib.load('pca2_'+sn+'.m')
|
|
@@ -45,8 +70,31 @@ for k in range(l):
|
|
|
outliers['sn']=sn
|
|
|
anomalies=anomalies.append(outliers)
|
|
|
anomalies.to_csv('anomalies.csv',encoding='gbk')
|
|
|
+ if df_diag_ram_sn.empty:
|
|
|
+ product_id=sn
|
|
|
+ start_time=outliers.loc[0,'时间']
|
|
|
+ if outliers.loc[-1,'时间'] == pred1.loc[-1,'时间']:
|
|
|
+ end_time='0000-00-00 00:00:00'
|
|
|
+ else:
|
|
|
+ end_time=outliers.loc[-1,'时间']
|
|
|
+ code='C493'
|
|
|
+ level=4
|
|
|
+ info='热失控预警'
|
|
|
+ advice='建议返厂维修'
|
|
|
+ df_res=df_res.append([start_time, end_time,product_id, code, level, info,advice])
|
|
|
+ with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控报警.txt','a') as file:
|
|
|
+ file.write(str(tuple(df_res.iloc[-1]))+'\n')
|
|
|
+ else:
|
|
|
+ if outliers.loc[-1,'时间'] == pred1.loc[-1,'时间']:
|
|
|
+ end_time='0000-00-00 00:00:00'
|
|
|
+ else:
|
|
|
+ end_time=outliers.loc[-1,'时间']
|
|
|
+ df_diag_ram_sn['end_time']=end_time
|
|
|
+ with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控报警.txt','a') as file:
|
|
|
+ file.write(str(tuple(df_diag_ram_sn.iloc[-1]))+'\n')
|
|
|
+
|
|
|
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
mylog.logopt(sn,e)
|
|
|
- pass
|
|
|
+ pass
|