1
- from datetime import datetime
2
1
from string import Template
3
- from typing import Any , Dict , List , Optional
2
+ from datetime import datetime
3
+ from typing import Any , Dict , List , Optional , Union
4
4
5
5
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
6
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
12
8
from labelbox .utils import _CamelCaseMixin
13
9
from labelbox .schema .labeling_service_status import LabelingServiceStatus
14
10
28
24
29
25
30
26
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 )
40
50
41
51
client : Any # type Any to avoid circular import from client
42
52
@@ -46,6 +56,14 @@ def __init__(self, **kwargs):
46
56
raise RuntimeError (
47
57
"Please enable experimental in client to use LabelingService" )
48
58
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
+
49
67
class Config (_CamelCaseMixin .Config ):
50
68
...
51
69
@@ -57,24 +75,14 @@ def get(cls, client, project_id: str) -> 'LabelingServiceDashboard':
57
75
Raises:
58
76
ResourceNotFoundError: If the project does not have a labeling service.
59
77
"""
60
- query = """
61
- query GetProjectByIdPyApi($id: ID!) {
62
- getProjectById(input: {id: $id}) {
63
- id
64
- name
65
- # serviceType
66
- # createdAt
67
- # updatedAt
68
- # createdById
69
- boostStatus
70
- dataRowsCount
71
- dataRowsInReviewCount
72
- dataRowsInReworkCount
73
- dataRowsDoneCount
74
- }
75
- }
76
- """
77
- result = client .execute (query , {"id" : project_id })
78
+ query = f"""
79
+ query GetProjectByIdPyApi($id: ID!) {{
80
+ getProjectById(input: {{id: $id}}) {{
81
+ { GRAPHQL_QUERY_SELECTIONS }
82
+ }}
83
+ }}
84
+ """
85
+ result = client .execute (query , {"id" : project_id }, experimental = True )
78
86
if result ["getProjectById" ] is None :
79
87
raise ResourceNotFoundError (
80
88
message = "The project does not have a labeling service." )
@@ -87,7 +95,6 @@ def get_all(
87
95
cls ,
88
96
client ,
89
97
after : Optional [str ] = None ,
90
- # where: Optional[Comparison] = None,
91
98
search_query : Optional [List [Dict ]] = None ,
92
99
) -> PaginatedCollection :
93
100
template = Template (
@@ -106,9 +113,9 @@ def get_all(
106
113
f"[{{type: \" organization\" , operator: \" is\" , values: [\" { organization_id } \" ]}}]"
107
114
)
108
115
109
- params = {
110
- 'from' : after ,
111
- }
116
+ params : Dict [ str , Union [ str , int ]] = {}
117
+ if after :
118
+ params = { "from" : after }
112
119
113
120
def convert_to_labeling_service_dashboard (client , data ):
114
121
data ['client' ] = client
@@ -121,16 +128,12 @@ def convert_to_labeling_service_dashboard(client, data):
121
128
dereferencing = ['searchProjects' , 'nodes' ],
122
129
obj_class = convert_to_labeling_service_dashboard ,
123
130
cursor_path = ['searchProjects' , 'pageInfo' , 'endCursor' ],
131
+ experimental = True ,
124
132
)
125
133
126
134
@root_validator (pre = True )
127
- def convert_graphql_to_attrs (cls , data ):
135
+ def convert_boost_status_to_enum (cls , data ):
128
136
if 'boostStatus' in data :
129
137
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
138
136
139
return data
0 commit comments