Skip to content

Commit d72b7a9

Browse files
committed
[Req report] Fix data fetching
1 parent c6e82fd commit d72b7a9

File tree

5 files changed

+39
-59
lines changed

5 files changed

+39
-59
lines changed

test2text/pages/reports/report_by_req.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from test2text.services.utils.math_utils import round_distance
66
from test2text.services.repositories import requirements
7+
from test2text.services.repositories import test_cases
78

89
SUMMARY_LENGTH = 100
910
LABELS_SUMMARY_LENGTH = 15
@@ -171,7 +172,7 @@ def make_a_report():
171172
smart_search_query=filter_embedding)
172173

173174
requirements_dict = {
174-
f"{req_external_id} {summary[:SUMMARY_LENGTH]}...": req_id
175+
req_id: f"{req_external_id} {summary[:SUMMARY_LENGTH]}..."
175176
for (req_id, req_external_id, summary) in data
176177
}
177178

@@ -180,6 +181,7 @@ def make_a_report():
180181
"Choose a requirement to work with",
181182
requirements_dict.keys(),
182183
key="filter_req_id",
184+
format_func=lambda x: requirements_dict[x],
183185
)
184186

185187
if selected_requirement:
@@ -206,14 +208,7 @@ def make_a_report():
206208
)
207209
st.info("Limit of selected test cases")
208210

209-
if filter_radius:
210-
where_clauses.append("distance <= ?")
211-
params.append(f"{filter_radius}")
212-
213-
if filter_limit:
214-
params.append(f"{filter_limit}")
215-
216-
rows = db.join_all_tables_by_requirements(where_clauses, params)
211+
rows = test_cases.fetch_test_cases_by_requirement(db, selected_requirement, filter_radius, filter_limit)
217212

218213
if not rows:
219214
st.error(

test2text/services/db/client.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -184,55 +184,6 @@ def get_embeddings_from_annotations_to_requirements_table(self):
184184
""")
185185
return cursor.fetchall()
186186

187-
def join_all_tables_by_requirements(
188-
self, where_clauses="", params=None
189-
) -> list[tuple]:
190-
"""
191-
Extract values from requirements with related annotations and their test cases based on the provided where clauses and parameters.
192-
Return a list of tuples containing :
193-
req_id,
194-
req_external_id,
195-
req_summary,
196-
req_embedding,
197-
anno_id,
198-
anno_summary,
199-
anno_embedding,
200-
distance,
201-
case_id,
202-
test_script,
203-
test_case
204-
"""
205-
where_sql = f"WHERE {' AND '.join(where_clauses)}" if where_clauses else ""
206-
sql = f"""
207-
SELECT
208-
Requirements.id as req_id,
209-
Requirements.external_id as req_external_id,
210-
Requirements.summary as req_summary,
211-
Requirements.embedding as req_embedding,
212-
213-
Annotations.id as anno_id,
214-
Annotations.summary as anno_summary,
215-
Annotations.embedding as anno_embedding,
216-
217-
AnnotationsToRequirements.cached_distance as distance,
218-
219-
TestCases.id as case_id,
220-
TestCases.test_script as test_script,
221-
TestCases.test_case as test_case
222-
FROM
223-
Requirements
224-
JOIN AnnotationsToRequirements ON Requirements.id = AnnotationsToRequirements.requirement_id
225-
JOIN Annotations ON Annotations.id = AnnotationsToRequirements.annotation_id
226-
JOIN CasesToAnnos ON Annotations.id = CasesToAnnos.annotation_id
227-
JOIN TestCases ON TestCases.id = CasesToAnnos.case_id
228-
{where_sql}
229-
ORDER BY
230-
Requirements.id, AnnotationsToRequirements.cached_distance, TestCases.id
231-
LIMIT ?
232-
"""
233-
data = self.conn.execute(sql, params)
234-
return data.fetchall()
235-
236187
def get_ordered_values_from_test_cases(
237188
self, distance_sql="", where_clauses="", distance_order_sql="", params=None
238189
) -> list[tuple]:

test2text/services/repositories/requirements/fetch_filtered.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def fetch_filtered_requirements(db: DbClient,
3131
if smart_search_query:
3232
from test2text.services.embeddings.embed import embed_requirement
3333
embedding = embed_requirement(smart_search_query.strip())
34-
conditions.append("vec_distance(Requirements.embedding, ?) < 0.7")
34+
conditions.append("vec_distance_L2(Requirements.embedding, ?) < 0.7")
3535
options.append(serialize_float32(embedding))
3636
sql += " AND ".join(conditions)
3737
sql += " ORDER BY Requirements.id ASC"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__all__=['fetch_test_cases_by_requirement']
2+
3+
from .fetch_by_requirement import fetch_test_cases_by_requirement
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from test2text.services.db import DbClient
2+
3+
4+
def fetch_test_cases_by_requirement(db: DbClient, requirement_id: int, radius: float, limit: int) -> list:
5+
sql = f"""
6+
SELECT
7+
Requirements.id as req_id,
8+
Requirements.external_id as req_external_id,
9+
Requirements.summary as req_summary,
10+
Requirements.embedding as req_embedding,
11+
12+
Annotations.id as anno_id,
13+
Annotations.summary as anno_summary,
14+
Annotations.embedding as anno_embedding,
15+
16+
vec_distance_L2(Requirements.embedding, Annotations.embedding) as distance,
17+
18+
TestCases.id as case_id,
19+
TestCases.test_script as test_script,
20+
TestCases.test_case as test_case
21+
FROM
22+
Requirements
23+
JOIN Annotations ON vec_distance_L2(Requirements.embedding, Annotations.embedding) <= ?
24+
JOIN CasesToAnnos ON Annotations.id = CasesToAnnos.annotation_id
25+
JOIN TestCases ON TestCases.id = CasesToAnnos.case_id
26+
WHERE Requirements.id = ?
27+
ORDER BY
28+
Requirements.id, distance, TestCases.id
29+
LIMIT ?
30+
"""
31+
return db.conn.execute(sql, (radius, requirement_id, limit)).fetchall()

0 commit comments

Comments
 (0)