From 0abd38307d0864675a0c141caef9ba54d1478602 Mon Sep 17 00:00:00 2001 From: jingboyitiji Date: Tue, 25 Mar 2025 15:46:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=B3=E6=B2=B9=E7=84=A6=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_shiyoujiao_lvyong.py | 36 +++++++++++++++++++++++------------- lib/dataread.py | 8 ++++++-- main_shiyoujiao_lvyong.py | 10 +++++----- models/nerulforcastmodels.py | 4 ++++ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/config_shiyoujiao_lvyong.py b/config_shiyoujiao_lvyong.py index e83ea57..20dfdad 100644 --- a/config_shiyoujiao_lvyong.py +++ b/config_shiyoujiao_lvyong.py @@ -144,12 +144,12 @@ modelsindex = { # 百川数据指标编码 baichuanidnamedict = { - '1588348470396480000': '石油焦滨州-友泰', - '1588348470396480000.00': '石油焦东营-海科瑞林', - '1588348470396480000.00': '石油焦东营-华联2', - '1588348470396480000.00': '石油焦东营-华联3', - '1588348470396480000.00': '石油焦东营-联合', - '1588348470396480000.00': '石油焦东营-联合3', + '1588348470396480901': '石油焦滨州-友泰', + '1588348470396480903': '石油焦东营-海科瑞林', + '1588348470396480902': '石油焦东营-华联2', + '1588348470396481080': '石油焦东营-华联3', + '1588348470396480905': '石油焦东营-联合', + '1588348470396481081': '石油焦东营-联合3', '1588348470396480915': '石油焦淄博-汇丰', '1588348470396480888': '石油焦沧州-鑫海', '1588348470396480917': '石油焦东营-万通', @@ -157,6 +157,7 @@ baichuanidnamedict = { '1588348470396481084': '石油焦东营-尚能4', '1588348470396480930': '石油焦潍坊-寿光鲁清', '1588348470396480929': '石油焦滨州-鑫岳', + '1588348470396480888': '江苏鑫海' } @@ -285,16 +286,25 @@ bdwd_items = { } # 北京环境数据库 -host = '192.168.101.27' +# host = '192.168.101.27' +# port = 3306 +# dbusername = 'root' +# password = '123456' +# dbname = 'jingbo_test' + +# 京博测试环境 +host = 'rm-2zehj3r1n60ttz9x5ko.mysql.rds.aliyuncs.com' port = 3306 -dbusername = 'root' -password = '123456' -dbname = 'jingbo_test' +dbusername ='jingbo' +password = 'shihua@123' +dbname = 'jingbo-test' + + table_name = 'v_tbl_crude_oil_warning' baichuan_table_name = 'V_TBL_BAICHUAN_YINGFU_VALUE' # select BAICHUAN_ID, DATA_DATE, DATA_VALUE from V_TBL_BAICHUAN_YINGFU_VALUE where BAICHUAN_ID in ('1588348470396475286', '1666') # 开关 -is_train = True # 是否训练 +is_train = False # 是否训练 is_debug = False # 是否调试 is_eta = True # 是否使用eta接口 is_market = False # 是否通过市场信息平台获取特征 ,在is_eta 为true 的情况下生效 @@ -361,11 +371,11 @@ db_name = os.path.join(dataset, 'jbsh_shiyoujiao_lvyong.db') sqlitedb = SQLiteHandler(db_name) sqlitedb.connect() -settings = f'{input_size}-{horizon}-{train_steps}--{k}-{data_set}-{y}' +settings = f'{input_size}-{horizon}-{train_steps}--{k}-{data_set}' # 获取日期时间 # now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') # 获取当前日期时间 now = datetime.datetime.now().strftime('%Y-%m-%d') # 获取当前日期时间 -reportname = f'石油焦铝用大模型预测报告--{end_time}.pdf' # 报告文件名 +reportname = f'石油焦铝用大模型日度预测报告--{end_time}.pdf' # 报告文件名 reportname = reportname.replace(':', '-') # 替换冒号 if end_time == '': end_time = now diff --git a/lib/dataread.py b/lib/dataread.py index 6d75a58..432fb2a 100644 --- a/lib/dataread.py +++ b/lib/dataread.py @@ -2222,7 +2222,7 @@ def addtimecharacteristics(df, dataset): # 从数据库获取百川数据,接收一个百川id列表,返回df格式的数据 def get_baichuan_data(baichuanidnamedict): - baichuanidlist = list(baichuanidnamedict.keys()) + baichuanidlist = [str(k) for k in baichuanidnamedict.keys()] # 连接数据库 db = config.db_mysql db.connect() @@ -2231,12 +2231,16 @@ def get_baichuan_data(baichuanidnamedict): # 获取查询结果 results = db.execute_query(sql) - df = pd.DataFrame(results, columns=[ + formatted_results = [tuple(item) for item in results] + df = pd.DataFrame(formatted_results, columns=[ 'BAICHUAN_ID', 'DATA_DATE', 'DATA_VALUE']) + df['BAICHUAN_ID'] = df['BAICHUAN_ID'].astype('string') + df.to_csv('百川数据test.csv', index=False) # 按BAICHUAN_ID 进行分组,然后按DATA_DATE合并 df1 = pd.DataFrame(columns=['DATA_DATE']) for baichuan_id, group in df.groupby('BAICHUAN_ID'): + print(f"当前分组ID类型: {type(baichuan_id)},值: {baichuan_id}") # 调试用 # group 删除BAICHUAN_ID列 group.drop(columns=['BAICHUAN_ID'], inplace=True) # group DATA_value 转换为float类型,保留两位小数 diff --git a/main_shiyoujiao_lvyong.py b/main_shiyoujiao_lvyong.py index 896c28d..a6cee8b 100644 --- a/main_shiyoujiao_lvyong.py +++ b/main_shiyoujiao_lvyong.py @@ -3,7 +3,7 @@ from lib.dataread import * from config_shiyoujiao_lvyong import * from lib.tools import SendMail, exception_logger -from models.nerulforcastmodels import ex_Model, model_losss, model_losss_juxiting, brent_export_pdf, tansuanli_export_pdf, pp_export_pdf, model_losss_juxiting +from models.nerulforcastmodels import ex_Model, model_losss,shiyoujiao_lvyong_export_pdf import datetime import torch torch.set_float32_matmul_precision("high") @@ -219,7 +219,7 @@ def predict_main(): # 指标列表添加百川数据 df_baichuanliebiao = pd.DataFrame( global_config['baichuanidnamedict'].items(), columns=['指标id', '指标名称']) - df_baichuanliebiao['指标分类'] = '百川' + df_baichuanliebiao['指标分类'] = '石油焦对标炼厂价格' df_baichuanliebiao['频度'] = '其他' df_zhibiaoliebiao = pd.concat( [df_zhibiaoliebiao, df_baichuanliebiao], axis=0) @@ -421,15 +421,15 @@ def predict_main(): # 模型报告 logger.info('制作报告ing') title = f'{settings}--{end_time}-预测报告' # 报告标题 - reportname = f'Brent原油大模型日度预测--{end_time}.pdf' # 报告文件名 + reportname = f'石油焦铝用大模型日度预测--{end_time}.pdf' # 报告文件名 reportname = reportname.replace(':', '-') # 替换冒号 - brent_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time, + shiyoujiao_lvyong_export_pdf(dataset=dataset, num_models=5 if is_fivemodels else 22, time=end_time, reportname=reportname, sqlitedb=sqlitedb), logger.info('制作报告end') logger.info('模型训练完成') - push_market_value() + # push_market_value() # # LSTM 单变量模型 # ex_Lstm(df,input_seq_len=input_size,output_seq_len=horizon,is_debug=is_debug,dataset=dataset) diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index 8f68abf..a5df9f1 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -2199,6 +2199,8 @@ def brent_export_pdf(num_indicators=475, num_models=21, num_dayindicator=202, in col = col.replace('*', '-') col = col.replace(':', '-') col = col.replace(r'/', '-') + col = col.replace(r'>', '-') + col = col.replace(r'<', '-') plt.savefig(os.path.join(config.dataset, f'{col}与价格散点图.png')) content.append(Graphs.draw_img( os.path.join(config.dataset, f'{col}与价格散点图.png'))) @@ -2517,6 +2519,8 @@ def shiyoujiao_lvyong_export_pdf(num_indicators=475, num_models=21, num_dayindic col = col.replace('*', '-') col = col.replace(':', '-') col = col.replace(r'/', '-') + col = col.replace(r'>', '-') + col = col.replace(r'<', '-') plt.savefig(os.path.join(config.dataset, f'{col}与价格散点图.png')) content.append(Graphs.draw_img( os.path.join(config.dataset, f'{col}与价格散点图.png')))