Skip to content

Commit 700982c

Browse files
committed
Fixed format and remove nested function
1 parent a4fa4fc commit 700982c

File tree

1 file changed

+57
-76
lines changed

1 file changed

+57
-76
lines changed

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 57 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,96 +1754,77 @@ def __check_data_rows_have_been_processed(
17541754
"allDataRowsHaveBeenProcessed"]
17551755

17561756
def get_overview(self, details=False) -> Union[ProjectOverview, ProjectOverviewDetailed]:
1757-
"""Return the overview of a project.
1757+
"""Return the overview of a project.
17581758
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.
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.
17611761
1762-
Args:
1763-
details (bool, optional): Whether to include detailed queue information for review and rework queues.
1764-
Defaults to False.
1762+
Args:
1763+
details (bool, optional): Whether to include detailed queue information for review and rework queues.
1764+
Defaults to False.
17651765
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.
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.
17701770
1771-
Raises:
1772-
Exception: If there is an error executing the query.
1771+
Raises:
1772+
Exception: If there is an error executing the query.
17731773
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.
1774+
"""
1775+
query = """query ProjectGetOverviewPyApi($projectId: ID!) {
1776+
project(where: { id: $projectId }) {
1777+
workstreamStateCounts {
1778+
state
1779+
count
1780+
}
1781+
taskQueues {
1782+
queueType
1783+
name
1784+
dataRowCount
1785+
}
1786+
issues {
1787+
totalCount
1788+
}
1789+
completedDataRowCount
1790+
}
1791+
}
1792+
"""
17781793

1779-
Args:
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.
1794+
# Must use experimental to access "issues"
1795+
result = self.client.execute(query, {"projectId": self.uid},
1796+
experimental=True)["project"]
17831797

1784-
Returns:
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
1789-
"""
1798+
# Reformat category names
1799+
overview = {
1800+
utils.snake_case(st["state"]): st["count"]
1801+
for st in result.get("workstreamStateCounts")
1802+
if st["state"] != "NotInTaskQueue"
1803+
}
1804+
1805+
overview["issues"] = result.get("issues", {}).get("totalCount")
1806+
1807+
# Rename categories
1808+
overview["to_label"] = overview.pop("unlabeled")
1809+
overview["total_data_rows"] = overview.pop("all")
1810+
1811+
if not details:
1812+
return ProjectOverview(**overview)
1813+
else:
1814+
# Build dictionary for queue details for review and rework queues
1815+
for category in ["rework", "review"]:
17901816
queues = [
17911817
{tq["name"]: tq.get("dataRowCount")}
17921818
for tq in result.get("taskQueues")
1793-
if tq.get("queueType") == queue_type
1819+
if tq.get("queueType") == f"MANUAL_{category.upper()}_QUEUE"
17941820
]
17951821

1796-
return {
1822+
overview[f"in_{category}"] = {
17971823
"data": queues,
1798-
"total": total
1799-
}
1800-
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
1824+
"total": overview[f"in_{category}"]
18161825
}
1817-
}
1818-
"""
1819-
1820-
# Must use experimental to access "issues"
1821-
result = self.client.execute(query, {"projectId": self.uid},
1822-
experimental=True)["project"]
1823-
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-
}
1830-
1831-
overview["issues"] = result.get("issues", {}).get("totalCount")
1832-
1833-
# Rename categories
1834-
overview["to_label"] = overview.pop("unlabeled")
1835-
overview["total_data_rows"] = overview.pop("all")
1836-
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)
1826+
1827+
return ProjectOverviewDetailed(**overview)
18471828

18481829
def clone(self) -> "Project":
18491830
"""

0 commit comments

Comments
 (0)