|
@@ -0,0 +1,52 @@
|
|
|
+#热失控预警:PCA异常指数
|
|
|
+#预测及异常预警
|
|
|
+
|
|
|
+from LIB.BACKEND import DBManager
|
|
|
+dbManager = DBManager.DBManager()
|
|
|
+from LIB.MIDDLE.CellStateEstimation.Common import log
|
|
|
+import pandas as pd
|
|
|
+from anomalyPCA import *
|
|
|
+import joblib
|
|
|
+import datetime
|
|
|
+
|
|
|
+dataSOH = pd.read_excel('sn-20210903.xlsx',sheet_name='sn-20210903')
|
|
|
+fileNames = dataSOH['sn']
|
|
|
+fileNames = list(fileNames)
|
|
|
+l = len(fileNames)
|
|
|
+
|
|
|
+now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') #type: str
|
|
|
+now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S') #type: datetime
|
|
|
+start_time=now_time-datetime.timedelta(hours=3)
|
|
|
+end_time=str(now_time)
|
|
|
+start_time=str(start_time)
|
|
|
+
|
|
|
+mylog=log.Mylog('log.txt','error')
|
|
|
+mylog.logcfg()
|
|
|
+
|
|
|
+anomalies=pd.DataFrame()
|
|
|
+for k in range(l):
|
|
|
+ try:
|
|
|
+ sn = fileNames[k]
|
|
|
+ df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
|
|
|
+ data_test = df_data['bms']
|
|
|
+
|
|
|
+ if len(data_test)>0:
|
|
|
+ pca1 = joblib.load('pca1_'+sn+'.m')
|
|
|
+ pca2 = joblib.load('pca2_'+sn+'.m')
|
|
|
+ res1 = pd.read_csv('res1_'+sn+'.csv',encoding='gbk')
|
|
|
+ res2 = pd.read_csv('res2_'+sn+'.csv',encoding='gbk')
|
|
|
+ pred1,pred2=prediction(data_test,pca1,pca2)
|
|
|
+ outliers1=detect_outliers(res1,pred1,threshold=30)
|
|
|
+ outliers2=detect_outliers(res2,pred2,threshold=16)
|
|
|
+ if (len(outliers1)>0) & (len(outliers2)>0):
|
|
|
+ outliers=check_anomaly(outliers1,outliers2)
|
|
|
+ if len(outliers)>5:
|
|
|
+ outliers.to_csv('outliers'+sn+'.csv',encoding='gbk')
|
|
|
+ outliers['sn']=sn
|
|
|
+ anomalies=anomalies.append(outliers)
|
|
|
+ anomalies.to_csv('anomalies.csv',encoding='gbk')
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ mylog.logopt(sn,e)
|
|
|
+ pass
|