Skip to content

Commit 718f2c1

Browse files
author
Val Brodsky
committed
Add readdoc files and update docstring(s)
1 parent 8e5548c commit 718f2c1

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

docs/labelbox/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Labelbox Python SDK Documentation
3030
labeling-frontend-options
3131
labeling-parameter-override
3232
labeling-service
33+
labeling-service-dashboard
3334
model
3435
model-config
3536
model-run
@@ -42,6 +43,7 @@ Labelbox Python SDK Documentation
4243
quality-mode
4344
resource-tag
4445
review
46+
search-filters
4547
send-to-annotate-params
4648
slice
4749
task
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Labeling Service
2+
===============================================================================================
3+
4+
.. automodule:: labelbox.schema.search_filters
5+
:members:
6+
:show-inheritance:

docs/labelbox/search-filters.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Labeling Service
2+
===============================================================================================
3+
4+
.. automodule:: labelbox.schema.labeling_service_dashboard
5+
:members:
6+
:exclude-members: _dict_to_graphql_string
7+
:show-inheritance:

libs/labelbox/src/labelbox/client.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from datetime import datetime, timezone
1212
from typing import Any, List, Dict, Union, Optional, overload, Callable
1313

14+
from labelbox.schema.search_filters import SearchFilter
1415
import requests
1516
import requests.exceptions
1617
from google.api_core import retry
@@ -2410,16 +2411,38 @@ def upsert_label_feedback(self, label_id: str, feedback: str,
24102411
def get_labeling_service_dashboards(
24112412
self,
24122413
after: Optional[str] = None,
2413-
search_query: Optional[List[Dict]] = None,
2414+
search_query: Optional[List[SearchFilter]] = None,
24142415
) -> PaginatedCollection:
24152416
"""
24162417
Get all labeling service dashboards for a given org.
24172418
24182419
Optional parameters:
2419-
after: The cursor to use for pagination.
2420-
where: A filter to apply to the query.
2421-
2422-
NOTE: support for after and search_query are not yet implemented.
2420+
search_query: A list of search filters representing the search
2421+
2422+
after: The cursor to use for pagination.
2423+
2424+
NOTE:
2425+
- Retrieves all projects for the organization or as filtered by the search query.
2426+
- Sorted by project created date in ascending order.
2427+
2428+
Examples:
2429+
Retrieves all labeling service dashboards for a given workspace id:
2430+
>>> workspace_filter = WorkspaceFilter(
2431+
>>> operation=OperationType.Workspace,
2432+
>>> operator=IdOperator.Is,
2433+
>>> values=[workspace_id])
2434+
>>> labeling_service_dashboard = [
2435+
>>> ld for ld in project.client.get_labeling_service_dashboards(search_query=[workspace_filter])]
2436+
2437+
Retrieves all labeling service dashboards requested less than 7 days ago:
2438+
>>> seven_days_ago = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
2439+
>>> workforce_requested_filter_before = WorkforceRequestedDateFilter(
2440+
>>> operation=OperationType.WorforceRequestedDate,
2441+
>>> value=DateValue(operator=DateOperator.GreaterThanOrEqual,
2442+
>>> value=seven_days_ago))
2443+
>>> labeling_service_dashboard = [ld for ld in project.client.get_labeling_service_dashboards(search_query=[workforce_requested_filter_before])]
2444+
2445+
See libs/labelbox/src/labelbox/schema/search_filters.py and libs/labelbox/tests/unit/test_unit_search_filters.py for more examples.
24232446
"""
24242447
return LabelingServiceDashboard.get_all(self,
24252448
after,

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
class BaseSearchFilter(BaseModel):
10+
"""
11+
Shared code for all search filters
12+
"""
1013

1114
class Config:
1215
use_enum_values = True
@@ -24,6 +27,9 @@ def dict(self, *args, **kwargs):
2427

2528

2629
class OperationType(Enum):
30+
"""
31+
Supported search entity types
32+
"""
2733
Organization = 'organization'
2834
Workspace = 'workspace'
2935
Tag = 'tag'
@@ -33,74 +39,121 @@ class OperationType(Enum):
3339

3440

3541
class IdOperator(Enum):
42+
"""
43+
Supported operators for ids
44+
"""
3645
Is = 'is'
3746

3847

3948
class DateOperator(Enum):
49+
"""
50+
Supported operators for dates
51+
"""
4052
Equals = 'EQUALS'
4153
GreaterThanOrEqual = 'GREATER_THAN_OR_EQUAL'
4254
LessThanOrEqual = 'LESS_THAN_OR_EQUAL'
4355

4456

4557
class DateRangeOperator(Enum):
58+
"""
59+
Supported operators for date ranges
60+
"""
4661
Between = 'BETWEEN'
4762

4863

4964
class OrganizationFilter(BaseSearchFilter):
65+
"""
66+
Filter for organization
67+
"""
5068
operation: Literal[OperationType.Organization]
5169
operator: IdOperator
5270
values: List[str]
5371

5472

5573
class WorkspaceFilter(BaseSearchFilter):
74+
"""
75+
Filter for workspace
76+
"""
5677
operation: Literal[OperationType.Workspace]
5778
operator: IdOperator
5879
values: List[str]
5980

6081

6182
class TagFilter(BaseSearchFilter):
83+
"""
84+
Filter for project tags
85+
"""
6286
operation: Literal[OperationType.Tag]
6387
operator: IdOperator
6488
values: List[str]
6589

6690

6791
class ProjectStageFilter(BaseSearchFilter):
92+
"""
93+
Filter labelbox service / aka project stages
94+
"""
6895
operation: Literal[OperationType.Stage]
6996
operator: IdOperator
7097
values: List[str]
7198

7299

73100
class DateValue(BaseSearchFilter):
101+
"""
102+
Date value for a search filter
103+
104+
Date formats:
105+
datetime: an existing datetime object
106+
str the following formats are accepted: YYYY-MM-DD[T]HH:MM[:SS[.ffffff]][Z or [±]HH[:]MM]
107+
default timezone is UTC
108+
"""
74109
operator: DateOperator
75110
value: datetime.datetime
76111

77112

78113
class WorkforceStageUpdatedFilter(BaseSearchFilter):
114+
"""
115+
Filter for workforce stage updated date
116+
"""
79117
operation: Literal[OperationType.WorkforceStageUpdatedDate]
80118
value: DateValue
81119

82120

83121
class WorkforceRequestedDateFilter(BaseSearchFilter):
122+
"""
123+
Filter for workforce requested date
124+
"""
84125
operation: Literal[OperationType.WorforceRequestedDate]
85126
value: DateValue
86127

87128

88129
class DateRange(BaseSearchFilter):
130+
"""
131+
Date range for a search filter
132+
"""
89133
min: datetime.datetime
90134
max: datetime.datetime
91135

92136

93137
class DateRangeValue(BaseSearchFilter):
138+
"""
139+
Date range value for a search filter
140+
"""
94141
operator: DateRangeOperator
95142
value: DateRange
96143

97144

98145
class WorkforceRequestedDateRangeFilter(BaseSearchFilter):
146+
"""
147+
Filter for workforce requested date range
148+
"""
99149
operation: Literal[OperationType.WorforceRequestedDate]
100150
value: DateRangeValue
101151

102152

103153
class WorkforceStageUpdatedRangeFilter(BaseSearchFilter):
154+
"""
155+
Filter for workforce stage updated date range
156+
"""
104157
operation: Literal[OperationType.WorkforceStageUpdatedDate]
105158
value: DateRangeValue
106159

@@ -124,5 +177,8 @@ def _dict_to_graphql_string(d: Union[dict, list]) -> str:
124177

125178

126179
def build_search_filter(filter: List[SearchFilter]):
180+
"""
181+
Converts a list of search filters to a graphql string
182+
"""
127183
filters = [_dict_to_graphql_string(f.dict()) for f in filter]
128184
return "[" + ", ".join(filters) + "]"

0 commit comments

Comments
 (0)