Skip to content

Commit 6401702

Browse files
authored
test:delete unusual test file (#299)
1.delete usual test file 2.format code
2 parents 7bdbe2d + b68bb2b commit 6401702

12 files changed

Lines changed: 84 additions & 267 deletions

File tree

pilot/common/sql_database.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,31 @@ def __query(self, session, query, fetch: str = "all"):
268268
result.insert(0, field_names)
269269
return result
270270

271+
def query_ex(self, session, query, fetch: str = "all"):
272+
"""
273+
only for query
274+
Args:
275+
session:
276+
query:
277+
fetch:
278+
Returns:
279+
"""
280+
print(f"Query[{query}]")
281+
if not query:
282+
return []
283+
cursor = session.execute(text(query))
284+
if cursor.returns_rows:
285+
if fetch == "all":
286+
result = cursor.fetchall()
287+
elif fetch == "one":
288+
result = cursor.fetchone()[0] # type: ignore
289+
else:
290+
raise ValueError("Fetch parameter must be either 'one' or 'all'")
291+
field_names = list(i[0:] for i in cursor.keys())
292+
293+
result = list(result)
294+
return field_names, result
295+
271296
def run(self, session, command: str, fetch: str = "all") -> List:
272297
"""Execute a SQL command and return a string representing the results."""
273298
print("SQL:" + command)

pilot/connections/rdbms/py_study/__init__.py

Whitespace-only changes.

pilot/connections/rdbms/py_study/pd_study.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

pilot/connections/rdbms/py_study/study_data.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

pilot/connections/rdbms/py_study/study_duckdb.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

pilot/connections/rdbms/py_study/study_enum.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

pilot/connections/rdbms/py_study/test_cls_1.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

pilot/connections/rdbms/py_study/test_cls_2.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

pilot/connections/rdbms/py_study/test_cls_base.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

pilot/scene/chat_dashboard/chat.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import uuid
44
from typing import Dict, NamedTuple, List
5+
from decimal import Decimal
6+
57
from pilot.scene.base_message import (
68
HumanMessage,
79
ViewMessage,
@@ -17,6 +19,7 @@
1719
from pilot.scene.chat_dashboard.data_preparation.report_schma import (
1820
ChartData,
1921
ReportData,
22+
ValueItem,
2023
)
2124

2225
CFG = Config()
@@ -74,16 +77,49 @@ def do_action(self, prompt_response):
7477
chart_datas: List[ChartData] = []
7578
for chart_item in prompt_response:
7679
try:
77-
datas = self.database.run(self.db_connect, chart_item.sql)
80+
field_names, datas = self.database.query_ex(
81+
self.db_connect, chart_item.sql
82+
)
83+
values: List[ValueItem] = []
84+
data_map = {}
85+
field_map = {}
86+
index = 0
87+
for field_name in field_names:
88+
data_map.update({f"{field_name}": [row[index] for row in datas]})
89+
index += 1
90+
if not data_map[field_name]:
91+
field_map.update({f"{field_name}": False})
92+
else:
93+
field_map.update(
94+
{
95+
f"{field_name}": all(
96+
isinstance(item, (int, float, Decimal))
97+
for item in data_map[field_name]
98+
)
99+
}
100+
)
101+
102+
for field_name in field_names[1:]:
103+
if not field_map[field_name]:
104+
print("more than 2 non-numeric column")
105+
else:
106+
for data in datas:
107+
value_item = ValueItem(
108+
name=data[0],
109+
type=field_name,
110+
value=data[field_names.index(field_name)],
111+
)
112+
values.append(value_item)
113+
78114
chart_datas.append(
79115
ChartData(
80116
chart_uid=str(uuid.uuid1()),
81117
chart_name=chart_item.title,
82118
chart_type=chart_item.showcase,
83119
chart_desc=chart_item.thoughts,
84120
chart_sql=chart_item.sql,
85-
column_name=datas[0],
86-
values=datas,
121+
column_name=field_names,
122+
values=values,
87123
)
88124
)
89125
except Exception as e:

0 commit comments

Comments
 (0)