Skip to content

Commit 49ea94a

Browse files
committed
[QQC-1061] Add get_winning_label_id to data row
1 parent 6df07ce commit 49ea94a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

labelbox/schema/data_row.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import TYPE_CHECKING
2+
from typing import TYPE_CHECKING, Optional
33
import json
44

55
from labelbox.orm import query
@@ -82,6 +82,30 @@ def bulk_delete(data_rows) -> None:
8282
"""
8383
BulkDeletable._bulk_delete(data_rows, True)
8484

85+
def get_winning_label_id(self, project_id: str) -> Optional[str]:
86+
""" Retrieves the winning label ID, i.e. the one that was marked as the
87+
best for a particular data row, in a project's workflow.
88+
89+
Args:
90+
project_id (str): ID of the project containing the data row
91+
"""
92+
data_row_id_param = "dataRowId"
93+
project_id_param = "projectId"
94+
query_str = """query GetWinningLabelIdPyApi($%s: ID!, $%s: ID!) {
95+
dataRow(where: { id: $%s }) {
96+
labelingActivity(where: { projectId: $%s }) {
97+
selectedLabelId
98+
}
99+
}} """ % (data_row_id_param, project_id_param, data_row_id_param,
100+
project_id_param)
101+
102+
res = self.client.execute(query_str, {
103+
data_row_id_param: self.uid,
104+
project_id_param: project_id,
105+
})
106+
107+
return res["dataRow"]["labelingActivity"]["selectedLabelId"]
108+
85109
def create_attachment(self, attachment_type,
86110
attachment_value) -> "AssetAttachment":
87111
""" Adds an AssetAttachment to a DataRow.

0 commit comments

Comments
 (0)