qingfeng 2 years ago
parent
commit
ec3e6c5283

+ 23 - 4
LIB/FRONTEND/FaultDetection/main_pred.py

@@ -21,6 +21,7 @@ import re
 #...................................故障检测函数......................................................................................................................
 #...................................故障检测函数......................................................................................................................
 def diag_cal():
 def diag_cal():
     global SNnums
     global SNnums
+    global scaler_dict, scaler2_dict, model_dict, model2_dict
 
 
     start=time.time()
     start=time.time()
     now_time=datetime.datetime.now()
     now_time=datetime.datetime.now()
@@ -67,11 +68,11 @@ def diag_cal():
                 if len(df_stand)>0:
                 if len(df_stand)>0:
                     #读取训练产出的缩放指标:均值&方差
                     #读取训练产出的缩放指标:均值&方差
                     logger.info("SN: {} 数据开始模型预测".format(sn))
                     logger.info("SN: {} 数据开始模型预测".format(sn))
-                    scaler = pickle.load(open('D:/deploy/python_platform/data_analyze_platform/LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerV_'+group+'_10.pkl', 'rb'))
-                    scaler2 = pickle.load(open('D:/deploy/python_platform/data_analyze_platform/LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerT_'+group+'_10.pkl', 'rb'))
+                    scaler = scaler_dict[group]
+                    scaler2 = scaler2_dict[group]
                     #读取训练产出的模型状态空间:电压模型&温度模型
                     #读取训练产出的模型状态空间:电压模型&温度模型
-                    model = load_model('D:/deploy/python_platform/data_analyze_platform/LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelV_'+group+'_10.h5')
-                    model2 = load_model('D:/deploy/python_platform/data_analyze_platform/LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelT_'+group+'_10.h5')
+                    model = model_dict[group]
+                    model2 = model2_dict[group]
                     res=prediction(df_stand,scaler,scaler2,model,model2)
                     res=prediction(df_stand,scaler,scaler2,model,model2)
                     if len(res)>0:
                     if len(res)>0:
                         df_res2,diff=threshold(res,group,end_time)
                         df_res2,diff=threshold(res,group,end_time)
@@ -145,6 +146,24 @@ if __name__ == "__main__":
     
     
     SNnums = list(df_sn['sn'])
     SNnums = list(df_sn['sn'])
     
     
+    scaler_list=[]
+    scaler2_list=[]
+    model_list=[]
+    model2_list=[]
+    for group in ['MGMLX','PK504','PK502','PK500','MGMCL']:
+        scaler = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerV_'+group+'_10.pkl', 'rb'))
+        scaler2 = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerT_'+group+'_10.pkl', 'rb'))
+        model = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelV_'+group+'_10.h5')
+        model2 = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelT_'+group+'_10.h5')
+        scaler_list.append(scaler)
+        scaler2_list.append(scaler2)
+        model_list.append(model)
+        model2_list.append(model2)
+    scaler_dict={'MGMLX':scaler_list[0],'PK504':scaler_list[1],'PK502':scaler_list[2],'PK500':scaler_list[3],'MGMCL':scaler_list[4]}
+    scaler2_dict={'MGMLX':scaler2_list[0],'PK504':scaler2_list[1],'PK502':scaler2_list[2],'PK500':scaler2_list[3],'MGMCL':scaler2_list[4]}
+    model_dict={'MGMLX':model_list[0],'PK504':model_list[1],'PK502':model_list[2],'PK500':model_list[3],'MGMCL':model_list[4]}
+    model2_dict={'MGMLX':model2_list[0],'PK504':model2_list[1],'PK502':model2_list[2],'PK500':model2_list[3],'MGMCL':model2_list[4]}
+    logger.info("模型加载完成")
 
 
     diag_cal()
     diag_cal()
     #定时任务.......................................................................................................................................................................
     #定时任务.......................................................................................................................................................................

+ 22 - 20
LIB/MIDDLE/FaultDetection/V1_0_2/main_pred.py

@@ -1,3 +1,4 @@
+
 from LIB.MIDDLE.FaultDetection.V1_0_2.aelstm import *
 from LIB.MIDDLE.FaultDetection.V1_0_2.aelstm import *
 import pymysql
 import pymysql
 import datetime
 import datetime
@@ -20,6 +21,7 @@ import re
 #...................................故障检测函数......................................................................................................................
 #...................................故障检测函数......................................................................................................................
 def diag_cal():
 def diag_cal():
     global SNnums
     global SNnums
+    global scaler_dict, scaler2_dict, model_dict, model2_dict
 
 
     start=time.time()
     start=time.time()
     now_time=datetime.datetime.now()
     now_time=datetime.datetime.now()
@@ -49,25 +51,7 @@ def diag_cal():
         "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
         "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
             user, parse.quote_plus(password), host, port, db
             user, parse.quote_plus(password), host, port, db
         ))
         ))
-    
-    scaler_list=[]
-    scaler2_list=[]
-    model_list=[]
-    model2_list=[]
-    for group in ['MGMLX','PK504','PK502','PK500','MGMCL']:
-        scaler = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerV_'+group+'_10.pkl', 'rb'))
-        scaler2 = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerT_'+group+'_10.pkl', 'rb'))
-        model = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelV_'+group+'_10.h5')
-        model2 = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelT_'+group+'_10.h5')
-        scaler_list.append(scaler)
-        scaler2_list.append(scaler2)
-        model_list.append(model)
-        model2_list.append(model2)
-    scaler_dict={'MGMLX':scaler_list[0],'PK504':scaler_list[1],'PK502':scaler_list[2],'PK500':scaler_list[3],'MGMCL':scaler_list[4]}
-    scaler2_dict={'MGMLX':scaler2_list[0],'PK504':scaler2_list[1],'PK502':scaler2_list[2],'PK500':scaler2_list[3],'MGMCL':scaler2_list[4]}
-    model_dict={'MGMLX':model_list[0],'PK504':model_list[1],'PK502':model_list[2],'PK500':model_list[3],'MGMCL':model_list[4]}
-    model2_dict={'MGMLX':model2_list[0],'PK504':model2_list[1],'PK502':model2_list[2],'PK500':model2_list[3],'MGMCL':model2_list[4]}
-    
+
 
 
     #调用主函数................................................................................................................................................................
     #调用主函数................................................................................................................................................................
     for sn in SNnums:
     for sn in SNnums:
@@ -162,6 +146,24 @@ if __name__ == "__main__":
     
     
     SNnums = list(df_sn['sn'])
     SNnums = list(df_sn['sn'])
     
     
+    scaler_list=[]
+    scaler2_list=[]
+    model_list=[]
+    model2_list=[]
+    for group in ['MGMLX','PK504','PK502','PK500','MGMCL']:
+        scaler = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerV_'+group+'_10.pkl', 'rb'))
+        scaler2 = pickle.load(open('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/scalerT_'+group+'_10.pkl', 'rb'))
+        model = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelV_'+group+'_10.h5')
+        model2 = load_model('LIB/MIDDLE/FaultDetection/V1_0_2/train_out/modelT_'+group+'_10.h5')
+        scaler_list.append(scaler)
+        scaler2_list.append(scaler2)
+        model_list.append(model)
+        model2_list.append(model2)
+    scaler_dict={'MGMLX':scaler_list[0],'PK504':scaler_list[1],'PK502':scaler_list[2],'PK500':scaler_list[3],'MGMCL':scaler_list[4]}
+    scaler2_dict={'MGMLX':scaler2_list[0],'PK504':scaler2_list[1],'PK502':scaler2_list[2],'PK500':scaler2_list[3],'MGMCL':scaler2_list[4]}
+    model_dict={'MGMLX':model_list[0],'PK504':model_list[1],'PK502':model_list[2],'PK500':model_list[3],'MGMCL':model_list[4]}
+    model2_dict={'MGMLX':model2_list[0],'PK504':model2_list[1],'PK502':model2_list[2],'PK500':model2_list[3],'MGMCL':model2_list[4]}
+    logger.info("模型加载完成")
 
 
     diag_cal()
     diag_cal()
     #定时任务.......................................................................................................................................................................
     #定时任务.......................................................................................................................................................................
@@ -173,4 +175,4 @@ if __name__ == "__main__":
     except Exception as e:
     except Exception as e:
         scheduler.shutdown()
         scheduler.shutdown()
         logger.error(str(e))
         logger.error(str(e))
-        logger.error(traceback.format_exc())
+        logger.error(traceback.format_exc())