diff --git a/dbgpt/app/openapi/api_v1/editor/api_editor_v1.py b/dbgpt/app/openapi/api_v1/editor/api_editor_v1.py index ad95a59bf..73c0a95de 100644 --- a/dbgpt/app/openapi/api_v1/editor/api_editor_v1.py +++ b/dbgpt/app/openapi/api_v1/editor/api_editor_v1.py @@ -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 @@ -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="", diff --git a/dbgpt/app/scene/chat_dashboard/data_loader.py b/dbgpt/app/scene/chat_dashboard/data_loader.py index 954e7da44..2a67a5e62 100644 --- a/dbgpt/app/scene/chat_dashboard/data_loader.py +++ b/dbgpt/app/scene/chat_dashboard/data_loader.py @@ -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)) diff --git a/dbgpt/util/date_utils.py b/dbgpt/util/date_utils.py new file mode 100644 index 000000000..e711070e8 --- /dev/null +++ b/dbgpt/util/date_utils.py @@ -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] +