From 3a1d85f275c89712e07b4c99c147c101e67ee4a1 Mon Sep 17 00:00:00 2001 From: workpc Date: Fri, 28 Mar 2025 16:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E6=B2=B9=E6=9C=88=E5=BA=A6=E9=A2=84?= =?UTF-8?q?=E6=B5=8B=E6=8A=A5=E5=91=8A=E6=B7=BB=E5=8A=A0=E5=85=AB=E5=A4=A7?= =?UTF-8?q?=E7=BB=B4=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_jingbo_yuedu.py | 1 + lib/dataread.py | 86 +++++++++++++++++++++++++++++++++++- main_yuanyou_yuedu.py | 2 + models/nerulforcastmodels.py | 13 ++++-- 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/config_jingbo_yuedu.py b/config_jingbo_yuedu.py index 7b482bc..e5e90ca 100644 --- a/config_jingbo_yuedu.py +++ b/config_jingbo_yuedu.py @@ -304,3 +304,4 @@ logger.addHandler(file_handler) logger.addHandler(console_handler) # logger.info('当前配置:'+settings) + diff --git a/lib/dataread.py b/lib/dataread.py index 9a5ca08..7d134d6 100644 --- a/lib/dataread.py +++ b/lib/dataread.py @@ -1186,6 +1186,10 @@ class Config: def push_data_value_list_data( self): return global_config['push_data_value_list_data'] + @property + def bdwd_items(self): return global_config['bdwd_items'] + + # 字段映射 @property def offsite_col(self): return global_config['offsite_col'] @@ -2325,4 +2329,84 @@ def push_market_value(): def get_bdwd_predict_data(): - pass \ No newline at end of file + # 获取认证头部信息 + token = get_head_auth_report() + + # 设置请求头部 + headers = {"Authorization": token} + + # 打印日志,显示正在上传预警数据 + config.logger.info("获取八大维度数据...") + + # 打印日志,显示上传的URL + config.logger.info(f"query_data_list_item_nos_url:{config.query_data_list_item_nos_url}") + + # 打印日志,显示认证头部信息 + config.logger.info(f"token:{token}") + + + + # 打印日志,显示要查询的数据项 + config.logger.info(f"query_data_list_item_nos_data:{query_data_list_item_nos_data}") + + # 发送POST请求,上传预警数据 + respose = requests.post( + url=config.upload_warning_url, headers=headers, json=query_data_list_item_nos_data, timeout=(3, 15)) + + + # 如果上传成功,返回响应对象 + if respose: + # 处理返回结果为df + df = pd.DataFrame(respose.json()['data']) + + return df + # 如果上传失败,打印日志并返回None + else: + config.logger.info("预警上传失败") + return None + pass + + +def get_bdwd_predict_data(): + """ + 获取市场数据,拼接到df中 + """ + # 获取token + token = get_head_auth_report() + # 定义请求参数 + query_data_list_item_nos_data = config.query_data_list_item_nos_data.copy() + query_data_list_item_nos_data['data']['dateStart'] = config.end_time.replace( + '-', '') + query_data_list_item_nos_data['data']['dateEnd'] = config.end_time.replace( + '-', '') + query_data_list_item_nos_data['data']['dataItemNoList'] = list( + config.bdwd_items.values()) + # 发送请求 + headers = {"Authorization": token} + config.logger.info('获取数据中...') + items_res = requests.post(url=config.query_data_list_item_nos_url, headers=headers, + json=query_data_list_item_nos_data, timeout=(3, 35)) + json_data = json.loads(items_res.text) + config.logger.info(f"获取到的数据:{json_data}") + df3 = pd.DataFrame(json_data['data']) + # 按照dataItemNo 分组 得到多个dataframe ,最后根据dataDate merge 成一个dataframe + df2 = pd.DataFrame() + for i in df3['dataItemNo'].unique(): + df1 = df3[df3['dataItemNo'] == i] + df1 = df1[['dataDate', 'dataValue']] + df1 = df1.rename(columns={'dataValue': i}) + if len(df2) == 0: + df2 = df1 + continue + df2 = pd.merge(df2, df1, how='left') + df2 = df2.rename(columns={'dataDate': 'date'}) + # 20240101 转换为 2024-01-01 + df2['date'] = pd.to_datetime(df2['date'], format='%Y%m%d') + df2['date'] = df2['date'].dt.strftime('%Y-%m-%d') + # df = pd.merge(df, df2, how='left', on='date') + # 更改列名: + df2.rename(columns={'yyycbdwdbz':'本周','yyycbdwdcey':'次二月','yyycbdwdcr':'次日','yyycbdwdcsiy':'次四月','yyycbdwdcsy':'次三月','yyycbdwdcy':'次月','yyycbdwdcz':'次周','yyycbdwdgz':'隔周',}, inplace=True) + # 更改显示顺序 + df2 = df2[['date','次日','本周','次周','隔周','次月','次二月','次三月','次四月']] + print(df2) + return df2 diff --git a/main_yuanyou_yuedu.py b/main_yuanyou_yuedu.py index 9b57366..d4b8e7f 100644 --- a/main_yuanyou_yuedu.py +++ b/main_yuanyou_yuedu.py @@ -76,6 +76,7 @@ global_config.update({ # 数据库配置 'sqlitedb': sqlitedb, + 'is_bdwd': is_bdwd, }) @@ -463,3 +464,4 @@ if __name__ == '__main__': # continue predict_main() + diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index 8a1a325..414a89c 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -2289,9 +2289,16 @@ def brent_export_pdf(num_indicators=475, num_models=21, num_dayindicator=202, in if config.is_bdwd: # 添加八大维度数据 content.append(Graphs.draw_text('八大维度预测:')) - bdwd_df = pd.read_csv(os.path.join( - config.dataset, '八大维度数据.csv'), encoding='utf-8') - # + df_bdwd = get_bdwd_predict_data() + # df转置 + df_bdwd = df_bdwd.T + df_bdwd = df_bdwd.T + # df重置索引 + df_bdwd = df_bdwd.reset_index() + # 添加预测值表格 + data = df_bdwd.values.tolist() + col_width = 500/len(df.columns) + content.append(Graphs.draw_table(col_width, *data)) pass content.append(Graphs.draw_little_title('二、上一预测周期偏差率分析:')) df = pd.read_csv(os.path.join(