Skip to content

Commit a0109d2

Browse files
author
Val Brodsky
committed
Add integration with searchProject
1 parent b8fc7f9 commit a0109d2

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ def upsert_label_feedback(self, label_id: str, feedback: str,
24102410

24112411
def get_labeling_service_dashboards(
24122412
self,
2413-
from_cursor: Optional[str] = None,
2413+
after: Optional[str] = None,
24142414
where: Optional[Comparison] = None,
24152415
) -> PaginatedCollection:
2416-
return LabelingServiceDashboard.get_all(self, from_cursor, where)
2416+
return LabelingServiceDashboard.get_all(self, after, where)

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

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
from datetime import datetime
22
from string import Template
3-
from typing import Any, Optional
3+
from typing import Any, Dict, List, Optional
44

55
from labelbox.exceptions import ResourceNotFoundError
66
from labelbox.orm.comparison import Comparison
7+
from labelbox.orm import query
8+
from ..orm.model import Field
79
from labelbox.pagination import PaginatedCollection
810
from labelbox.pydantic_compat import BaseModel, root_validator
11+
from .organization import Organization
912
from labelbox.utils import _CamelCaseMixin
1013
from labelbox.schema.labeling_service_status import LabelingServiceStatus
1114

15+
GRAPHQL_QUERY_SELECTIONS = """
16+
id
17+
name
18+
# serviceType
19+
# createdAt
20+
# updatedAt
21+
# createdById
22+
boostStatus
23+
dataRowsCount
24+
dataRowsInReviewCount
25+
dataRowsInReworkCount
26+
dataRowsDoneCount
27+
"""
28+
1229

1330
class LabelingServiceDashboard(BaseModel):
1431
id: str
@@ -69,40 +86,41 @@ def get(cls, client, project_id: str) -> 'LabelingServiceDashboard':
6986
def get_all(
7087
cls,
7188
client,
72-
from_cursor: Optional[str] = None,
73-
where: Optional[Comparison] = None,
89+
after: Optional[str] = None,
90+
# where: Optional[Comparison] = None,
91+
search_query: Optional[List[Dict]] = None,
7492
) -> PaginatedCollection:
75-
page_size = 500 # hardcode to avoid overloading the server
76-
# where_param = query.where_as_dict(Entity.DataRow,
77-
# where) if where is not None else None
78-
7993
template = Template(
80-
"""query SearchProjectsPyApi($$id: ID!, $$after: ID, $$first: Int, $$where: SearchProjectsInput) {
81-
searchProjects(id: $$id, after: $$after, first: $$first, where: $$where)
94+
"""query SearchProjectsPyApi($$first: Int, $$from: String) {
95+
searchProjects(input: {after: $$from, searchQuery: $search_query, size: $$first})
8296
{
83-
nodes { $datarow_selections }
84-
pageInfo { hasNextPage startCursor }
97+
nodes { $labeling_dashboard_selections }
98+
pageInfo { endCursor }
8599
}
86100
}
87101
""")
102+
organization_id = client.get_organization().uid
88103
query_str = template.substitute(
89-
datarow_selections=LabelingServiceDashboard.schema()
90-
['properties'].keys())
104+
labeling_dashboard_selections=GRAPHQL_QUERY_SELECTIONS,
105+
search_query=
106+
f"[{{type: \"organization\", operator: \"is\", values: [\"{organization_id}\"]}}]"
107+
)
91108

92109
params = {
93-
'id': self.uid,
94-
'from': from_cursor,
95-
'first': page_size,
96-
'where': where_param,
110+
'from': after,
97111
}
98112

113+
def convert_to_labeling_service_dashboard(client, data):
114+
data['client'] = client
115+
return LabelingServiceDashboard(**data)
116+
99117
return PaginatedCollection(
100118
client=client,
101119
query=query_str,
102120
params=params,
103121
dereferencing=['searchProjects', 'nodes'],
104-
obj_class=LabelingServiceDashboard,
105-
cursor_path=['datasetDataRows', 'pageInfo', 'endCursor'],
122+
obj_class=convert_to_labeling_service_dashboard,
123+
cursor_path=['searchProjects', 'pageInfo', 'endCursor'],
106124
)
107125

108126
@root_validator(pre=True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from labelbox.schema.labeling_service import LabelingServiceStatus
2+
3+
4+
def test_request_labeling_service_moe_offline_project(
5+
rand_gen, offline_chat_evaluation_project, chat_evaluation_ontology,
6+
offline_conversational_data_row):
7+
project = offline_chat_evaluation_project
8+
project.connect_ontology(chat_evaluation_ontology)
9+
10+
project.create_batch(
11+
rand_gen(str),
12+
[offline_conversational_data_row.uid], # sample of data row objects
13+
)
14+
labeling_service_dashboard = project.labeling_service_dashboard()
15+
assert labeling_service_dashboard.status == LabelingServiceStatus.Missing
16+
assert labeling_service_dashboard.tasks_completed == 0
17+
assert labeling_service_dashboard.tasks_remaining == 0
18+
19+
labeling_service_dashboard = [
20+
ld for ld in project.client.get_labeling_service_dashboards()
21+
][0]
22+
assert labeling_service_dashboard.status == LabelingServiceStatus.Missing
23+
assert labeling_service_dashboard.tasks_completed == 0
24+
assert labeling_service_dashboard.tasks_remaining == 0

0 commit comments

Comments
 (0)