From 8d51e933dcb3c93b84752a27ed8661c8330bb704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Mattheliu=E2=80=99?= <‘leonliuzx@outlook.com’> Date: Tue, 23 Jan 2024 19:46:55 +0800 Subject: [PATCH] fix dashboard and autopilot --- ai/backend/aidb/autopilot/autopilot.py | 5 +++-- ai/backend/aidb/dashboard/prettify_dashboard.py | 5 +++-- ai/backend/util/base_util.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ai/backend/aidb/autopilot/autopilot.py b/ai/backend/aidb/autopilot/autopilot.py index 20440f63..3216b2f2 100644 --- a/ai/backend/aidb/autopilot/autopilot.py +++ b/ai/backend/aidb/autopilot/autopilot.py @@ -157,8 +157,9 @@ def generate_report_template(self, data): current_directory = CONFIG.up_file_path # 构建路径时使用 os.path.join,并使用 os.path.normpath 进行规范化 - html_template_path = os.path.join(os.path.normpath(current_directory.replace(r'\user_upload_files', '')), 'ai', 'backend', 'aidb', 'autopilot') + html_template_path = os.path.join(os.path.normpath(current_directory.replace('user_upload_files', '')), 'ai', 'backend', 'aidb', 'autopilot') html_template_path = html_template_path.replace('\\', '/') + html_file_path = os.path.normpath(html_file_path) if CONFIG.web_language == 'CN': html_template_path = os.path.join(html_template_path, 'html_template') @@ -182,7 +183,7 @@ def generate_report_template(self, data): # print('rendered_html : ', rendered_html) # 将渲染后的HTML写入文件 - with open(CONFIG.up_file_path + 'output_' + str(timestamp) + '.html', 'w') as output_file: + with open(CONFIG.up_file_path + 'output_' + str(timestamp) + '.html', 'w',encoding='utf-8') as output_file: output_file.write(rendered_html) print("HTML文件已生成:output.html") diff --git a/ai/backend/aidb/dashboard/prettify_dashboard.py b/ai/backend/aidb/dashboard/prettify_dashboard.py index 9c98a154..f79daa20 100644 --- a/ai/backend/aidb/dashboard/prettify_dashboard.py +++ b/ai/backend/aidb/dashboard/prettify_dashboard.py @@ -96,7 +96,8 @@ async def generate_echart_code(self, echart_json, task_file_name, task_id, html_ current_directory = CONFIG.up_file_path # 构建路径时使用 os.path.join - html_file_path = os.path.join(current_directory.replace(r'\user_upload_files', ''), 'bi', 'templates') + html_file_path = os.path.join(current_directory.replace('user_upload_files', ''), 'bi', 'templates') + html_file_path = os.path.normpath(html_file_path) self.generate_html(echart_json, os.path.join(html_file_path, html_file_name)) @@ -133,7 +134,7 @@ def generate_html(self, data, html_file_name): rendered_html = template.render(data) # 将渲染后的HTML写入文件 - with open(html_file_name, 'w') as output_file: + with open(html_file_name, 'w',encoding='utf-8') as output_file: output_file.write(rendered_html) print("HTML文件已生成:", html_file_name) diff --git a/ai/backend/util/base_util.py b/ai/backend/util/base_util.py index d9318764..76567358 100644 --- a/ai/backend/util/base_util.py +++ b/ai/backend/util/base_util.py @@ -2,6 +2,7 @@ import os from dotenv import load_dotenv from pathlib import Path +from bi.settings import DATA_SOURCE_FILE_DIR as docker_data_source_file_dir host_secret = 'tNGoVq0KpQ4LKr5WMIZM' @@ -20,7 +21,7 @@ def is_json(myjson): def get_upload_path(): # 加载 .env 文件中的环境变量 - data_source_file_dir = os.environ.get("DATA_SOURCE_FILE_DIR", None) + data_source_file_dir = os.environ.get("DATA_SOURCE_FILE_DIR",docker_data_source_file_dir) if data_source_file_dir and len(str(data_source_file_dir)) > 0: return str(data_source_file_dir) + '/' else: