Skip to content

[PLT-1440] Vb/labeling dashboard filter updates #1780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/labelbox/src/labelbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,7 @@ def get_labeling_service_dashboards(
>>> seven_days_ago = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
>>> workforce_requested_filter_before = WorkforceRequestedDateFilter(
>>> operation=OperationType.WorforceRequestedDate,
>>> value=DateValue(operator=RangeOperatorWithSingleValue.GreaterThanOrEqual,
>>> value=DateValue(operator=RangeDateTimeOperatorWithSingleValue.GreaterThanOrEqual,
>>> value=seven_days_ago))
>>> labeling_service_dashboard = [ld for ld in project.client.get_labeling_service_dashboards(search_query=[workforce_requested_filter_before])]

Expand Down
39 changes: 13 additions & 26 deletions libs/labelbox/src/labelbox/schema/labeling_service_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
boostUpdatedAt
boostRequestedBy
boostStatus
dataRowsCount
dataRowsInReviewCount
dataRowsInReworkCount
dataRowsDoneCount
tasksCompletedCount
tasksPercentCompleted
tasksRemainingCount
tasksTotalCount
mediaType
editorTaskType
tags
Expand All @@ -43,8 +43,12 @@ class LabelingServiceDashboard(BaseModel):
id (str): project id
name (str): project name
status (LabelingServiceStatus): status of the labeling service
tasks_completed (int): number of data rows completed
tasks_remaining (int): number of data rows that have not started
tasks_completed_count (int): number of data rows completed
tasks_remaining_count (int): number of data rows that have not started
tasks_total_count (int): total number of data rows in the project
tags (List[LabelingServiceDashboardTags]): tags associated with the project
media_type (MediaType): media type of the project
editor_task_type (EditorTaskType): editor task type of the project
client (Any): labelbox client
"""
id: str = Field(frozen=True)
Expand All @@ -53,10 +57,9 @@ class LabelingServiceDashboard(BaseModel):
updated_at: Optional[datetime] = Field(frozen=True, default=None)
created_by_id: Optional[str] = Field(frozen=True, default=None)
status: LabelingServiceStatus = Field(frozen=True, default=None)
data_rows_count: int = Field(frozen=True)
data_rows_in_review_count: int = Field(frozen=True)
data_rows_in_rework_count: int = Field(frozen=True)
data_rows_done_count: int = Field(frozen=True)
tasks_completed_count: int = Field(frozen=True)
tasks_remaining_count: int = Field(frozen=True)
tasks_total_count: int = Field(frozen=True)
media_type: Optional[MediaType] = Field(frozen=True, default=None)
editor_task_type: EditorTaskType = Field(frozen=True, default=None)
tags: List[LabelingServiceDashboardTags] = Field(frozen=True, default=None)
Expand All @@ -69,20 +72,6 @@ def __init__(self, **kwargs):
raise RuntimeError(
"Please enable experimental in client to use LabelingService")

@property
def tasks_completed(self):
"""
Count how many data rows have been completed (i.e. in the Done queue)
"""
return self.data_rows_done_count

@property
def tasks_remaining(self):
"""
Count how many data rows have not been completed
"""
return self.data_rows_count - self.data_rows_done_count

@property
def service_type(self):
"""
Expand Down Expand Up @@ -202,7 +191,5 @@ def convert_boost_data(cls, data):
def dict(self, *args, **kwargs):
row = super().dict(*args, **kwargs)
row.pop('client')
row['tasks_completed'] = self.tasks_completed
row['tasks_remaining'] = self.tasks_remaining
row['service_type'] = self.service_type
return row
10 changes: 9 additions & 1 deletion libs/labelbox/src/labelbox/schema/search_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class RangeOperatorWithSingleValue(Enum):
LessThanOrEqual = 'LESS_THAN_OR_EQUAL'


class RangeDateTimeOperatorWithSingleValue(Enum):
"""
Supported operators for dates
"""
GreaterThanOrEqual = 'GREATER_THAN_OR_EQUAL'
LessThanOrEqual = 'LESS_THAN_OR_EQUAL'


class RangeOperatorWithValue(Enum):
"""
Supported operators for date ranges
Expand Down Expand Up @@ -126,7 +134,7 @@ class DateValue(BaseSearchFilter):
so for a string '2024-01-01' that is run on a computer in PST, we would convert it to '2024-01-01T08:00:00Z'
while the same string in EST will get converted to '2024-01-01T05:00:00Z'
"""
operator: RangeOperatorWithSingleValue
operator: RangeDateTimeOperatorWithSingleValue
value: datetime.datetime


Expand Down
10 changes: 5 additions & 5 deletions libs/labelbox/tests/integration/test_labeling_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime, timedelta
from labelbox.exceptions import ResourceNotFoundError
from labelbox.schema.labeling_service import LabelingServiceStatus
from labelbox.schema.ontology_kind import EditorTaskType
from labelbox.schema.media_type import MediaType
from labelbox.schema.search_filters import IntegerValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, TaskCompletedCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkspaceFilter, TaskRemainingCountFilter
from labelbox.schema.search_filters import IntegerValue, RangeDateTimeOperatorWithSingleValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, TaskCompletedCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkspaceFilter, TaskRemainingCountFilter


def test_request_labeling_service_dashboard(requested_labeling_service):
Expand Down Expand Up @@ -37,13 +36,14 @@ def test_request_labeling_service_dashboard_filters(requested_labeling_service):
workforce_requested_filter_before = WorkforceRequestedDateFilter(
operation=OperationType.WorforceRequestedDate,
value=DateValue(
operator=RangeOperatorWithSingleValue.GreaterThanOrEqual,
operator=RangeDateTimeOperatorWithSingleValue.GreaterThanOrEqual,
value=datetime.strptime("2024-01-01", "%Y-%m-%d")))
year_from_now = (datetime.now() + timedelta(days=365))
workforce_requested_filter_after = WorkforceRequestedDateFilter(
operation=OperationType.WorforceRequestedDate,
value=DateValue(operator=RangeOperatorWithSingleValue.LessThanOrEqual,
value=year_from_now))
value=DateValue(
operator=RangeDateTimeOperatorWithSingleValue.LessThanOrEqual,
value=year_from_now))

labeling_service_dashboard = project.client.get_labeling_service_dashboards(
search_query=[
Expand Down
6 changes: 3 additions & 3 deletions libs/labelbox/tests/unit/test_unit_search_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from labelbox.schema.labeling_service import LabelingServiceStatus
from labelbox.schema.search_filters import IntegerValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, ProjectStageFilter, SharedWithOrganizationFilter, TagFilter, TaskCompletedCountFilter, TaskRemainingCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkforceStageUpdatedFilter, WorkforceStageUpdatedRangeFilter, WorkspaceFilter, build_search_filter
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
from labelbox.utils import format_iso_datetime


Expand Down Expand Up @@ -28,10 +28,10 @@ def test_date_filters():

filters = [
WorkforceRequestedDateFilter(value=DateValue(
operator=RangeOperatorWithSingleValue.GreaterThanOrEqual,
operator=RangeDateTimeOperatorWithSingleValue.GreaterThanOrEqual,
value=local_time_start)),
WorkforceStageUpdatedFilter(value=DateValue(
operator=RangeOperatorWithSingleValue.LessThanOrEqual,
operator=RangeDateTimeOperatorWithSingleValue.LessThanOrEqual,
value=local_time_end)),
]
expected_start = format_iso_datetime(local_time_start)
Expand Down
Loading