-
Notifications
You must be signed in to change notification settings - Fork 68
Vb/search projects filters plt 1399 #1771
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Labeling Service Dashboard | ||
=============================================================================================== | ||
|
||
.. automodule:: labelbox.schema.labeling_service_dashboard | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Labeling Service Status | ||
=============================================================================================== | ||
|
||
.. automodule:: labelbox.schema.labeling_service_status | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Search Filters | ||
=============================================================================================== | ||
|
||
.. automodule:: labelbox.schema.search_filters | ||
:members: | ||
:exclude-members: _dict_to_graphql_string | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import datetime | ||
from enum import Enum | ||
from typing import List, Literal, Union | ||
|
||
from labelbox.pydantic_compat import BaseModel | ||
from labelbox.utils import format_iso_datetime | ||
|
||
|
||
class BaseSearchFilter(BaseModel): | ||
""" | ||
Shared code for all search filters | ||
""" | ||
|
||
class Config: | ||
use_enum_values = True | ||
|
||
def dict(self, *args, **kwargs): | ||
res = super().dict(*args, **kwargs) | ||
if 'operation' in res: | ||
res['type'] = res.pop('operation') | ||
|
||
# go through all the keys and convert date to string | ||
for key in res: | ||
if isinstance(res[key], datetime.datetime): | ||
res[key] = format_iso_datetime(res[key]) | ||
return res | ||
|
||
|
||
class OperationType(Enum): | ||
""" | ||
Supported search entity types | ||
""" | ||
Organization = 'organization' | ||
Workspace = 'workspace' | ||
Tag = 'tag' | ||
Stage = 'stage' | ||
WorforceRequestedDate = 'workforce_requested_at' | ||
WorkforceStageUpdatedDate = 'workforce_stage_updated_at' | ||
|
||
|
||
class IdOperator(Enum): | ||
""" | ||
Supported operators for ids | ||
""" | ||
Is = 'is' | ||
|
||
|
||
class DateOperator(Enum): | ||
""" | ||
Supported operators for dates | ||
""" | ||
Equals = 'EQUALS' | ||
GreaterThanOrEqual = 'GREATER_THAN_OR_EQUAL' | ||
LessThanOrEqual = 'LESS_THAN_OR_EQUAL' | ||
|
||
|
||
class DateRangeOperator(Enum): | ||
""" | ||
Supported operators for date ranges | ||
""" | ||
Between = 'BETWEEN' | ||
|
||
|
||
class OrganizationFilter(BaseSearchFilter): | ||
""" | ||
Filter for organization | ||
""" | ||
operation: Literal[OperationType.Organization] | ||
operator: IdOperator | ||
values: List[str] | ||
|
||
|
||
class WorkspaceFilter(BaseSearchFilter): | ||
""" | ||
Filter for workspace | ||
""" | ||
operation: Literal[OperationType.Workspace] | ||
operator: IdOperator | ||
values: List[str] | ||
|
||
|
||
class TagFilter(BaseSearchFilter): | ||
""" | ||
Filter for project tags | ||
""" | ||
operation: Literal[OperationType.Tag] | ||
operator: IdOperator | ||
values: List[str] | ||
|
||
|
||
class ProjectStageFilter(BaseSearchFilter): | ||
""" | ||
Filter labelbox service / aka project stages | ||
""" | ||
operation: Literal[OperationType.Stage] | ||
operator: IdOperator | ||
values: List[str] | ||
|
||
|
||
class DateValue(BaseSearchFilter): | ||
""" | ||
Date value for a search filter | ||
Date formats: | ||
datetime: an existing datetime object | ||
str the following formats are accepted: YYYY-MM-DD[T]HH:MM[:SS[.ffffff]][Z or [±]HH[:]MM] | ||
NOTE | ||
if a date / datetime string is passed without a timezone, we will assume the time is UTC and convert it to a local timezone | ||
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: DateOperator | ||
value: datetime.datetime | ||
|
||
|
||
class WorkforceStageUpdatedFilter(BaseSearchFilter): | ||
""" | ||
Filter for workforce stage updated date | ||
""" | ||
operation: Literal[OperationType.WorkforceStageUpdatedDate] | ||
value: DateValue | ||
|
||
|
||
class WorkforceRequestedDateFilter(BaseSearchFilter): | ||
""" | ||
Filter for workforce requested date | ||
""" | ||
operation: Literal[OperationType.WorforceRequestedDate] | ||
value: DateValue | ||
|
||
|
||
class DateRange(BaseSearchFilter): | ||
""" | ||
Date range for a search filter | ||
""" | ||
min: datetime.datetime | ||
max: datetime.datetime | ||
|
||
|
||
class DateRangeValue(BaseSearchFilter): | ||
""" | ||
Date range value for a search filter | ||
""" | ||
operator: DateRangeOperator | ||
value: DateRange | ||
|
||
|
||
class WorkforceRequestedDateRangeFilter(BaseSearchFilter): | ||
""" | ||
Filter for workforce requested date range | ||
""" | ||
operation: Literal[OperationType.WorforceRequestedDate] | ||
value: DateRangeValue | ||
|
||
|
||
class WorkforceStageUpdatedRangeFilter(BaseSearchFilter): | ||
""" | ||
Filter for workforce stage updated date range | ||
""" | ||
operation: Literal[OperationType.WorkforceStageUpdatedDate] | ||
value: DateRangeValue | ||
|
||
|
||
SearchFilter = Union[OrganizationFilter, WorkspaceFilter, TagFilter, | ||
ProjectStageFilter, WorkforceRequestedDateFilter, | ||
WorkforceStageUpdatedFilter, | ||
WorkforceRequestedDateRangeFilter, | ||
WorkforceStageUpdatedRangeFilter] | ||
|
||
|
||
def _dict_to_graphql_string(d: Union[dict, list, str, int]) -> str: | ||
if isinstance(d, dict): | ||
return "{" + ", ".join( | ||
f'{k}: {_dict_to_graphql_string(v)}' for k, v in d.items()) + "}" | ||
elif isinstance(d, list): | ||
return "[" + ", ".join( | ||
_dict_to_graphql_string(item) for item in d) + "]" | ||
else: | ||
return f'"{d}"' if isinstance(d, str) else str(d) | ||
|
||
|
||
def build_search_filter(filter: List[SearchFilter]): | ||
""" | ||
Converts a list of search filters to a graphql string | ||
""" | ||
filters = [_dict_to_graphql_string(f.dict()) for f in filter] | ||
return "[" + ", ".join(filters) + "]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to surround numbers with quotations too? Maybe doesn't matter currently since I don't think any of the filters currently use one, but if we do we should do that now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the quotations are only if
isinstance(d, str)
. You are right we need to test this code with numbers. Currently we do not have any, but I will do it in a follow up story for a new filter we are creating