diff --git a/labelbox/schema/data_row.py b/labelbox/schema/data_row.py index 0ec7a4e6e..d65a222ff 100644 --- a/labelbox/schema/data_row.py +++ b/labelbox/schema/data_row.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional import json from labelbox.orm import query @@ -82,6 +82,30 @@ def bulk_delete(data_rows) -> None: """ BulkDeletable._bulk_delete(data_rows, True) + def get_winning_label_id(self, project_id: str) -> Optional[str]: + """ Retrieves the winning label ID, i.e. the one that was marked as the + best for a particular data row, in a project's workflow. + + Args: + project_id (str): ID of the project containing the data row + """ + data_row_id_param = "dataRowId" + project_id_param = "projectId" + query_str = """query GetWinningLabelIdPyApi($%s: ID!, $%s: ID!) { + dataRow(where: { id: $%s }) { + labelingActivity(where: { projectId: $%s }) { + selectedLabelId + } + }} """ % (data_row_id_param, project_id_param, data_row_id_param, + project_id_param) + + res = self.client.execute(query_str, { + data_row_id_param: self.uid, + project_id_param: project_id, + }) + + return res["dataRow"]["labelingActivity"]["selectedLabelId"] + def create_attachment(self, attachment_type, attachment_value) -> "AssetAttachment": """ Adds an AssetAttachment to a DataRow.