Skip to content

Commit ebe0f35

Browse files
authored
Vb/make labeling service user friendly (#1775)
1 parent e19673d commit ebe0f35

File tree

6 files changed

+45
-46
lines changed

6 files changed

+45
-46
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@
2525
dataRowsDoneCount
2626
mediaType
2727
editorTaskType
28+
tags
2829
"""
2930

3031

32+
class LabelingServiceDashboardTags(BaseModel):
33+
name: str
34+
color: str
35+
type: str
36+
37+
3138
class LabelingServiceDashboard(BaseModel):
3239
"""
3340
Represent labeling service data for a project
@@ -52,6 +59,7 @@ class LabelingServiceDashboard(BaseModel):
5259
data_rows_done_count: int = Field(frozen=True)
5360
media_type: Optional[MediaType] = Field(frozen=True, default=None)
5461
editor_task_type: EditorTaskType = Field(frozen=True, default=None)
62+
tags: List[LabelingServiceDashboardTags] = Field(frozen=True, default=None)
5563

5664
client: Any # type Any to avoid circular import from client
5765

@@ -121,7 +129,8 @@ def get(cls, client, project_id: str) -> 'LabelingServiceDashboard':
121129
result = client.execute(query, {"id": project_id}, experimental=True)
122130
if result["getProjectById"] is None:
123131
raise ResourceNotFoundError(
124-
message="The project does not have a labeling service.")
132+
message="The project does not have a labeling service data yet."
133+
)
125134
data = result["getProjectById"]
126135
data["client"] = client
127136
return cls(**data)
@@ -190,3 +199,11 @@ def convert_boost_data(cls, data):
190199
data['created_by_id'] = data.pop('boostRequestedBy')
191200

192201
return data
202+
203+
def dict(self, *args, **kwargs):
204+
row = super().dict(*args, **kwargs)
205+
row.pop('client')
206+
row['tasks_completed'] = self.tasks_completed
207+
row['tasks_remaining'] = self.tasks_remaining
208+
row['service_type'] = self.service_type
209+
return row

libs/labelbox/src/labelbox/schema/media_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def matches(value, name):
5454
if matches(value, name):
5555
return member
5656

57+
return cls.Unsupported
58+
5759
@classmethod
5860
def is_supported(cls, value):
5961
return isinstance(value,

libs/labelbox/src/labelbox/schema/search_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OperationType(Enum):
3030
"""
3131
Supported search entity types
3232
"""
33-
Organization = 'organization'
33+
Organization = 'organization_id'
3434
Workspace = 'workspace'
3535
Tag = 'tag'
3636
Stage = 'stage'

libs/labelbox/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,9 @@ def valid_model_id():
10991099

11001100

11011101
@pytest.fixture
1102-
def requested_labeling_service(
1103-
rand_gen, live_chat_evaluation_project_with_new_dataset,
1104-
chat_evaluation_ontology, model_config):
1102+
def requested_labeling_service(rand_gen,
1103+
live_chat_evaluation_project_with_new_dataset,
1104+
chat_evaluation_ontology, model_config):
11051105
project = live_chat_evaluation_project_with_new_dataset
11061106
project.connect_ontology(chat_evaluation_ontology)
11071107

@@ -1113,4 +1113,4 @@ def requested_labeling_service(
11131113

11141114
labeling_service.request()
11151115

1116-
yield project, labeling_service
1116+
yield project, project.get_labeling_service()
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
from datetime import datetime, timedelta
2+
from labelbox.exceptions import ResourceNotFoundError
23
from labelbox.schema.labeling_service import LabelingServiceStatus
34
from labelbox.schema.ontology_kind import EditorTaskType
45
from labelbox.schema.media_type import MediaType
56
from labelbox.schema.search_filters import IntegerValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, TaskCompletedCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkspaceFilter, TaskRemainingCountFilter
67

78

8-
def test_request_labeling_service_dashboard(rand_gen,
9-
offline_chat_evaluation_project,
10-
chat_evaluation_ontology,
11-
offline_conversational_data_row):
12-
project = offline_chat_evaluation_project
13-
project.connect_ontology(chat_evaluation_ontology)
9+
def test_request_labeling_service_dashboard(requested_labeling_service):
10+
project, _ = requested_labeling_service
1411

15-
project.create_batch(
16-
rand_gen(str),
17-
[offline_conversational_data_row.uid], # sample of data row objects
18-
)
1912
labeling_service_dashboard = project.labeling_service_dashboard()
20-
assert labeling_service_dashboard.status == LabelingServiceStatus.Missing
13+
assert labeling_service_dashboard.status == LabelingServiceStatus.Requested
2114
assert labeling_service_dashboard.tasks_completed == 0
2215
assert labeling_service_dashboard.tasks_remaining == 0
2316
assert labeling_service_dashboard.media_type == MediaType.Conversational
24-
assert labeling_service_dashboard.editor_task_type == EditorTaskType.OfflineModelChatEvaluation
25-
assert labeling_service_dashboard.service_type == "Offline chat evaluation"
17+
assert labeling_service_dashboard.editor_task_type == EditorTaskType.ModelChatEvaluation
18+
assert labeling_service_dashboard.service_type == "Live chat evaluation"
2619

27-
labeling_service_dashboard = [
28-
ld for ld in project.client.get_labeling_service_dashboards()
29-
][0]
30-
assert labeling_service_dashboard.status == LabelingServiceStatus.Missing
31-
assert labeling_service_dashboard.tasks_completed == 0
32-
assert labeling_service_dashboard.tasks_remaining == 0
20+
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
21+
).get_one()
22+
assert labeling_service_dashboard
3323

3424

3525
def test_request_labeling_service_dashboard_filters(requested_labeling_service):
@@ -40,10 +30,8 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
4030
operator=IdOperator.Is,
4131
values=[organization.uid])
4232

43-
labeling_service_dashboard = [
44-
ld for ld in project.client.get_labeling_service_dashboards(
45-
search_query=[org_filter])
46-
][0]
33+
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
34+
search_query=[org_filter]).get_one()
4735
assert labeling_service_dashboard is not None
4836

4937
workforce_requested_filter_before = WorkforceRequestedDateFilter(
@@ -57,12 +45,10 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
5745
value=DateValue(operator=RangeOperatorWithSingleValue.LessThanOrEqual,
5846
value=year_from_now))
5947

60-
labeling_service_dashboard = [
61-
ld
62-
for ld in project.client.get_labeling_service_dashboards(search_query=[
48+
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
49+
search_query=[
6350
workforce_requested_filter_after, workforce_requested_filter_before
64-
])
65-
][0]
51+
]).get_one()
6652
assert labeling_service_dashboard is not None
6753

6854
workforce_date_range_filter = WorkforceRequestedDateRangeFilter(
@@ -71,10 +57,8 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
7157
value=DateRange(min="2024-01-01T00:00:00-0800",
7258
max=year_from_now)))
7359

74-
labeling_service_dashboard = [
75-
ld for ld in project.client.get_labeling_service_dashboards(
76-
search_query=[workforce_date_range_filter])
77-
][0]
60+
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
61+
search_query=[workforce_date_range_filter]).get_one()
7862
assert labeling_service_dashboard is not None
7963

8064
# with non existing data
@@ -88,9 +72,6 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
8872
]
8973
assert len(labeling_service_dashboard) == 0
9074
assert labeling_service_dashboard == []
91-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
92-
).get_one()
93-
assert labeling_service_dashboard
9475

9576
task_done_count_filter = TaskCompletedCountFilter(
9677
operation=OperationType.TaskCompletedCount,
@@ -101,8 +82,7 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
10182
value=IntegerValue(
10283
operator=RangeOperatorWithSingleValue.GreaterThanOrEqual, value=0))
10384

104-
labeling_service_dashboard = [
105-
ld for ld in project.client.get_labeling_service_dashboards(
106-
search_query=[task_done_count_filter, task_remaining_count_filter])
107-
][0]
85+
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
86+
search_query=[task_done_count_filter, task_remaining_count_filter
87+
]).get_one()
10888
assert labeling_service_dashboard is not None

libs/labelbox/tests/unit/test_unit_search_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_id_filters():
1515

1616
assert build_search_filter(
1717
filters
18-
) == '[{operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "organization"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "workspace"}, {operator: "is", values: ["tag"], type: "tag"}, {operator: "is", values: ["requested"], type: "stage"}]'
18+
) == '[{operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "organization_id"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "workspace"}, {operator: "is", values: ["tag"], type: "tag"}, {operator: "is", values: ["requested"], type: "stage"}]'
1919

2020

2121
def test_date_filters():

0 commit comments

Comments
 (0)