Skip to content

Commit de73623

Browse files
committed
added labels to plots
1 parent 1433462 commit de73623

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

test2text/pages/reports/report_by_req.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from test2text.services.utils.math_utils import round_distance
77

8-
SUMMARY_LENGHT = 100
8+
SUMMARY_LENGTH = 100
99

1010
def make_a_report():
1111
from test2text.services.db import get_db_client
@@ -88,12 +88,12 @@ def write_annotations(current_annotations: set[tuple]):
8888
)
8989
if distance_sql:
9090
requirements_dict = {
91-
f"{req_external_id} {summary[:SUMMARY_LENGHT]}... [smart search d={round_distance(distance)}]": req_id
91+
f"{req_external_id} {summary[:SUMMARY_LENGTH]}... [smart search d={round_distance(distance)}]": req_id
9292
for (req_id, req_external_id, summary, distance) in data.fetchall()
9393
}
9494
else:
9595
requirements_dict = {
96-
f"{req_external_id} {summary[:SUMMARY_LENGHT]}...": req_id
96+
f"{req_external_id} {summary[:SUMMARY_LENGTH]}...": req_id
9797
for (req_id, req_external_id, summary) in data.fetchall()
9898
}
9999

@@ -262,6 +262,12 @@ def write_annotations(current_annotations: set[tuple]):
262262
st.session_state["radio_choice"]
263263
]
264264
]
265+
anno_labels = [
266+
f"{anno_id} {anno_sum[:SUMMARY_LENGTH]}"
267+
for anno_id, anno_sum, _, _ in current_test_cases[
268+
st.session_state["radio_choice"]
269+
]
270+
]
265271
requirement_vectors = np.array(
266272
[np.array(unpack_float32(req_embedding))]
267273
)
@@ -274,8 +280,9 @@ def write_annotations(current_annotations: set[tuple]):
274280
minifold_vectors_2d(annotation_vectors),
275281
"Requirement",
276282
"Annotations",
277-
first_color="red",
278-
second_color="green",
283+
first_labels=[f"{req_external_id}"],
284+
second_labels=anno_labels,
285+
279286
)
280287
else:
281288
reqs_vectors_3d = minifold_vectors_3d(
@@ -289,6 +296,8 @@ def write_annotations(current_annotations: set[tuple]):
289296
anno_vectors_3d,
290297
"Requirement",
291298
"Annotations",
299+
first_labels=[f"{req_external_id}"],
300+
second_labels=anno_labels,
292301
)
293302

294303

test2text/pages/reports/report_by_tc.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from test2text.services.utils.math_utils import round_distance
77

88

9+
SUMMARY_LENGTH = 100
10+
911
def make_a_tc_report():
1012
from test2text.services.db import get_db_client
1113

@@ -272,6 +274,12 @@ def write_requirements(current_requirements: set[tuple]):
272274
reqs_by_anno[radio_choice]
273275
]
274276
]
277+
req_labels = [
278+
f"{ext_id}"
279+
for _, ext_id, req_sum, _, _ in current_annotations[
280+
reqs_by_anno[radio_choice]
281+
]
282+
]
275283
annotation_vectors = np.array(
276284
[np.array(unpack_float32(anno_embedding))]
277285
)
@@ -282,10 +290,10 @@ def write_requirements(current_requirements: set[tuple]):
282290
minifold_vectors_2d(
283291
requirement_vectors
284292
),
285-
"Annotation",
286-
"Requirements",
287-
first_color="red",
288-
second_color="green",
293+
first_title="Annotation",
294+
second_title="Requirements",
295+
first_labels=radio_choice,
296+
second_labels=req_labels,
289297
)
290298
else:
291299
reqs_vectors_3d = minifold_vectors_3d(
@@ -297,8 +305,10 @@ def write_requirements(current_requirements: set[tuple]):
297305
plot_2_sets_in_one_3d(
298306
anno_vectors_3d,
299307
reqs_vectors_3d,
300-
"Annotation",
301-
"Requirements",
308+
first_title="Annotation",
309+
second_title="Requirements",
310+
first_labels=radio_choice,
311+
second_labels=req_labels,
302312
)
303313

304314

test2text/services/visualisation/visualize_vectors.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,31 @@ def plot_2_sets_in_one_2d(
100100
second_set_of_vec,
101101
first_title,
102102
second_title,
103-
first_color="blue",
103+
first_color="red",
104104
second_color="green",
105+
first_labels=None,
106+
second_labels=None
105107
):
106108
fig = go.Figure()
107109
fig.add_trace(
108110
go.Scatter(
109111
x=first_set_of_vec[:, 0],
110112
y=first_set_of_vec[:, 1],
111-
mode="markers",
113+
mode="markers+text",
112114
name=first_title,
115+
text=first_labels,
116+
textposition="top center",
113117
marker=dict(color=f"{first_color}"),
114118
)
115119
)
116120
fig.add_trace(
117121
go.Scatter(
118122
x=second_set_of_vec[:, 0],
119123
y=second_set_of_vec[:, 1],
120-
mode="markers",
124+
mode="markers+text",
121125
name=second_title,
126+
text=second_labels,
127+
textposition="top center",
122128
marker=dict(color=f"{second_color}"),
123129
)
124130
)
@@ -129,16 +135,26 @@ def plot_2_sets_in_one_2d(
129135

130136

131137
def plot_2_sets_in_one_3d(
132-
first_set_of_vec, second_set_of_vec, first_title, second_title
138+
first_set_of_vec,
139+
second_set_of_vec,
140+
first_title,
141+
second_title,
142+
first_color="red",
143+
second_color="green",
144+
first_labels=None,
145+
second_labels=None
133146
):
134147
fig = go.Figure()
135148
fig.add_trace(
136149
go.Scatter3d(
137150
x=first_set_of_vec[:, 0],
138151
y=first_set_of_vec[:, 1],
139152
z=first_set_of_vec[:, 2],
140-
mode="markers",
153+
mode="markers+text",
141154
name=first_title,
155+
text=first_labels,
156+
textposition="top left",
157+
marker=dict(color=f"{first_color}")
142158
)
143159
)
144160

@@ -147,8 +163,11 @@ def plot_2_sets_in_one_3d(
147163
x=second_set_of_vec[:, 0],
148164
y=second_set_of_vec[:, 1],
149165
z=second_set_of_vec[:, 2],
150-
mode="markers",
166+
mode="markers+text",
151167
name=second_title,
168+
text=second_labels,
169+
textposition="top center",
170+
marker=dict(color=f"{second_color}")
152171
)
153172
)
154173

0 commit comments

Comments
 (0)