|
| 1 | +from labelbox.orm.db_object import DbObject |
| 2 | +from labelbox.orm.model import Field |
| 3 | +from labelbox.pagination import PaginatedCollection |
| 4 | + |
| 5 | + |
| 6 | +class Slice(DbObject): |
| 7 | + """ |
| 8 | + A Slice is a saved set of filters (saved query). |
| 9 | + This is an abstract class and should not be instantiated. |
| 10 | +
|
| 11 | + Attributes: |
| 12 | + name (datetime) |
| 13 | + description (datetime) |
| 14 | + created_at (datetime) |
| 15 | + updated_at (datetime) |
| 16 | + filter (json) |
| 17 | + """ |
| 18 | + name = Field.String("name") |
| 19 | + description = Field.String("description") |
| 20 | + created_at = Field.DateTime("created_at") |
| 21 | + updated_at = Field.DateTime("updated_at") |
| 22 | + filter = Field.Json("filter") |
| 23 | + |
| 24 | + |
| 25 | +class CatalogSlice(Slice): |
| 26 | + """ |
| 27 | + Represents a Slice used for filtering data rows in Catalog. |
| 28 | + """ |
| 29 | + |
| 30 | + def get_data_row_ids(self) -> PaginatedCollection: |
| 31 | + """ |
| 32 | + Fetches all data row ids that match this Slice |
| 33 | +
|
| 34 | + Returns: |
| 35 | + A PaginatedCollection of data row ids |
| 36 | + """ |
| 37 | + query_str = """ |
| 38 | + query getDataRowIdsBySavedQueryPyApi($id: ID!, $from: String, $first: Int!) { |
| 39 | + getDataRowIdsBySavedQuery(input: { |
| 40 | + savedQueryId: $id, |
| 41 | + after: $from |
| 42 | + first: $first |
| 43 | + }) { |
| 44 | + totalCount |
| 45 | + nodes |
| 46 | + pageInfo { |
| 47 | + endCursor |
| 48 | + hasNextPage |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + """ |
| 53 | + return PaginatedCollection( |
| 54 | + client=self.client, |
| 55 | + query=query_str, |
| 56 | + params={'id': self.uid}, |
| 57 | + dereferencing=['getDataRowIdsBySavedQuery', 'nodes'], |
| 58 | + obj_class=lambda _, data_row_id: data_row_id, |
| 59 | + cursor_path=['getDataRowIdsBySavedQuery', 'pageInfo', 'endCursor']) |
0 commit comments