聚烯烃配置八大维度

This commit is contained in:
jingboyitiji 2025-03-28 10:55:59 +08:00
parent a2347ed1c3
commit 14e1484751
7 changed files with 84 additions and 70 deletions

View File

@ -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个模型

View File

@ -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}")

View File

@ -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()

View File

@ -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),

View File

@ -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),

View File

@ -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 获取数据处理数据训练模型并进行预测

View File

@ -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')