Quellcode durchsuchen

Merge branch 'dev_awg' into dev_david
增加LSTM变型后合并

David vor 2 Wochen
Ursprung
Commit
34838899ea

+ 7 - 4
data_processing/data_operation/data_nwp_ftp.py

@@ -241,10 +241,13 @@ def get_nwp_from_ftp():
         date, moment = get_moment_next(args.get('dt'))
         logger.info("从日期{}时刻{}开始查找文件".format(date, moment))
         success = select_file_to_mongo(args, date, moment)
-        while not success:
-            date, moment = get_previous_moment(date, moment)
-            logger.info("未找到,从日期{}时刻{}开始查找文件".format(date, moment))
-            success = select_file_to_mongo(args, date, moment)
+        new_date = date
+        i = 1
+        while not success and date == new_date and i <= 2:
+            new_date, moment = get_previous_moment(date, moment)
+            logger.info("未找到,从日期{}时刻{}开始查找文件".format(new_date, moment))
+            success = select_file_to_mongo(args, new_date, moment)
+            i += 1
     except Exception as e:
         my_exception = traceback.format_exc()
         my_exception.replace("\n", "\t")

+ 10 - 9
data_processing/data_operation/pre_prod_ftp.py

@@ -106,15 +106,16 @@ def get_next_target_time(current_time=None):
     if current_time is None:
         current_time = datetime.now(timezone('Asia/Shanghai'))
 
-    target_hours = [0, 6, 12, 18]
+    # target_hours = [0, 6, 12, 18]
     current_hour = current_time.hour
-
-    for hour in sorted(target_hours):
-        if current_hour <= hour:
-            return current_time.replace(hour=hour, minute=0, second=0, microsecond=0)
-
-    # 如果当前时间超过所有目标小时,使用次日0点
-    return (current_time + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
+    if current_hour >= 0 and current_hour <= 2:
+        return current_time.replace(hour=0, minute=0, second=0, microsecond=0)
+    elif current_hour >= 3 and current_hour <= 6:
+        return current_time.replace(hour=6, minute=0, second=0, microsecond=0)
+    elif current_hour >= 7 and current_hour <= 12:
+        return current_time.replace(hour=12, minute=0, second=0, microsecond=0)
+    else:
+        return current_time.replace(hour=18, minute=0, second=0, microsecond=0)
 
 
 def download_files_via_sftp(mappings, datetime_str, local_temp_dir, model_type):
@@ -332,7 +333,7 @@ def configure_scheduler():
 
     # 配置第一个触发器:处理每个主小时段的前 60 分钟(0-50 分钟)
     trigger1 = CronTrigger(
-        hour='23,5,11,17',  # 主触发小时
+        hour='1,5,12,17',  # 主触发小时
         minute='0-50/10',  # 每 10 分钟一次,覆盖 00:00-00:50
         timezone='Asia/Shanghai'  # 按需设置时区
     )

+ 2 - 2
models_processing/model_predict/model_prediction_bp.py

@@ -12,7 +12,7 @@ app = Flask('model_prediction_bp——service')
 def model_prediction(df,args):
     if 'is_limit' in df.columns:
         df = df[df['is_limit'] == False]
-    features, time_steps, col_time, model_name,howLongAgo,farm_id = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],int(args['howLongAgo']),args['farm_id']
+    features, time_steps, col_time, model_name,howLongAgo,farm_id,target = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],int(args['howLongAgo']),args['farm_id'],args['target']
     feature_scaler,target_scaler = get_scaler_model_from_mongo(args)
     df = df.sort_values(by=col_time).fillna(method='ffill').fillna(method='bfill')
     scaled_features = feature_scaler.transform(df[features])
@@ -28,7 +28,7 @@ def model_prediction(df,args):
     result['model'] = model_name
     result['howLongAgo'] = howLongAgo
     result['farm_id'] = farm_id
-    return result[['dateTime', 'howLongAgo', 'model', 'farm_id', 'power_forecast', 'realPower']]
+    return result[['dateTime', 'howLongAgo', 'model', 'farm_id', 'power_forecast', target]]
 
 
 @app.route('/model_prediction_bp', methods=['POST'])

+ 2 - 2
models_processing/model_predict/model_prediction_lightgbm.py

@@ -73,7 +73,7 @@ def forecast_data_distribution(pre_data,args):
 
 
 def model_prediction(df,args):
-    mongodb_connection,mongodb_database,mongodb_model_table,model_name,howLongAgo,farm_id = "mongodb://root:sdhjfREWFWEF23e@192.168.1.43:30000/",args['mongodb_database'],args['mongodb_model_table'],args['model_name'],int(args['howLongAgo']),args['farm_id']
+    mongodb_connection,mongodb_database,mongodb_model_table,model_name,howLongAgo,farm_id,target = "mongodb://root:sdhjfREWFWEF23e@192.168.1.43:30000/",args['mongodb_database'],args['mongodb_model_table'],args['model_name'],int(args['howLongAgo']),args['farm_id'],args['target']
     client = MongoClient(mongodb_connection)
     db = client[mongodb_database]
     collection = db[mongodb_model_table]
@@ -92,7 +92,7 @@ def model_prediction(df,args):
         df['farm_id'] = farm_id
         print("model predict result  successfully!")
 
-    return df[['dateTime','howLongAgo','model','farm_id','power_forecast','realPower']]
+    return df[['dateTime','howLongAgo','model','farm_id','power_forecast',target]]
 
 
 @app.route('/model_prediction_lightgbm', methods=['POST'])

+ 2 - 2
models_processing/model_predict/model_prediction_lstm.py

@@ -63,7 +63,7 @@ def forecast_data_distribution(pre_data,args):
 def model_prediction(df,args):
     if 'is_limit' in df.columns:
         df = df[df['is_limit'] == False]
-    features, time_steps, col_time, model_name,howLongAgo,farm_id = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],int(args['howLongAgo']),args['farm_id']
+    features, time_steps, col_time, model_name,howLongAgo,farm_id,target = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],int(args['howLongAgo']),args['farm_id'],args['target']
     feature_scaler,target_scaler = get_scaler_model_from_mongo(args)
     df = df.sort_values(by=col_time).fillna(method='ffill').fillna(method='bfill')
     scaled_features = feature_scaler.transform(df[features])
@@ -78,7 +78,7 @@ def model_prediction(df,args):
     result['howLongAgo'] = howLongAgo
     result['farm_id'] = farm_id
     result['model'] = model_name
-    return result[['dateTime', 'howLongAgo', 'model', 'farm_id', 'power_forecast', 'realPower']]
+    return result[['dateTime', 'howLongAgo', 'model', 'farm_id', 'power_forecast', target]]
 
 
 @app.route('/model_prediction_lstm', methods=['POST'])

+ 1 - 1
models_processing/model_train/model_training_lstm.py

@@ -86,7 +86,7 @@ def build_model(data, args):
     # 使用GPU进行训练
     with tf.device('/GPU:1'):
         history = model.fit(X_train, y_train,
-                        epochs=5,
+                        epochs=100,
                         batch_size=32,
                         validation_data=(X_test, y_test),
                         verbose=2,