图片报告样式调优

This commit is contained in:
workpc 2025-08-13 11:54:39 +08:00
parent af31fa2587
commit ee29518edf
7 changed files with 82 additions and 36 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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