Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dashboard editor run error #1380

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbgpt/app/openapi/api_v1/editor/api_editor_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from dbgpt.app.scene import ChatFactory
from dbgpt.app.scene.chat_dashboard.data_loader import DashboardDataLoader
from dbgpt.serve.conversation.serve import Serve as ConversationServe
from dbgpt.util.date_utils import convert_datetime_in_row

from ._chat_history.chat_hisotry_factory import ChatHistory

Expand Down Expand Up @@ -173,9 +174,8 @@ async def editor_chart_run(run_param: dict = Body()):
field_names, chart_values = dashboard_data_loader.get_chart_values_by_data(
colunms, sql_result, sql
)

start_time = time.time() * 1000
# 计算执行耗时
sql_result = [convert_datetime_in_row(row) for row in sql_result]
end_time = time.time() * 1000
sql_run_data: SqlRunData = SqlRunData(
result_info="",
Expand Down
20 changes: 10 additions & 10 deletions dbgpt/app/scene/chat_dashboard/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def get_chart_values_by_data(self, field_names, datas, chart_sql: str):
)

for field_name in field_names[1:]:
if not field_map[field_name]:
logger.info("More than 2 non-numeric column:" + field_name)
else:
for data in datas:
value_item = ValueItem(
name=data[0],
type=field_name,
value=data[field_names.index(field_name)],
)
values.append(value_item)
# if not field_map[field_name]:
# logger.info("More than 2 non-numeric column:" + field_name)
# else:
for data in datas:
value_item = ValueItem(
name=data[0],
type=field_name,
value=str(data[field_names.index(field_name)]),
)
values.append(value_item)
return field_names, values
except Exception as e:
logger.debug("Prepare Chart Data Failed!" + str(e))
Expand Down
11 changes: 11 additions & 0 deletions dbgpt/util/date_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import datetime


def is_datetime(value):
return isinstance(value, datetime.datetime)


def convert_datetime_in_row(row):
return [value.strftime('%Y-%m-%d %H:%M:%S') if is_datetime(value)
else value for value in row]

Loading