|
1 | 1 | import logging |
2 | | -from typing import TYPE_CHECKING |
| 2 | +from typing import TYPE_CHECKING, Optional |
3 | 3 | import json |
4 | 4 |
|
5 | 5 | from labelbox.orm import query |
@@ -82,6 +82,30 @@ def bulk_delete(data_rows) -> None: |
82 | 82 | """ |
83 | 83 | BulkDeletable._bulk_delete(data_rows, True) |
84 | 84 |
|
| 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 | + |
85 | 109 | def create_attachment(self, attachment_type, |
86 | 110 | attachment_value) -> "AssetAttachment": |
87 | 111 | """ Adds an AssetAttachment to a DataRow. |
|
0 commit comments