原油日度预测上传市场信息平台数据
This commit is contained in:
parent
2fbd6c04f9
commit
046e6dcc7b
@ -2276,60 +2276,6 @@ def get_baichuan_data(baichuanidnamedict):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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}")
|
|
||||||
|
|
||||||
|
|
||||||
def get_bdwd_predict_data():
|
def get_bdwd_predict_data():
|
||||||
# 获取认证头部信息
|
# 获取认证头部信息
|
||||||
token = get_head_auth_report()
|
token = get_head_auth_report()
|
||||||
|
@ -80,6 +80,63 @@ global_config.update({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def predict_main():
|
def predict_main():
|
||||||
"""
|
"""
|
||||||
主预测函数,用于从 ETA 获取数据、处理数据、训练模型并进行预测。
|
主预测函数,用于从 ETA 获取数据、处理数据、训练模型并进行预测。
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from lib.dataread import *
|
from lib.dataread import *
|
||||||
from config_jingbo_yuedu import *
|
from config_jingbo_yuedu import *
|
||||||
from lib.tools import SendMail, exception_logger
|
from lib.tools import SendMail, exception_logger
|
||||||
from models.nerulforcastmodels import ex_Model, model_losss
|
from models.nerulforcastmodels import ex_Model, model_losss,brent_export_pdf
|
||||||
import datetime
|
import datetime
|
||||||
import torch
|
import torch
|
||||||
torch.set_float32_matmul_precision("high")
|
torch.set_float32_matmul_precision("high")
|
||||||
@ -417,18 +417,18 @@ def predict_main():
|
|||||||
model_results3 = model_losss(sqlitedb, end_time=end_time)
|
model_results3 = model_losss(sqlitedb, end_time=end_time)
|
||||||
logger.info('训练数据绘图end')
|
logger.info('训练数据绘图end')
|
||||||
|
|
||||||
# # 模型报告
|
# 模型报告
|
||||||
# logger.info('制作报告ing')
|
logger.info('制作报告ing')
|
||||||
# title = f'{settings}--{end_time}-预测报告' # 报告标题
|
title = f'{settings}--{end_time}-预测报告' # 报告标题
|
||||||
# reportname = f'Brent原油大模型月度预测--{end_time}.pdf' # 报告文件名
|
reportname = f'Brent原油大模型月度预测--{end_time}.pdf' # 报告文件名
|
||||||
# reportname = reportname.replace(':', '-') # 替换冒号
|
reportname = reportname.replace(':', '-') # 替换冒号
|
||||||
# brent_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time,
|
brent_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time,
|
||||||
# reportname=reportname, sqlitedb=sqlitedb),
|
reportname=reportname, sqlitedb=sqlitedb),
|
||||||
|
|
||||||
# logger.info('制作报告end')
|
logger.info('制作报告end')
|
||||||
# logger.info('模型训练完成')
|
logger.info('模型训练完成')
|
||||||
|
|
||||||
# push_market_value()
|
push_market_value()
|
||||||
|
|
||||||
# # LSTM 单变量模型
|
# # LSTM 单变量模型
|
||||||
# ex_Lstm(df,input_seq_len=input_size,output_seq_len=horizon,is_debug=is_debug,dataset=dataset)
|
# ex_Lstm(df,input_seq_len=input_size,output_seq_len=horizon,is_debug=is_debug,dataset=dataset)
|
||||||
@ -455,13 +455,13 @@ def predict_main():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# global end_time
|
# global end_time
|
||||||
# 遍历2024-11-25 到 2024-12-3 之间的工作日日期
|
# 遍历2024-11-25 到 2024-12-3 之间的工作日日期
|
||||||
for i_time in pd.date_range('2025-1-1', '2025-3-26', freq='B'):
|
# for i_time in pd.date_range('2025-1-1', '2025-3-26', freq='B'):
|
||||||
# try:
|
# # try:
|
||||||
global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
# global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
||||||
predict_main()
|
# predict_main()
|
||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# logger.info(f'预测失败:{e}')
|
# logger.info(f'预测失败:{e}')
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
# predict_main()
|
predict_main()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user