Skip to content

Commit 04d6e75

Browse files
authored
Vb/fixes and improvements 3 (#1784)
1 parent 360d78f commit 04d6e75

File tree

4 files changed

+68
-46
lines changed

4 files changed

+68
-46
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
boostUpdatedAt
2020
boostRequestedBy
2121
boostStatus
22-
tasksCompletedCount
23-
tasksPercentCompleted
24-
tasksRemainingCount
25-
tasksTotalCount
22+
dataRowsCount
23+
dataRowsDoneCount
24+
dataRowsInReviewCount
25+
dataRowsInReworkCount
2626
mediaType
2727
editorTaskType
2828
tags
2929
"""
3030

3131

3232
class LabelingServiceDashboardTags(BaseModel):
33+
id: str
3334
text: str
3435
color: str
3536
type: str
@@ -43,9 +44,8 @@ class LabelingServiceDashboard(BaseModel):
4344
id (str): project id
4445
name (str): project name
4546
status (LabelingServiceStatus): status of the labeling service
46-
tasks_completed_count (int): number of data rows completed
47-
tasks_remaining_count (int): number of data rows that have not started
48-
tasks_total_count (int): total number of data rows in the project
47+
data_rows_count (int): total number of data rows in the project
48+
data_rows_done_count (int): number of data rows completed
4949
tags (List[LabelingServiceDashboardTags]): tags associated with the project
5050
media_type (MediaType): media type of the project
5151
editor_task_type (EditorTaskType): editor task type of the project
@@ -57,9 +57,10 @@ class LabelingServiceDashboard(BaseModel):
5757
updated_at: Optional[datetime] = Field(frozen=True, default=None)
5858
created_by_id: Optional[str] = Field(frozen=True, default=None)
5959
status: LabelingServiceStatus = Field(frozen=True, default=None)
60-
tasks_completed_count: int = Field(frozen=True)
61-
tasks_remaining_count: int = Field(frozen=True)
62-
tasks_total_count: int = Field(frozen=True)
60+
data_rows_count: int = Field(frozen=True)
61+
data_rows_done_count: int = Field(frozen=True)
62+
data_rows_in_review_count: int = Field(frozen=True)
63+
data_rows_in_rework_count: int = Field(frozen=True)
6364
media_type: Optional[MediaType] = Field(frozen=True, default=None)
6465
editor_task_type: EditorTaskType = Field(frozen=True, default=None)
6566
tags: List[LabelingServiceDashboardTags] = Field(frozen=True, default=None)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from typing import List, Literal, Union
44

5-
from labelbox.pydantic_compat import BaseModel
5+
from labelbox.pydantic_compat import BaseModel, validator
66
from labelbox.schema.labeling_service_status import LabelingServiceStatus
77
from labelbox.utils import format_iso_datetime
88

@@ -106,6 +106,8 @@ class WorkspaceFilter(BaseSearchFilter):
106106
class TagFilter(BaseSearchFilter):
107107
"""
108108
Filter for project tags
109+
110+
values are tag ids
109111
"""
110112
operation: Literal[OperationType.Tag] = OperationType.Tag
111113
operator: IdOperator
@@ -121,6 +123,16 @@ class ProjectStageFilter(BaseSearchFilter):
121123
operator: IdOperator
122124
values: List[LabelingServiceStatus]
123125

126+
@validator('values', pre=True)
127+
def validate_values(cls, values):
128+
disallowed_values = [LabelingServiceStatus.Missing]
129+
for value in values:
130+
if value in disallowed_values:
131+
raise ValueError(
132+
f"{value} is not a valid value for ProjectStageFilter")
133+
134+
return values
135+
124136

125137
class DateValue(BaseSearchFilter):
126138
"""
Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
from datetime import datetime, timedelta
2-
from time import sleep
3-
from labelbox.schema.labeling_service import LabelingServiceStatus
4-
from labelbox.schema.ontology_kind import EditorTaskType
5-
from labelbox.schema.media_type import MediaType
62
from labelbox.schema.search_filters import IntegerValue, RangeDateTimeOperatorWithSingleValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, TaskCompletedCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkspaceFilter, TaskRemainingCountFilter
73

8-
ALLOW_TIME_TO_CREATE_DASHBOARD = 5 ## seconds
9-
104

115
def test_request_labeling_service_dashboard(requested_labeling_service):
126
project, _ = requested_labeling_service
137

14-
labeling_service_dashboard = project.get_labeling_service_dashboard()
15-
assert labeling_service_dashboard.status == LabelingServiceStatus.Requested
16-
assert labeling_service_dashboard.tasks_completed_count == 0
17-
assert labeling_service_dashboard.tasks_remaining_count == 0
18-
assert labeling_service_dashboard.media_type == MediaType.Conversational
19-
assert labeling_service_dashboard.editor_task_type == EditorTaskType.ModelChatEvaluation
20-
assert labeling_service_dashboard.service_type == "Live chat evaluation"
8+
try:
9+
project.get_labeling_service_dashboard()
10+
except Exception as e:
11+
assert False, f"An exception was raised: {e}"
2112

22-
sleep(ALLOW_TIME_TO_CREATE_DASHBOARD)
23-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
24-
).get_one()
25-
assert labeling_service_dashboard
13+
try:
14+
project.client.get_labeling_service_dashboards().get_one()
15+
except Exception as e:
16+
assert False, f"An exception was raised: {e}"
2617

2718

2819
def test_request_labeling_service_dashboard_filters(requested_labeling_service):
@@ -33,38 +24,42 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
3324
operator=IdOperator.Is,
3425
values=[organization.uid])
3526

36-
sleep(ALLOW_TIME_TO_CREATE_DASHBOARD)
37-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
38-
search_query=[org_filter]).get_one()
39-
assert labeling_service_dashboard is not None
27+
try:
28+
project.client.get_labeling_service_dashboards(
29+
search_query=[org_filter]).get_one()
30+
except Exception as e:
31+
assert False, f"An exception was raised: {e}"
4032

41-
workforce_requested_filter_before = WorkforceRequestedDateFilter(
33+
workforce_requested_filter_after = WorkforceRequestedDateFilter(
4234
operation=OperationType.WorforceRequestedDate,
4335
value=DateValue(
4436
operator=RangeDateTimeOperatorWithSingleValue.GreaterThanOrEqual,
4537
value=datetime.strptime("2024-01-01", "%Y-%m-%d")))
4638
year_from_now = (datetime.now() + timedelta(days=365))
47-
workforce_requested_filter_after = WorkforceRequestedDateFilter(
39+
workforce_requested_filter_before = WorkforceRequestedDateFilter(
4840
operation=OperationType.WorforceRequestedDate,
4941
value=DateValue(
5042
operator=RangeDateTimeOperatorWithSingleValue.LessThanOrEqual,
5143
value=year_from_now))
5244

53-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
54-
search_query=[
45+
try:
46+
project.client.get_labeling_service_dashboards(search_query=[
5547
workforce_requested_filter_after, workforce_requested_filter_before
5648
]).get_one()
57-
assert labeling_service_dashboard is not None
49+
except Exception as e:
50+
assert False, f"An exception was raised: {e}"
5851

5952
workforce_date_range_filter = WorkforceRequestedDateRangeFilter(
6053
operation=OperationType.WorforceRequestedDate,
6154
value=DateRangeValue(operator=RangeOperatorWithValue.Between,
6255
value=DateRange(min="2024-01-01T00:00:00-0800",
6356
max=year_from_now)))
6457

65-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
66-
search_query=[workforce_date_range_filter]).get_one()
67-
assert labeling_service_dashboard is not None
58+
try:
59+
project.client.get_labeling_service_dashboards(
60+
search_query=[workforce_date_range_filter]).get_one()
61+
except Exception as e:
62+
assert False, f"An exception was raised: {e}"
6863

6964
# with non existing data
7065
workspace_id = "clzzu4rme000008l42vnl4kre"
@@ -87,7 +82,9 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
8782
value=IntegerValue(
8883
operator=RangeOperatorWithSingleValue.GreaterThanOrEqual, value=0))
8984

90-
labeling_service_dashboard = project.client.get_labeling_service_dashboards(
91-
search_query=[task_done_count_filter, task_remaining_count_filter
92-
]).get_one()
93-
assert labeling_service_dashboard is not None
85+
try:
86+
project.client.get_labeling_service_dashboards(
87+
search_query=[task_done_count_filter, task_remaining_count_filter
88+
]).get_one()
89+
except Exception as e:
90+
assert False, f"An exception was raised: {e}"

libs/labelbox/tests/unit/test_unit_search_filters.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from labelbox.schema.labeling_service import LabelingServiceStatus
33
from labelbox.schema.search_filters import IntegerValue, RangeDateTimeOperatorWithSingleValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, ProjectStageFilter, SharedWithOrganizationFilter, TagFilter, TaskCompletedCountFilter, TaskRemainingCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkforceStageUpdatedFilter, WorkforceStageUpdatedRangeFilter, WorkspaceFilter, build_search_filter
44
from labelbox.utils import format_iso_datetime
5+
import pytest
56

67

78
def test_id_filters():
@@ -12,14 +13,25 @@ def test_id_filters():
1213
values=["clphb4vd7000cd2wv1ktu5cwa"]),
1314
WorkspaceFilter(operator=IdOperator.Is,
1415
values=["clphb4vd7000cd2wv1ktu5cwa"]),
15-
TagFilter(operator=IdOperator.Is, values=["tag"]),
16+
TagFilter(operator=IdOperator.Is, values=["cls1vkrw401ab072vg2pq3t5d"]),
1617
ProjectStageFilter(operator=IdOperator.Is,
1718
values=[LabelingServiceStatus.Requested]),
1819
]
1920

2021
assert build_search_filter(
2122
filters
22-
) == '[{operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "organization_id"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "shared_with_organizations"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "workspace"}, {operator: "is", values: ["tag"], type: "tag"}, {operator: "is", values: ["REQUESTED"], type: "stage"}]'
23+
) == '[{operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "organization_id"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "shared_with_organizations"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "workspace"}, {operator: "is", values: ["cls1vkrw401ab072vg2pq3t5d"], type: "tag"}, {operator: "is", values: ["REQUESTED"], type: "stage"}]'
24+
25+
26+
def test_stage_filter_with_invalid_values():
27+
with pytest.raises(
28+
ValueError,
29+
match="is not a valid value for ProjectStageFilter") as e:
30+
_ = ProjectStageFilter(operator=IdOperator.Is,
31+
values=[
32+
LabelingServiceStatus.Requested,
33+
LabelingServiceStatus.Missing
34+
]),
2335

2436

2537
def test_date_filters():

0 commit comments

Comments
 (0)