Skip to content

Commit 0701c6d

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

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from labelbox import utils
2121
from labelbox.adv_client import AdvClient
2222
from labelbox.orm import query
23-
from labelbox.orm.comparison import Comparison
2423
from labelbox.orm.db_object import DbObject
2524
from labelbox.orm.model import Entity, Field
2625
from labelbox.pagination import PaginatedCollection
@@ -2395,6 +2394,17 @@ def upsert_label_feedback(self, label_id: str, feedback: str,
23952394
def get_labeling_service_dashboards(
23962395
self,
23972396
after: Optional[str] = None,
2398-
where: Optional[Comparison] = None,
2397+
search_query: Optional[List[Dict]] = None,
23992398
) -> PaginatedCollection:
2400-
return LabelingServiceDashboard.get_all(self, after, where)
2399+
"""
2400+
Get all labeling service dashboards for a given org.
2401+
2402+
Optional parameters:
2403+
after: The cursor to use for pagination.
2404+
where: A filter to apply to the query.
2405+
2406+
NOTE: support for after and search_query are not yet implemented.
2407+
"""
2408+
return LabelingServiceDashboard.get_all(self,
2409+
after,
2410+
search_query=search_query)

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
from datetime import datetime
21
from string import Template
2+
from datetime import datetime
33
from typing import Any, Dict, List, Optional
44

55
from labelbox.exceptions import ResourceNotFoundError
6-
from labelbox.orm.comparison import Comparison
7-
from labelbox.orm import query
8-
from ..orm.model import Field
96
from labelbox.pagination import PaginatedCollection
10-
from labelbox.pydantic_compat import BaseModel, root_validator
11-
from .organization import Organization
7+
from labelbox.pydantic_compat import BaseModel, root_validator, Field
128
from labelbox.utils import _CamelCaseMixin
139
from labelbox.schema.labeling_service_status import LabelingServiceStatus
1410

@@ -28,15 +24,29 @@
2824

2925

3026
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
27+
"""
28+
Represent labeling service data for a project
29+
30+
Attributes:
31+
id (str): project id
32+
name (str): project name
33+
status (LabelingServiceStatus): status of the labeling service
34+
tasks_completed (int): number of data rows completed
35+
tasks_remaining (int): number of data rows that have not started
36+
client (Any): labelbox client
37+
"""
38+
id: str = Field(frozen=True)
39+
name: str = Field(frozen=True)
40+
service_type: Optional[str] = Field(frozen=True, default=None)
41+
created_at: Optional[datetime] = Field(frozen=True, default=None)
42+
updated_at: Optional[datetime] = Field(frozen=True, default=None)
43+
created_by_id: Optional[str] = Field(frozen=True, default=None)
44+
status: LabelingServiceStatus = Field(frozen=True,
45+
default=LabelingServiceStatus.Missing)
46+
data_rows_count: int = Field(frozen=True)
47+
data_rows_in_review_count: int = Field(frozen=True)
48+
data_rows_in_rework_count: int = Field(frozen=True)
49+
data_rows_done_count: int = Field(frozen=True)
4050

4151
client: Any # type Any to avoid circular import from client
4252

@@ -46,6 +56,14 @@ def __init__(self, **kwargs):
4656
raise RuntimeError(
4757
"Please enable experimental in client to use LabelingService")
4858

59+
@property
60+
def tasks_completed(self):
61+
return self.data_rows_done_count
62+
63+
@property
64+
def tasks_remaining(self):
65+
return self.data_rows_count - self.data_rows_done_count
66+
4967
class Config(_CamelCaseMixin.Config):
5068
...
5169

@@ -74,7 +92,7 @@ def get(cls, client, project_id: str) -> 'LabelingServiceDashboard':
7492
}
7593
}
7694
"""
77-
result = client.execute(query, {"id": project_id})
95+
result = client.execute(query, {"id": project_id}, experimental=True)
7896
if result["getProjectById"] is None:
7997
raise ResourceNotFoundError(
8098
message="The project does not have a labeling service.")
@@ -87,7 +105,6 @@ def get_all(
87105
cls,
88106
client,
89107
after: Optional[str] = None,
90-
# where: Optional[Comparison] = None,
91108
search_query: Optional[List[Dict]] = None,
92109
) -> PaginatedCollection:
93110
template = Template(
@@ -121,16 +138,12 @@ def convert_to_labeling_service_dashboard(client, data):
121138
dereferencing=['searchProjects', 'nodes'],
122139
obj_class=convert_to_labeling_service_dashboard,
123140
cursor_path=['searchProjects', 'pageInfo', 'endCursor'],
141+
experimental=True,
124142
)
125143

126144
@root_validator(pre=True)
127-
def convert_graphql_to_attrs(cls, data):
145+
def convert_boost_status_to_enum(cls, data):
128146
if 'boostStatus' in data:
129147
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'])
135148

136149
return data

0 commit comments

Comments
 (0)