1
- from datetime import datetime
1
+ from email . policy import default
2
2
from string import Template
3
+ from datetime import datetime
3
4
from typing import Any , Dict , List , Optional
4
5
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
+
5
13
from labelbox .exceptions import ResourceNotFoundError
6
- from labelbox .orm .comparison import Comparison
7
- from labelbox .orm import query
8
- from ..orm .model import Field
9
14
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
12
16
from labelbox .utils import _CamelCaseMixin
13
17
from labelbox .schema .labeling_service_status import LabelingServiceStatus
14
18
28
32
29
33
30
34
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 )
40
58
41
59
client : Any # type Any to avoid circular import from client
42
60
@@ -46,6 +64,14 @@ def __init__(self, **kwargs):
46
64
raise RuntimeError (
47
65
"Please enable experimental in client to use LabelingService" )
48
66
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
+
49
75
class Config (_CamelCaseMixin .Config ):
50
76
...
51
77
@@ -74,7 +100,7 @@ def get(cls, client, project_id: str) -> 'LabelingServiceDashboard':
74
100
}
75
101
}
76
102
"""
77
- result = client .execute (query , {"id" : project_id })
103
+ result = client .execute (query , {"id" : project_id }, experimental = True )
78
104
if result ["getProjectById" ] is None :
79
105
raise ResourceNotFoundError (
80
106
message = "The project does not have a labeling service." )
@@ -87,7 +113,6 @@ def get_all(
87
113
cls ,
88
114
client ,
89
115
after : Optional [str ] = None ,
90
- # where: Optional[Comparison] = None,
91
116
search_query : Optional [List [Dict ]] = None ,
92
117
) -> PaginatedCollection :
93
118
template = Template (
@@ -121,16 +146,12 @@ def convert_to_labeling_service_dashboard(client, data):
121
146
dereferencing = ['searchProjects' , 'nodes' ],
122
147
obj_class = convert_to_labeling_service_dashboard ,
123
148
cursor_path = ['searchProjects' , 'pageInfo' , 'endCursor' ],
149
+ experimental = True ,
124
150
)
125
151
126
152
@root_validator (pre = True )
127
- def convert_graphql_to_attrs (cls , data ):
153
+ def convert_boost_status_to_enum (cls , data ):
128
154
if 'boostStatus' in data :
129
155
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' ])
135
156
136
157
return data
0 commit comments