图片报告样式调优
This commit is contained in:
parent
af31fa2587
commit
ee29518edf
@ -142,7 +142,7 @@ data = {
|
|||||||
ClassifyId = 1161
|
ClassifyId = 1161
|
||||||
|
|
||||||
|
|
||||||
# # 变量定义--线上环境
|
# 变量定义--线上环境
|
||||||
# server_host = '10.200.32.39'
|
# server_host = '10.200.32.39'
|
||||||
# login_pushreport_url = "http://10.200.32.39/jingbo-api/api/server/login"
|
# 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"
|
# upload_url = "http://10.200.32.39/jingbo-api/api/analysis/reportInfo/researchUploadReportSave"
|
||||||
|
@ -225,6 +225,7 @@ ClassifyId = 1161
|
|||||||
# query_data_list_item_nos_url = f"http://{server_host}/jingbo-api/api/warehouse/dwDataItem/queryDataListItemNos"
|
# 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_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 = {
|
# login_data = {
|
||||||
# "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 = {
|
# bdwd_items = {
|
||||||
# 'ciri': '原油大数据预测|FORECAST|PRICE|T',
|
# 'ciri': '原油大数据预测|FORECAST|PRICE|T',
|
||||||
@ -422,6 +438,7 @@ push_png_report_data = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 八大维度数据项编码
|
# 八大维度数据项编码
|
||||||
bdwd_items = {
|
bdwd_items = {
|
||||||
'ciri': 'jxtppbdwdcr',
|
'ciri': 'jxtppbdwdcr',
|
||||||
|
@ -2520,6 +2520,8 @@ def push_market_data(data):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
|
# from lib.tools import NumpyEncoder
|
||||||
|
|
||||||
# 获取token
|
# 获取token
|
||||||
token = get_head_auth_report()
|
token = get_head_auth_report()
|
||||||
# 定义请求参数
|
# 定义请求参数
|
||||||
@ -2527,6 +2529,9 @@ def push_market_data(data):
|
|||||||
# 发送请求
|
# 发送请求
|
||||||
headers = {"Authorization": token}
|
headers = {"Authorization": token}
|
||||||
config.logger.info('上传数据中...')
|
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,
|
items_res = requests.post(url=config.push_data_value_list_url, headers=headers,
|
||||||
json=config.push_data_value_list_data, timeout=(3, 35))
|
json=config.push_data_value_list_data, timeout=(3, 35))
|
||||||
json_data = json.loads(items_res.text)
|
json_data = json.loads(items_res.text)
|
||||||
|
25
lib/tools.py
25
lib/tools.py
@ -36,6 +36,8 @@ import numpy as np
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from lib.pydantic_models import PredictionResult, PpPredictionResult
|
from lib.pydantic_models import PredictionResult, PpPredictionResult
|
||||||
@ -93,6 +95,22 @@ class BinanceAPI:
|
|||||||
# return self.signature
|
# 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:
|
class Graphs:
|
||||||
'''
|
'''
|
||||||
pdf生成类
|
pdf生成类
|
||||||
@ -828,6 +846,8 @@ def convert_df_to_pydantic_pp(df_predict, model_id_name_dict, global_config):
|
|||||||
results = []
|
results = []
|
||||||
data = global_config['DEFAULT_CONFIG'].copy()
|
data = global_config['DEFAULT_CONFIG'].copy()
|
||||||
data['data_date'] = df_predict['created_dt'].values[0]
|
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):
|
if isinstance(data['data_date'], np.datetime64):
|
||||||
data['data_date'] = pd.Timestamp(
|
data['data_date'] = pd.Timestamp(
|
||||||
data['data_date']).to_pydatetime()
|
data['data_date']).to_pydatetime()
|
||||||
@ -1130,6 +1150,11 @@ def plot_pp_predict_result(y_hat, global_config,wd='yuedu'):
|
|||||||
|
|
||||||
# 绘制 y 的折线图,颜色为蓝色
|
# 绘制 y 的折线图,颜色为蓝色
|
||||||
sns.lineplot(x=y['ds'], y=y['y'], color='blue', label='真实值', ax=ax)
|
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')
|
# 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)
|
ax.set_title(f'{datetime.datetime.now().strftime("%Y-%m-%d")} PP期货十一大维度 预测价格走势', fontsize=24)
|
||||||
|
@ -128,28 +128,28 @@ def push_market_value():
|
|||||||
"dataItemNo": global_config['bdwd_items']['ciri'],
|
"dataItemNo": global_config['bdwd_items']['ciri'],
|
||||||
"dataDate": global_config['end_time'].replace('-', ''),
|
"dataDate": global_config['end_time'].replace('-', ''),
|
||||||
"dataStatus": "add",
|
"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'],
|
"dataItemNo": global_config['bdwd_items']['cierri'],
|
||||||
"dataDate": global_config['end_time'].replace('-', ''),
|
"dataDate": global_config['end_time'].replace('-', ''),
|
||||||
"dataStatus": "add",
|
"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'],
|
"dataItemNo": global_config['bdwd_items']['cisanri'],
|
||||||
"dataDate": global_config['end_time'].replace('-', ''),
|
"dataDate": global_config['end_time'].replace('-', ''),
|
||||||
"dataStatus": "add",
|
"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'],
|
"dataItemNo": global_config['bdwd_items']['cisiri'],
|
||||||
"dataDate": global_config['end_time'].replace('-', ''),
|
"dataDate": global_config['end_time'].replace('-', ''),
|
||||||
"dataStatus": "add",
|
"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'],
|
"dataItemNo": global_config['bdwd_items']['benzhou'],
|
||||||
"dataDate": global_config['end_time'].replace('-', ''),
|
"dataDate": global_config['end_time'].replace('-', ''),
|
||||||
"dataStatus": "add",
|
"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__':
|
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-8-1', '2025-8-11', freq='B'):
|
# for i_time in pd.date_range('2025-8-1', '2025-8-11', freq='B'):
|
||||||
try:
|
# try:
|
||||||
global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
# global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
||||||
global_config['db_mysql'].connect()
|
# 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()
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.info(f'预测失败:{e}')
|
||||||
|
# continue
|
||||||
|
# global_config['end_time'] = '2025-08-05'
|
||||||
|
predict_main()
|
||||||
|
|
||||||
# global_config['end_time'] = '2025-08-01'
|
# global_config['end_time'] = '2025-08-12'
|
||||||
# push_market_value()
|
# push_market_value()
|
||||||
# sql_inset_predict(global_config)
|
# sql_inset_predict(global_config)
|
||||||
|
@ -113,13 +113,14 @@ def push_market_value():
|
|||||||
|
|
||||||
# 准备要推送的数据
|
# 准备要推送的数据
|
||||||
ciyue_mean = four_month_predict_price[best_bdwd_price['next_month_price']
|
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']
|
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']
|
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']
|
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)
|
ciyue_mean = round(ciyue_mean, 2)
|
||||||
cieryue_mean = round(cieryue_mean, 2)
|
cieryue_mean = round(cieryue_mean, 2)
|
||||||
@ -551,13 +552,13 @@ if __name__ == '__main__':
|
|||||||
# logger.info(f'预测失败:{e}')
|
# logger.info(f'预测失败:{e}')
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
# global_config['end_time'] = '2025-07-25'
|
# global_config['end_time'] = '2025-08-13'
|
||||||
# predict_main()
|
# predict_main()
|
||||||
# push_market_value()
|
# push_market_value()
|
||||||
# sql_inset_predict(global_config)
|
# sql_inset_predict(global_config)
|
||||||
|
|
||||||
# 图片报告
|
# 图片报告
|
||||||
global_config['end_time'] = '2025-08-12'
|
# global_config['end_time'] = '2025-08-12'
|
||||||
logger.info('图片报告ing')
|
logger.info('图片报告ing')
|
||||||
pp_bdwd_png(global_config=global_config)
|
pp_bdwd_png(global_config=global_config)
|
||||||
logger.info('图片报告end')
|
logger.info('图片报告end')
|
||||||
|
@ -122,8 +122,8 @@ def push_market_value():
|
|||||||
first_mean = weeks_predict_price[best_bdwd_price['second_week_price']['model_name']].iloc[0]
|
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]
|
last_mean = weeks_predict_price[best_bdwd_price['next_week_price']['model_name']].iloc[-1]
|
||||||
# 保留两位小数
|
# 保留两位小数
|
||||||
first_mean = round(first_mean, 2)
|
first_mean = float(round(first_mean, 2))
|
||||||
last_mean = round(last_mean, 2)
|
last_mean = float(round(last_mean, 2))
|
||||||
|
|
||||||
predictdata = [
|
predictdata = [
|
||||||
{
|
{
|
||||||
@ -140,8 +140,6 @@ def push_market_value():
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
print(predictdata)
|
|
||||||
|
|
||||||
# 推送数据到市场信息平台
|
# 推送数据到市场信息平台
|
||||||
try:
|
try:
|
||||||
push_market_data(predictdata)
|
push_market_data(predictdata)
|
||||||
@ -512,18 +510,18 @@ 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-7-24', '2025-8-12', freq='B'):
|
# for i_time in pd.date_range('2025-3-3', '2025-5-30', freq='B'):
|
||||||
try:
|
# try:
|
||||||
global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
# global_config['end_time'] = i_time.strftime('%Y-%m-%d')
|
||||||
global_config['db_mysql'].connect()
|
# 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()
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.info(f'预测失败:{e}')
|
||||||
|
# continue
|
||||||
|
|
||||||
|
|
||||||
|
# global_config['end_time'] = '2025-08-12'
|
||||||
|
predict_main()
|
||||||
|
|
||||||
|
|
||||||
# push_market_value()
|
# push_market_value()
|
||||||
|
Loading…
Reference in New Issue
Block a user