|
39 | 39 | from labelbox.schema.task import Task |
40 | 40 | from labelbox.schema.task_queue import TaskQueue |
41 | 41 | from labelbox.schema.ontology_kind import (EditorTaskType, OntologyKind) |
| 42 | +from labelbox.schema.project_overview import Project_Overview |
42 | 43 |
|
43 | 44 | if TYPE_CHECKING: |
44 | 45 | from labelbox import BulkImportRequest |
@@ -1746,6 +1747,63 @@ def __check_data_rows_have_been_processed( |
1746 | 1747 | return response["queryAllDataRowsHaveBeenProcessed"][ |
1747 | 1748 | "allDataRowsHaveBeenProcessed"] |
1748 | 1749 |
|
| 1750 | + def get_overview(self) -> Project_Overview: |
| 1751 | + """ Return the number of data rows per task queue, and issues of a project |
| 1752 | + Equivalent of the Overview tab of a project |
| 1753 | +
|
| 1754 | + Args: |
| 1755 | + with_issues: (optional) boolean to include issues in the overview |
| 1756 | + Returns: |
| 1757 | + Object Project_Overview |
| 1758 | + """ |
| 1759 | + |
| 1760 | + query = """query ProjectGetOverviewPyApi($projectId: ID!) { |
| 1761 | + project(where: { id: $projectId }) { |
| 1762 | + workstreamStateCounts { |
| 1763 | + state |
| 1764 | + count |
| 1765 | + } |
| 1766 | + taskQueues { |
| 1767 | + queueType |
| 1768 | + name |
| 1769 | + dataRowCount |
| 1770 | + } |
| 1771 | + issues { |
| 1772 | + totalCount |
| 1773 | + } |
| 1774 | + completedDataRowCount |
| 1775 | + } |
| 1776 | + } |
| 1777 | + """ |
| 1778 | + |
| 1779 | + # Must use experimental to access "issues" |
| 1780 | + result = self.client.execute(query, {"projectId": self.uid}, |
| 1781 | + experimental=True)["project"] |
| 1782 | + |
| 1783 | + overview = { |
| 1784 | + utils.snake_case(st["state"]): st["count"] |
| 1785 | + for st in result.get("workstreamStateCounts") |
| 1786 | + if st["state"] != "NotInTaskQueue" |
| 1787 | + } |
| 1788 | + |
| 1789 | + review_queues = { |
| 1790 | + tq["name"]: tq.get("dataRowCount") |
| 1791 | + for tq in result.get("taskQueues") |
| 1792 | + if tq.get("queueType") == "MANUAL_REVIEW_QUEUE" |
| 1793 | + } |
| 1794 | + |
| 1795 | + # Store the total number of data rows in review |
| 1796 | + review_queues["all"] = overview.get("in_review") |
| 1797 | + overview["in_review"] = review_queues |
| 1798 | + |
| 1799 | + overview["issues"] = result.get("issues", {}).get("totalCount") |
| 1800 | + |
| 1801 | + # Rename keys |
| 1802 | + overview["to_label"] = overview.pop("unlabeled") |
| 1803 | + overview["all_in_data_rows"] = overview.pop("all") |
| 1804 | + |
| 1805 | + return Project_Overview(**overview) |
| 1806 | + |
1749 | 1807 |
|
1750 | 1808 | class ProjectMember(DbObject): |
1751 | 1809 | user = Relationship.ToOne("User", cache=True) |
|
0 commit comments