Skip to content

Commit a44cefe

Browse files
authored
Merge branch 'develop' into PNO/set-iam-integration
2 parents bb83716 + b3e285a commit a44cefe

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

docs/labelbox/project-overview.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ProjectOverview
2+
===============================================================================================
3+
4+
.. automodule:: labelbox.schema.project-overview
5+
:members:
6+
:show-inheritance:

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from labelbox.schema.task import Task
4040
from labelbox.schema.task_queue import TaskQueue
4141
from labelbox.schema.ontology_kind import (EditorTaskType, OntologyKind)
42+
from labelbox.schema.project_overview import ProjectOverview
4243

4344
if TYPE_CHECKING:
4445
from labelbox import BulkImportRequest
@@ -1746,6 +1747,63 @@ def __check_data_rows_have_been_processed(
17461747
return response["queryAllDataRowsHaveBeenProcessed"][
17471748
"allDataRowsHaveBeenProcessed"]
17481749

1750+
def get_overview(self) -> ProjectOverview:
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 ProjectOverview(**overview)
1806+
17491807

17501808
class ProjectMember(DbObject):
17511809
user = Relationship.ToOne("User", cache=True)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Dict
2+
from labelbox.pydantic_compat import BaseModel
3+
4+
from typing import Dict
5+
6+
class ProjectOverview(BaseModel):
7+
"""
8+
Class that represents a project summary as displayed in the UI, in Annotate,
9+
under the "Overview" tab of a particular project.
10+
11+
All attributes represent the number of data rows in the corresponding state.
12+
The `in_review` attribute is a dictionary where the keys are the queue names
13+
and the values are the number of data rows in that queue.
14+
15+
Attributes:
16+
Representing existing fields from the Overview tag (UI names in parentheses):
17+
18+
to_label (int): The number of data rows that are yet to be labeled (To Label).
19+
in_review (Dict[str, int]): A dictionary where the keys are the queue names .
20+
and the values are the number of data rows in that queue. (In Review)
21+
in_rework (int): The number of data rows that are in the Rework queue (In Rework).
22+
skipped (int): The number of data rows that have been skipped (Skipped).
23+
done (int): The number of data rows that have been marked as Done (Done).
24+
issues (int): The number of data rows with associated issues (Issues).
25+
26+
Additional values:
27+
28+
labeled (int): The number of data rows that have been labeled.
29+
all_in_data_rows (int): The total number of data rows in the project.
30+
"""
31+
to_label: int
32+
in_review: Dict[str, int]
33+
in_rework: int
34+
skipped: int
35+
done: int
36+
issues: int
37+
labeled: int
38+
all_in_data_rows: int

libs/labelbox/tests/integration/test_task_queue.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
32
from labelbox import Project
43
from labelbox.schema.identifiables import GlobalKeys, UniqueIds
54

@@ -12,6 +11,19 @@ def test_get_task_queue(project: Project):
1211
assert review_queue
1312

1413

14+
def test_get_overview(project: Project):
15+
po = project.get_overview()
16+
17+
assert isinstance(po.to_label, int)
18+
assert isinstance(po.in_review, dict)
19+
assert isinstance(po.in_rework, int)
20+
assert isinstance(po.skipped, int)
21+
assert isinstance(po.done, int)
22+
assert isinstance(po.issues, int)
23+
assert isinstance(po.labeled, int)
24+
assert isinstance(po.all_in_data_rows, int)
25+
26+
1527
def _validate_moved(project, queue_name, data_row_count):
1628
timeout_seconds = 30
1729
sleep_time = 2

0 commit comments

Comments
 (0)