|
41 | 41 | from labelbox.schema.task import Task
|
42 | 42 | from labelbox.schema.task_queue import TaskQueue
|
43 | 43 | from labelbox.schema.ontology_kind import (EditorTaskType, OntologyKind)
|
44 |
| -from labelbox.schema.project_overview import ProjectOverview |
| 44 | +from labelbox.schema.project_overview import ProjectOverview, ProjectOverviewDetailed |
45 | 45 |
|
46 | 46 | if TYPE_CHECKING:
|
47 | 47 | from labelbox import BulkImportRequest
|
@@ -1753,62 +1753,97 @@ def __check_data_rows_have_been_processed(
|
1753 | 1753 | return response["queryAllDataRowsHaveBeenProcessed"][
|
1754 | 1754 | "allDataRowsHaveBeenProcessed"]
|
1755 | 1755 |
|
1756 |
| - def get_overview(self) -> ProjectOverview: |
1757 |
| - """ Return the number of data rows per task queue, and issues of a project |
1758 |
| - Equivalent of the Overview tab of a project |
| 1756 | + def get_overview(self, details=False) -> Union[ProjectOverview, ProjectOverviewDetailed]: |
| 1757 | + """Return the overview of a project. |
| 1758 | +
|
| 1759 | + This method returns the number of data rows per task queue and issues of a project, |
| 1760 | + which is equivalent to the Overview tab of a project. |
| 1761 | +
|
| 1762 | + Args: |
| 1763 | + details (bool, optional): Whether to include detailed queue information for review and rework queues. |
| 1764 | + Defaults to False. |
| 1765 | +
|
| 1766 | + Returns: |
| 1767 | + Union[ProjectOverview, ProjectOverviewDetailed]: An object representing the project overview. |
| 1768 | + If `details` is False, returns a `ProjectOverview` object. |
| 1769 | + If `details` is True, returns a `ProjectOverviewDetailed` object. |
| 1770 | +
|
| 1771 | + Raises: |
| 1772 | + Exception: If there is an error executing the query. |
| 1773 | +
|
| 1774 | + """ |
| 1775 | + def _build_queue_details(overview_category: str, queue_type: str, total: int): |
| 1776 | + """ |
| 1777 | + Builds the queue details for a given overview category and queue type. |
1759 | 1778 |
|
1760 | 1779 | Args:
|
1761 |
| - with_issues: (optional) boolean to include issues in the overview |
| 1780 | + overview_category (str): The overview category. |
| 1781 | + queue_type (str): The queue type. |
| 1782 | + total (int): The total number of items in the queue. |
| 1783 | +
|
1762 | 1784 | Returns:
|
1763 |
| - Object Project_Overview |
| 1785 | + dict: A dictionary containing the queue details. |
| 1786 | + - data (list): A list of dictionaries representing the queues. |
| 1787 | + Each dictionary contains the queue name and the number of data rows. |
| 1788 | + - total (int): The total number of data rows for the category |
1764 | 1789 | """
|
| 1790 | + queues = [ |
| 1791 | + {tq["name"]: tq.get("dataRowCount")} |
| 1792 | + for tq in result.get("taskQueues") |
| 1793 | + if tq.get("queueType") == queue_type |
| 1794 | + ] |
| 1795 | + |
| 1796 | + return { |
| 1797 | + "data": queues, |
| 1798 | + "total": total |
| 1799 | + } |
1765 | 1800 |
|
1766 |
| - query = """query ProjectGetOverviewPyApi($projectId: ID!) { |
1767 |
| - project(where: { id: $projectId }) { |
1768 |
| - workstreamStateCounts { |
1769 |
| - state |
1770 |
| - count |
1771 |
| - } |
1772 |
| - taskQueues { |
1773 |
| - queueType |
1774 |
| - name |
1775 |
| - dataRowCount |
1776 |
| - } |
1777 |
| - issues { |
1778 |
| - totalCount |
1779 |
| - } |
1780 |
| - completedDataRowCount |
| 1801 | + query = """query ProjectGetOverviewPyApi($projectId: ID!) { |
| 1802 | + project(where: { id: $projectId }) { |
| 1803 | + workstreamStateCounts { |
| 1804 | + state |
| 1805 | + count |
| 1806 | + } |
| 1807 | + taskQueues { |
| 1808 | + queueType |
| 1809 | + name |
| 1810 | + dataRowCount |
| 1811 | + } |
| 1812 | + issues { |
| 1813 | + totalCount |
| 1814 | + } |
| 1815 | + completedDataRowCount |
| 1816 | + } |
1781 | 1817 | }
|
1782 |
| - } |
1783 |
| - """ |
| 1818 | + """ |
1784 | 1819 |
|
1785 |
| - # Must use experimental to access "issues" |
1786 |
| - result = self.client.execute(query, {"projectId": self.uid}, |
1787 |
| - experimental=True)["project"] |
| 1820 | + # Must use experimental to access "issues" |
| 1821 | + result = self.client.execute(query, {"projectId": self.uid}, |
| 1822 | + experimental=True)["project"] |
1788 | 1823 |
|
1789 |
| - overview = { |
1790 |
| - utils.snake_case(st["state"]): st["count"] |
1791 |
| - for st in result.get("workstreamStateCounts") |
1792 |
| - if st["state"] != "NotInTaskQueue" |
1793 |
| - } |
1794 |
| - |
1795 |
| - review_queues = { |
1796 |
| - tq["name"]: tq.get("dataRowCount") |
1797 |
| - for tq in result.get("taskQueues") |
1798 |
| - if tq.get("queueType") == "MANUAL_REVIEW_QUEUE" |
1799 |
| - } |
1800 |
| - |
1801 |
| - # Store the total number of data rows in review |
1802 |
| - review_queues["all"] = overview.get("in_review") |
1803 |
| - overview["in_review"] = review_queues |
| 1824 | + # Reformat category names |
| 1825 | + overview = { |
| 1826 | + utils.snake_case(st["state"]): st["count"] |
| 1827 | + for st in result.get("workstreamStateCounts") |
| 1828 | + if st["state"] != "NotInTaskQueue" |
| 1829 | + } |
1804 | 1830 |
|
1805 |
| - overview["issues"] = result.get("issues", {}).get("totalCount") |
| 1831 | + overview["issues"] = result.get("issues", {}).get("totalCount") |
1806 | 1832 |
|
1807 |
| - # Rename keys |
1808 |
| - overview["to_label"] = overview.pop("unlabeled") |
1809 |
| - overview["all_in_data_rows"] = overview.pop("all") |
| 1833 | + # Rename categories |
| 1834 | + overview["to_label"] = overview.pop("unlabeled") |
| 1835 | + overview["total_data_rows"] = overview.pop("all") |
1810 | 1836 |
|
1811 |
| - return ProjectOverview(**overview) |
| 1837 | + if not details: |
| 1838 | + return ProjectOverview(**overview) |
| 1839 | + else: |
| 1840 | + # Build queue details for review and rework queues |
| 1841 | + for category in ["rework", "review"]: |
| 1842 | + overview[f"in_{category}"] = _build_queue_details(f"in_{category}", |
| 1843 | + f"MANUAL_{category.upper()}_QUEUE", |
| 1844 | + overview[f"in_{category}"]) |
| 1845 | + |
| 1846 | + return ProjectOverviewDetailed(**overview) |
1812 | 1847 |
|
1813 | 1848 | def clone(self) -> "Project":
|
1814 | 1849 | """
|
|
0 commit comments