From 14e1484751eec738731a7a07c9e6767d947954ba Mon Sep 17 00:00:00 2001 From: jingboyitiji Date: Fri, 28 Mar 2025 10:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=9A=E7=83=AF=E7=83=83=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=85=AB=E5=A4=A7=E7=BB=B4=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_juxiting.py | 16 +++++++++-- lib/dataread.py | 56 ++++++++++++++++++++++++++++++++++++ main_juxiting.py | 20 +++++++------ main_juxiting_yuedu.py | 2 +- main_juxiting_zhoudu.py | 2 +- main_yuanyou.py | 54 ---------------------------------- models/nerulforcastmodels.py | 4 +-- 7 files changed, 84 insertions(+), 70 deletions(-) diff --git a/config_juxiting.py b/config_juxiting.py index eee339d..502ac7d 100644 --- a/config_juxiting.py +++ b/config_juxiting.py @@ -190,7 +190,17 @@ query_data_list_item_nos_data = { } } - +# 八大维度数据项编码 +bdwd_items = { + 'ciri': 'jxtppbdwdcr', + 'benzhou': 'jxtppbdwdbz', + 'cizhou': 'jxtppbdwdcz', + 'gezhou': 'jxtppbdwdgz', + 'ciyue': 'jxtppbdwdcy', + 'cieryue': 'jxtppbdwdcey', + 'cisanyue': 'jxtppbdwdcsy', + 'cisiyue': 'jxtppbdwdcsiy', +} # 北京环境数据库 host = '192.168.101.27' port = 3306 @@ -201,9 +211,9 @@ table_name = 'v_tbl_crude_oil_warning' # 开关 -is_train = True # 是否训练 +is_train = False # 是否训练 is_debug = False # 是否调试 -is_eta = True # 是否使用eta接口 +is_eta = False # 是否使用eta接口 is_market = False # 是否通过市场信息平台获取特征 ,在is_eta 为true 的情况下生效 is_timefurture = True # 是否使用时间特征 is_fivemodels = False # 是否使用之前保存的最佳的5个模型 diff --git a/lib/dataread.py b/lib/dataread.py index ce7cbc7..459b655 100644 --- a/lib/dataread.py +++ b/lib/dataread.py @@ -2259,3 +2259,59 @@ def get_baichuan_data(baichuanidnamedict): df1.drop(columns=['DATA_DATE'], inplace=True) return df1 + + + +def push_market_value(): + config.logger.info('发送预测结果到市场信息平台') + # 读取预测数据和模型评估数据 + predict_file_path = os.path.join(config.dataset, 'predict.csv') + model_eval_file_path = os.path.join(config.dataset, 'model_evaluation.csv') + try: + predictdata_df = pd.read_csv(predict_file_path) + top_models_df = pd.read_csv(model_eval_file_path) + except FileNotFoundError as e: + config.logger.error(f"文件未找到: {e}") + return + + predictdata = predictdata_df.copy() + + # 取模型前十 + top_models = top_models_df['模型(Model)'].head(10).tolist() + + # 计算前十模型的均值 + predictdata_df['top_models_mean'] = predictdata_df[top_models].mean(axis=1) + + # 打印日期和前十模型均值 + print(predictdata_df[['ds', 'top_models_mean']]) + + # 准备要推送的数据 + first_mean = predictdata_df['top_models_mean'].iloc[0] + last_mean = predictdata_df['top_models_mean'].iloc[-1] + # 保留两位小数 + first_mean = round(first_mean, 2) + last_mean = round(last_mean, 2) + + predictdata = [ + { + "dataItemNo": global_config['bdwd_items']['ciri'], + "dataDate": global_config['end_time'].replace('-',''), + "dataStatus": "add", + "dataValue": first_mean + }, + { + "dataItemNo": global_config['bdwd_items']['benzhou'], + "dataDate": global_config['end_time'].replace('-',''), + "dataStatus": "add", + "dataValue": last_mean + } + ] + + print(predictdata) + + # 推送数据到市场信息平台 + try: + push_market_data(predictdata) + except Exception as e: + config.logger.error(f"推送数据失败: {e}") + diff --git a/main_juxiting.py b/main_juxiting.py index 2b878e3..a6371e9 100644 --- a/main_juxiting.py +++ b/main_juxiting.py @@ -347,7 +347,7 @@ def predict_main(): # # 模型报告 logger.info('制作报告ing') title = f'{settings}--{end_time}-预测报告' # 报告标题 - reportname = f'Brent原油大模型日度预测--{end_time}.pdf' # 报告文件名 + reportname = f'聚烯烃PP大模型日度预测--{end_time}.pdf' # 报告文件名 reportname = reportname.replace(':', '-') # 替换冒号 pp_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time, reportname=reportname, sqlitedb=sqlitedb), @@ -355,6 +355,8 @@ def predict_main(): logger.info('制作报告end') logger.info('模型训练完成') + push_market_value() + # # LSTM 单变量模型 # ex_Lstm(df,input_seq_len=input_size,output_seq_len=horizon,is_debug=is_debug,dataset=dataset) @@ -380,12 +382,12 @@ def predict_main(): if __name__ == '__main__': # global end_time # 遍历2024-11-25 到 2024-12-3 之间的工作日日期 - # for i_time in pd.date_range('2022-1-1', '2025-3-26', freq='M'): - # try: - # global_config['end_time'] = i_time.strftime('%Y-%m-%d') - # predict_main() - # except Exception as e: - # logger.info(f'预测失败:{e}') - # continue + for i_time in pd.date_range('2025-2-1', '2025-3-18', freq='M'): + try: + global_config['end_time'] = i_time.strftime('%Y-%m-%d') + predict_main() + except Exception as e: + logger.info(f'预测失败:{e}') + continue - predict_main() + # predict_main() diff --git a/main_juxiting_yuedu.py b/main_juxiting_yuedu.py index 91b98c5..cd7ff96 100644 --- a/main_juxiting_yuedu.py +++ b/main_juxiting_yuedu.py @@ -346,7 +346,7 @@ def predict_main(): # # 模型报告 logger.info('制作报告ing') title = f'{settings}--{end_time}-预测报告' # 报告标题 - reportname = f'Brent原油大模型月度预测--{end_time}.pdf' # 报告文件名 + reportname = f'聚烯烃PP大模型月度预测--{end_time}.pdf' # 报告文件名 reportname = reportname.replace(':', '-') # 替换冒号 pp_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time, reportname=reportname, sqlitedb=sqlitedb), diff --git a/main_juxiting_zhoudu.py b/main_juxiting_zhoudu.py index 56d6d1b..92844e9 100644 --- a/main_juxiting_zhoudu.py +++ b/main_juxiting_zhoudu.py @@ -346,7 +346,7 @@ def predict_main(): # # 模型报告 logger.info('制作报告ing') title = f'{settings}--{end_time}-预测报告' # 报告标题 - reportname = f'Brent原油大模型周度预测--{end_time}.pdf' # 报告文件名 + reportname = f'聚烯烃PP大模型周度预测--{end_time}.pdf' # 报告文件名 reportname = reportname.replace(':', '-') # 替换冒号 pp_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time, reportname=reportname, sqlitedb=sqlitedb), diff --git a/main_yuanyou.py b/main_yuanyou.py index e2b2e31..e158092 100644 --- a/main_yuanyou.py +++ b/main_yuanyou.py @@ -80,60 +80,6 @@ global_config.update({ }) -def push_market_value(): - logger.info('发送预测结果到市场信息平台') - # 读取预测数据和模型评估数据 - predict_file_path = os.path.join(config.dataset, 'predict.csv') - model_eval_file_path = os.path.join(config.dataset, 'model_evaluation.csv') - try: - predictdata_df = pd.read_csv(predict_file_path) - top_models_df = pd.read_csv(model_eval_file_path) - except FileNotFoundError as e: - logger.error(f"文件未找到: {e}") - return - - predictdata = predictdata_df.copy() - - # 取模型前十 - top_models = top_models_df['模型(Model)'].head(10).tolist() - - # 计算前十模型的均值 - predictdata_df['top_models_mean'] = predictdata_df[top_models].mean(axis=1) - - # 打印日期和前十模型均值 - print(predictdata_df[['ds', 'top_models_mean']]) - - # 准备要推送的数据 - first_mean = predictdata_df['top_models_mean'].iloc[0] - last_mean = predictdata_df['top_models_mean'].iloc[-1] - # 保留两位小数 - first_mean = round(first_mean, 2) - last_mean = round(last_mean, 2) - - predictdata = [ - { - "dataItemNo": global_config['bdwd_items']['ciri'], - "dataDate": global_config['end_time'].replace('-',''), - "dataStatus": "add", - "dataValue": first_mean - }, - { - "dataItemNo": global_config['bdwd_items']['benzhou'], - "dataDate": global_config['end_time'].replace('-',''), - "dataStatus": "add", - "dataValue": last_mean - } - ] - - print(predictdata) - - # 推送数据到市场信息平台 - try: - push_market_data(predictdata) - except Exception as e: - logger.error(f"推送数据失败: {e}") - - def predict_main(): """ 主预测函数,用于从 ETA 获取数据、处理数据、训练模型并进行预测。 diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index 3ccbda0..bce724c 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -455,10 +455,10 @@ def ex_Model_Juxiting(df, horizon, input_size, train_steps, val_check_steps, ear df_predict.to_csv(os.path.join(config.dataset, "predict.csv"), index=False) # 将预测结果保存到数据库 - save_to_database(sqlitedb, df_predict, 'predict', end_time) + save_to_database(config.sqlitedb, df_predict, 'predict', end_time) # 把预测值上传到eta - if is_update_eta: + if config.is_update_eta: df_predict['ds'] = pd.to_datetime(df_predict['ds']) dates = df_predict['ds'].dt.strftime('%Y-%m-%d')