Skip to content

Commit 1ac021c

Browse files
author
Val Brodsky
committed
Cleanup LabelingDashboard
1 parent fd7c426 commit 1ac021c

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

libs/labelbox/src/labelbox/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@
4343
from labelbox.schema.identifiable import UniqueId, GlobalKey
4444
from labelbox.schema.ontology_kind import OntologyKind
4545
from labelbox.schema.project_overview import ProjectOverview, ProjectOverviewDetailed
46-
from labelbox.schema.labeling_service import LabelingService, LabelingServiceStatus
46+
from labelbox.schema.labeling_service import LabelingService
47+
from labelbox.schema.labeling_service_dashboard import LabelingServiceDashboard
48+
from labelbox.schema.labeling_service_status import LabelingServiceStatus

libs/labelbox/src/labelbox/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,4 +2397,11 @@ def get_labeling_service_dashboards(
23972397
after: Optional[str] = None,
23982398
where: Optional[Comparison] = None,
23992399
) -> PaginatedCollection:
2400+
"""
2401+
Get all labeling service dashboards for a given org.
2402+
2403+
Optional parameters:
2404+
after: The cursor to use for pagination.
2405+
where: A filter to apply to the query.
2406+
"""
24002407
return LabelingServiceDashboard.get_all(self, after, where)

libs/labelbox/src/labelbox/schema/labeling_service_dashboard.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
from datetime import datetime
1+
from email.policy import default
22
from string import Template
3+
from datetime import datetime
34
from typing import Any, Dict, List, Optional
45

6+
import sys
7+
8+
if sys.version_info[:2] == (3, 8):
9+
from typing_extensions import Annotated
10+
else:
11+
from typing import Annotated
12+
513
from labelbox.exceptions import ResourceNotFoundError
6-
from labelbox.orm.comparison import Comparison
7-
from labelbox.orm import query
8-
from ..orm.model import Field
914
from labelbox.pagination import PaginatedCollection
10-
from labelbox.pydantic_compat import BaseModel, root_validator
11-
from .organization import Organization
15+
from labelbox.pydantic_compat import BaseModel, root_validator, Field
1216
from labelbox.utils import _CamelCaseMixin
1317
from labelbox.schema.labeling_service_status import LabelingServiceStatus
1418

@@ -28,15 +32,29 @@
2832

2933

3034
class LabelingServiceDashboard(BaseModel):
31-
id: str
32-
name: str
33-
# service_type: str
34-
# created_at: datetime
35-
# updated_at: datetime
36-
# created_by_id: str
37-
status: LabelingServiceStatus
38-
tasks_completed: int
39-
tasks_remaining: int
35+
"""
36+
Represent labeling service data for a project
37+
38+
Attributes:
39+
id (str): project id
40+
name (str): project name
41+
status (LabelingServiceStatus): status of the labeling service
42+
tasks_completed (int): number of data rows completed
43+
tasks_remaining (int): number of data rows that have not started
44+
client (Any): labelbox client
45+
"""
46+
id: str = Field(frozen=True)
47+
name: str = Field(frozen=True)
48+
service_type: Optional[str] = Field(frozen=True, default=None)
49+
created_at: Optional[datetime] = Field(frozen=True, default=None)
50+
updated_at: Optional[datetime] = Field(frozen=True, default=None)
51+
created_by_id: Optional[str] = Field(frozen=True, default=None)
52+
status: LabelingServiceStatus = Field(frozen=True,
53+
default=LabelingServiceStatus.Missing)
54+
data_rows_count: int = Field(frozen=True)
55+
data_rows_in_review_count: int = Field(frozen=True)
56+
data_rows_in_rework_count: int = Field(frozen=True)
57+
data_rows_done_count: int = Field(frozen=True)
4058

4159
client: Any # type Any to avoid circular import from client
4260

@@ -46,6 +64,14 @@ def __init__(self, **kwargs):
4664
raise RuntimeError(
4765
"Please enable experimental in client to use LabelingService")
4866

67+
@property
68+
def tasks_completed(self):
69+
return self.data_rows_done_count
70+
71+
@property
72+
def tasks_remaining(self):
73+
return self.data_rows_count - self.data_rows_done_count
74+
4975
class Config(_CamelCaseMixin.Config):
5076
...
5177

@@ -124,13 +150,8 @@ def convert_to_labeling_service_dashboard(client, data):
124150
)
125151

126152
@root_validator(pre=True)
127-
def convert_graphql_to_attrs(cls, data):
153+
def convert_boost_status_to_enum(cls, data):
128154
if 'boostStatus' in data:
129155
data['status'] = LabelingServiceStatus(data.pop('boostStatus'))
130-
if 'dataRowsDoneCount' in data:
131-
data['tasksCompleted'] = data.pop('dataRowsDoneCount')
132-
if 'dataRowsCount' in data and 'dataRowsInReviewCount' in data and 'dataRowsInReworkCount' in data:
133-
data['tasksRemaining'] = data['dataRowsCount'] - (
134-
data['dataRowsInReviewCount'] + data['dataRowsInReworkCount'])
135156

136157
return data

0 commit comments

Comments
 (0)