def test_search(self, mock_seq_response): res = SEQ_API.search(filter=SequenceFilter(external_id_prefix="e")) assert mock_seq_response.calls[0].response.json()["items"] == res.dump(camel_case=True) assert { "search": {"name": None, "description": None, "query": None}, "filter": {"externalIdPrefix": "e"}, "limit": None, } == jsgz_load(mock_seq_response.calls[0].request.body)
def __call__( self, chunk_size: int = None, name: str = None, external_id_prefix: str = None, metadata: Dict[str, str] = None, asset_ids: List[int] = None, root_asset_ids: List[int] = None, asset_subtree_ids: List[int] = None, asset_subtree_external_ids: List[str] = None, created_time: Dict[str, Any] = None, last_updated_time: Dict[str, Any] = None, limit: int = None, ) -> Generator[Union[Sequence, SequenceList], None, None]: """Iterate over sequences Fetches sequences as they are iterated over, so you keep a limited number of objects in memory. Args: chunk_size (int, optional): Number of sequences to return in each chunk. Defaults to yielding one event a time. name (str): Filter out sequences that do not have this *exact* name. external_id_prefix (str): Filter out sequences that do not have this string as the start of the externalId metadata (Dict[str, Any]): Filter out sequences that do not match these metadata fields and values (case-sensitive). Format is {"key1":"value1","key2":"value2"}. asset_ids (List[int]): Filter out sequences that are not linked to any of these assets. root_asset_ids (List[int]): Filter out sequences not linked to assets with one of these assets as the root asset. asset_subtree_ids (List[int]): List of asset subtrees ids to filter on. asset_subtree_external_ids (List[str]): List of asset subtrees external ids to filter on. created_time (Union[Dict[str, int], TimestampRange]): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. last_updated_time (Union[Dict[str, int], TimestampRange]): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. limit (int, optional): Max number of sequences to return. Defaults to return all items. Yields: Union[Sequence, SequenceList]: yields Sequence one by one if chunk is not specified, else SequenceList objects. """ if asset_subtree_ids or asset_subtree_external_ids: asset_subtree_ids = self._process_ids(asset_subtree_ids, asset_subtree_external_ids, wrap_ids=True) filter = SequenceFilter( name=name, metadata=metadata, external_id_prefix=external_id_prefix, asset_ids=asset_ids, root_asset_ids=root_asset_ids, asset_subtree_ids=asset_subtree_ids, created_time=created_time, last_updated_time=last_updated_time, ).dump(camel_case=True) return self._list_generator(method="GET", chunk_size=chunk_size, filter=filter, limit=limit)
def test_search_with_filter(self, mock_seq_response): res = SEQ_API.search( name="n", description="d", query="q", filter=SequenceFilter(last_updated_time={"max": 42})) assert mock_seq_response.calls[0].response.json()["items"] == res.dump( camel_case=True) req_body = jsgz_load(mock_seq_response.calls[0].request.body) assert 42 == req_body["filter"]["lastUpdatedTime"]["max"] assert { "name": "n", "description": "d", "query": "q" } == req_body["search"]
def list( self, name: str = None, external_id_prefix: str = None, metadata: Dict[str, str] = None, asset_ids: List[int] = None, root_asset_ids: List[int] = None, asset_subtree_ids: List[int] = None, asset_subtree_external_ids: List[str] = None, data_set_ids: List[int] = None, data_set_external_ids: List[str] = None, created_time: (Union[Dict[str, Any], TimestampRange]) = None, last_updated_time: (Union[Dict[str, Any], TimestampRange]) = None, limit: Optional[int] = 25, ) -> SequenceList: """`Iterate over sequences <https://docs.cognite.com/api/v1/#operation/advancedListSequences>`_ Fetches sequences as they are iterated over, so you keep a limited number of objects in memory. Args: name (str): Filter out sequences that do not have this *exact* name. external_id_prefix (str): Filter out sequences that do not have this string as the start of the externalId metadata (Dict[str, Any]): Filter out sequences that do not match these metadata fields and values (case-sensitive). Format is {"key1":"value1","key2":"value2"}. asset_ids (List[int]): Filter out sequences that are not linked to any of these assets. root_asset_ids (List[int]): Filter out sequences not linked to assets with one of these assets as the root asset. asset_subtree_ids (List[int]): List of asset subtrees ids to filter on. asset_subtree_external_ids (List[str]): List of asset subtrees external ids to filter on. data_set_ids (List[int]): Return only events in the specified data sets with these ids. data_set_external_ids (List[str]): Return only events in the specified data sets with these external ids. created_time (Union[Dict[str, int], TimestampRange]): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. last_updated_time (Union[Dict[str, int], TimestampRange]): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. limit (int, optional): Max number of sequences to return. Defaults to 25. Set to -1, float("inf") or None to return all items. Returns: SequenceList: The requested sequences. Examples: List sequences:: >>> from cognite.client import CogniteClient >>> c = CogniteClient() >>> res = c.sequences.list(limit=5) Iterate over sequences:: >>> from cognite.client import CogniteClient >>> c = CogniteClient() >>> for seq in c.sequences: ... seq # do something with the sequences Iterate over chunks of sequences to reduce memory load:: >>> from cognite.client import CogniteClient >>> c = CogniteClient() >>> for seq_list in c.sequences(chunk_size=2500): ... seq_list # do something with the sequences """ if asset_subtree_ids or asset_subtree_external_ids: asset_subtree_ids = self._process_ids(asset_subtree_ids, asset_subtree_external_ids, wrap_ids=True) if data_set_ids or data_set_external_ids: data_set_ids = self._process_ids(data_set_ids, data_set_external_ids, wrap_ids=True) filter = SequenceFilter( name=name, metadata=metadata, external_id_prefix=external_id_prefix, asset_ids=asset_ids, root_asset_ids=root_asset_ids, asset_subtree_ids=asset_subtree_ids, created_time=created_time, last_updated_time=last_updated_time, data_set_ids=data_set_ids, ).dump(camel_case=True) return self._list(method="POST", filter=filter, limit=limit)
def test_search(self): res = COGNITE_CLIENT.sequences.search( name="42", filter=SequenceFilter(created_time={"min": 0})) assert len(res) > 0
def test_aggregate(self): res = COGNITE_CLIENT.sequences.aggregate(filter=SequenceFilter( name="42")) assert res[0].count > 0
def list( self, name: str = None, external_id_prefix: str = None, metadata: Dict[str, Any] = None, asset_ids: List[int] = None, root_asset_ids: List[int] = None, created_time: Dict[str, Any] = None, last_updated_time: Dict[str, Any] = None, limit: Optional[int] = 25, ) -> SequenceList: """Iterate over sequences Fetches sequences as they are iterated over, so you keep a limited number of objects in memory. Args: name (str): Filter out sequences that do not have this *exact* name. external_id_prefix (str): Filter out sequences that do not have this string as the start of the externalId metadata (Dict[str, Any]): Filter out sequences that do not match these metadata fields and values (case-sensitive). Format is {"key1":"value1","key2":"value2"}. asset_ids (List[int]): Filter out sequences that are not linked to any of these assets. root_asset_ids (List[int]): Filter out sequences not linked to assets with one of these assets as the root asset. created_time (Dict[str, Any]): Filter out sequences with createdTime outside this range. last_updated_time (Dict[str, Any]): Filter out sequences with lastUpdatedTime outside this range. limit (int, optional): Max number of sequences to return. Defaults to 25. Set to -1, float("inf") or None to return all items. Returns: SequenceList: The requested sequences. Examples: List sequences:: >>> from cognite.client.experimental import CogniteClient >>> c = CogniteClient() >>> res = c.sequences.list(limit=5) Iterate over sequences:: >>> from cognite.client.experimental import CogniteClient >>> c = CogniteClient() >>> for seq in c.sequences: ... seq # do something with the sequences Iterate over chunks of sequences to reduce memory load:: >>> from cognite.client.experimental import CogniteClient >>> c = CogniteClient() >>> for seq_list in c.sequences(chunk_size=2500): ... seq_list # do something with the sequences """ filter = SequenceFilter( name=name, metadata=metadata, external_id_prefix=external_id_prefix, asset_ids=asset_ids, root_asset_ids=root_asset_ids, created_time=created_time, last_updated_time=last_updated_time, ).dump(camel_case=True) return self._list(method="POST", filter=filter, limit=limit)