From ee29518edfec4a9a69d366e5d1f103f4ad60d14d Mon Sep 17 00:00:00 2001 From: workpc Date: Wed, 13 Aug 2025 11:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=8A=A5=E5=91=8A=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E4=BC=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_juxiting.py | 2 +- config_juxiting_yuedu.py | 17 +++++++++++++++++ lib/dataread.py | 5 +++++ lib/tools.py | 25 +++++++++++++++++++++++++ main_juxiting.py | 30 +++++++++++++++--------------- main_juxiting_yuedu.py | 13 +++++++------ main_juxiting_zhoudu.py | 26 ++++++++++++-------------- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/config_juxiting.py b/config_juxiting.py index 2f4b972..439a9f8 100644 --- a/config_juxiting.py +++ b/config_juxiting.py @@ -142,7 +142,7 @@ data = { ClassifyId = 1161 -# # 变量定义--线上环境 +# 变量定义--线上环境 # server_host = '10.200.32.39' # login_pushreport_url = "http://10.200.32.39/jingbo-api/api/server/login" # upload_url = "http://10.200.32.39/jingbo-api/api/analysis/reportInfo/researchUploadReportSave" diff --git a/config_juxiting_yuedu.py b/config_juxiting_yuedu.py index 41112df..43630c1 100644 --- a/config_juxiting_yuedu.py +++ b/config_juxiting_yuedu.py @@ -225,6 +225,7 @@ ClassifyId = 1161 # query_data_list_item_nos_url = f"http://{server_host}/jingbo-api/api/warehouse/dwDataItem/queryDataListItemNos" # # 上传数据项值 # push_data_value_list_url = f"http://{server_host}/jingbo-api/api/dw/dataValue/pushDataValueList" +# push_png_report_url = f"http://{server_host}/jingbo-api/api/analysis/reportInfo/priceForecastImg" # login_data = { # "data": { @@ -298,6 +299,21 @@ ClassifyId = 1161 # } # ] # } + +# push_png_report_data = { +# "funcModule": '聚烯烃图片报告', +# "funcOperation": '上传聚烯烃PP价格预测图片报告', +# "data": { +# "groupNo": "000211", +# "updateTime": "2024-09-06 15:01:29", +# "fileBase64": '', # 文件内容base64 +# "title": '2025年8月5日日度周度预测结果', +# "billNo": '', +# } +# } + + + # # 八大维度数据项编码 # bdwd_items = { # 'ciri': '原油大数据预测|FORECAST|PRICE|T', @@ -422,6 +438,7 @@ push_png_report_data = { } + # 八大维度数据项编码 bdwd_items = { 'ciri': 'jxtppbdwdcr', diff --git a/lib/dataread.py b/lib/dataread.py index 5d568c3..6dc6d56 100644 --- a/lib/dataread.py +++ b/lib/dataread.py @@ -2520,6 +2520,8 @@ def push_market_data(data): } ] ''' + # from lib.tools import NumpyEncoder + # 获取token token = get_head_auth_report() # 定义请求参数 @@ -2527,6 +2529,9 @@ def push_market_data(data): # 发送请求 headers = {"Authorization": token} config.logger.info('上传数据中...') + config.logger.info(f'上传数据URL:{config.push_data_value_list_url}') + config.logger.info(f'上传数据数据:{config.push_data_value_list_data}') + items_res = requests.post(url=config.push_data_value_list_url, headers=headers, json=config.push_data_value_list_data, timeout=(3, 35)) json_data = json.loads(items_res.text) diff --git a/lib/tools.py b/lib/tools.py index a893b1d..1dde014 100644 --- a/lib/tools.py +++ b/lib/tools.py @@ -36,6 +36,8 @@ import numpy as np import os import time import logging +import json + from dotenv import load_dotenv from lib.pydantic_models import PredictionResult, PpPredictionResult @@ -93,6 +95,22 @@ class BinanceAPI: # return self.signature +# 自定义JSON编码器,处理NumPy类型 +class NumpyEncoder(json.JSONEncoder): + def default(self, obj): + # 处理int64类型 + if isinstance(obj, np.integer): + return int(obj) + # 处理float64等其他类型 + elif isinstance(obj, np.floating): + return float(obj) + # 处理ndarray类型 + elif isinstance(obj, np.ndarray): + return obj.tolist() + # 其他类型交给默认编码器处理 + return super(NumpyEncoder, self).default(obj) + + class Graphs: ''' pdf生成类 @@ -828,6 +846,8 @@ def convert_df_to_pydantic_pp(df_predict, model_id_name_dict, global_config): results = [] data = global_config['DEFAULT_CONFIG'].copy() data['data_date'] = df_predict['created_dt'].values[0] + data['update_date'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + if isinstance(data['data_date'], np.datetime64): data['data_date'] = pd.Timestamp( data['data_date']).to_pydatetime() @@ -1130,6 +1150,11 @@ def plot_pp_predict_result(y_hat, global_config,wd='yuedu'): # 绘制 y 的折线图,颜色为蓝色 sns.lineplot(x=y['ds'], y=y['y'], color='blue', label='真实值', ax=ax) + # 月度日期每月显示一个 + import matplotlib.dates as mdates + if wd == 'yuedu': + ax.xaxis.set_major_locator(mdates.MonthLocator()) + ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) # date_str = pd.Timestamp(y_hat["ds"].iloc[0]).strftime('%Y-%m-%d') ax.set_title(f'{datetime.datetime.now().strftime("%Y-%m-%d")} PP期货十一大维度 预测价格走势', fontsize=24) diff --git a/main_juxiting.py b/main_juxiting.py index 0657cf4..0c9669f 100644 --- a/main_juxiting.py +++ b/main_juxiting.py @@ -128,28 +128,28 @@ def push_market_value(): "dataItemNo": global_config['bdwd_items']['ciri'], "dataDate": global_config['end_time'].replace('-', ''), "dataStatus": "add", - "dataValue": five_days_predict_price.loc['次日','predictresult'].round(2) + "dataValue": five_days_predict_price.loc['次日','predictresult'].round(2).item() },{ "dataItemNo": global_config['bdwd_items']['cierri'], "dataDate": global_config['end_time'].replace('-', ''), "dataStatus": "add", - "dataValue": five_days_predict_price.loc['次二日','predictresult'].round(2) + "dataValue": five_days_predict_price.loc['次二日','predictresult'].round(2).item() },{ "dataItemNo": global_config['bdwd_items']['cisanri'], "dataDate": global_config['end_time'].replace('-', ''), "dataStatus": "add", - "dataValue": five_days_predict_price.loc['次三日','predictresult'].round(2) + "dataValue": five_days_predict_price.loc['次三日','predictresult'].round(2).item() },{ "dataItemNo": global_config['bdwd_items']['cisiri'], "dataDate": global_config['end_time'].replace('-', ''), "dataStatus": "add", - "dataValue": five_days_predict_price.loc['次四日','predictresult'].round(2) + "dataValue": five_days_predict_price.loc['次四日','predictresult'].round(2).item() }, { "dataItemNo": global_config['bdwd_items']['benzhou'], "dataDate": global_config['end_time'].replace('-', ''), "dataStatus": "add", - "dataValue": five_days_predict_price.loc['次五日','predictresult'].round(2) + "dataValue": five_days_predict_price.loc['次五日','predictresult'].round(2).item() } ] @@ -558,17 +558,17 @@ def predict_main(): if __name__ == '__main__': # global end_time # 遍历2024-11-25 到 2024-12-3 之间的工作日日期 - for i_time in pd.date_range('2025-8-1', '2025-8-11', freq='B'): - try: - global_config['end_time'] = i_time.strftime('%Y-%m-%d') - global_config['db_mysql'].connect() - predict_main() - except Exception as e: - logger.info(f'预测失败:{e}') - continue + # for i_time in pd.date_range('2025-8-1', '2025-8-11', freq='B'): + # try: + # global_config['end_time'] = i_time.strftime('%Y-%m-%d') + # global_config['db_mysql'].connect() + # predict_main() + # except Exception as e: + # logger.info(f'预测失败:{e}') + # continue # global_config['end_time'] = '2025-08-05' - # predict_main() + predict_main() - # global_config['end_time'] = '2025-08-01' + # global_config['end_time'] = '2025-08-12' # push_market_value() # sql_inset_predict(global_config) diff --git a/main_juxiting_yuedu.py b/main_juxiting_yuedu.py index 9c756a4..6c4be64 100644 --- a/main_juxiting_yuedu.py +++ b/main_juxiting_yuedu.py @@ -113,13 +113,14 @@ def push_market_value(): # 准备要推送的数据 ciyue_mean = four_month_predict_price[best_bdwd_price['next_month_price'] - ['model_name']].iloc[0] + ['model_name']].iloc[0].item() + cieryue_mean = four_month_predict_price[best_bdwd_price['next_february_price'] - ['model_name']].iloc[1] + ['model_name']].iloc[1].item() cisanyue_mean = four_month_predict_price[best_bdwd_price['next_march_price'] - ['model_name']].iloc[2] + ['model_name']].iloc[2].item() cisieryue_mean = four_month_predict_price[best_bdwd_price['next_april_price'] - ['model_name']].iloc[3] + ['model_name']].iloc[3].item() # # 保留两位小数 ciyue_mean = round(ciyue_mean, 2) cieryue_mean = round(cieryue_mean, 2) @@ -551,13 +552,13 @@ if __name__ == '__main__': # logger.info(f'预测失败:{e}') # continue - # global_config['end_time'] = '2025-07-25' + # global_config['end_time'] = '2025-08-13' # predict_main() # push_market_value() # sql_inset_predict(global_config) # 图片报告 - global_config['end_time'] = '2025-08-12' + # global_config['end_time'] = '2025-08-12' logger.info('图片报告ing') pp_bdwd_png(global_config=global_config) logger.info('图片报告end') diff --git a/main_juxiting_zhoudu.py b/main_juxiting_zhoudu.py index cc52296..7895803 100644 --- a/main_juxiting_zhoudu.py +++ b/main_juxiting_zhoudu.py @@ -122,8 +122,8 @@ def push_market_value(): first_mean = weeks_predict_price[best_bdwd_price['second_week_price']['model_name']].iloc[0] last_mean = weeks_predict_price[best_bdwd_price['next_week_price']['model_name']].iloc[-1] # 保留两位小数 - first_mean = round(first_mean, 2) - last_mean = round(last_mean, 2) + first_mean = float(round(first_mean, 2)) + last_mean = float(round(last_mean, 2)) predictdata = [ { @@ -140,8 +140,6 @@ def push_market_value(): } ] - print(predictdata) - # 推送数据到市场信息平台 try: push_market_data(predictdata) @@ -512,18 +510,18 @@ def predict_main(): if __name__ == '__main__': # global end_time # 遍历2024-11-25 到 2024-12-3 之间的工作日日期 - for i_time in pd.date_range('2025-7-24', '2025-8-12', freq='B'): - try: - global_config['end_time'] = i_time.strftime('%Y-%m-%d') - global_config['db_mysql'].connect() - predict_main() - except Exception as e: - logger.info(f'预测失败:{e}') - continue + # for i_time in pd.date_range('2025-3-3', '2025-5-30', freq='B'): + # try: + # global_config['end_time'] = i_time.strftime('%Y-%m-%d') + # global_config['db_mysql'].connect() + # predict_main() + # except Exception as e: + # logger.info(f'预测失败:{e}') + # continue - # global_config['end_time'] = '2025-08-05' - # predict_main() + # global_config['end_time'] = '2025-08-12' + predict_main() # push_market_value()