Skip to content

Commit

Permalink
update subscription docs (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiascognite authored Nov 7, 2023
1 parent 0e6ad7a commit 7dd5259
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cognite/client/_api/datapoints_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create(self, subscription: DataPointSubscriptionCreate) -> DatapointSubscrip
>>> from cognite.client.data_classes import DataPointSubscriptionCreate
>>> c = CogniteClient()
>>> sub = DataPointSubscriptionCreate("mySubscription", partition_count=1, time_series_ids=["myFistTimeSeries", "mySecondTimeSeries"], name="My subscription")
>>> created = c.time_series.subscriptions.create()
>>> created = c.time_series.subscriptions.create(sub)
Create a filter defined subscription for all numeric time series:
Expand Down Expand Up @@ -88,7 +88,7 @@ def delete(self, external_id: str | Sequence[str], ignore_unknown_ids: bool = Fa
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> batch = c.time_series.subscriptions.delete("my_subscription")
>>> c.time_series.subscriptions.delete("my_subscription")
"""
self._warning.warn()

Expand All @@ -114,7 +114,7 @@ def retrieve(self, external_id: str, ignore_unknown_ids: bool = False) -> Datapo
>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> batch = c.time_series.subscriptions.retrieve("my_subscription")
>>> res = c.time_series.subscriptions.retrieve("my_subscription")
"""
self._warning.warn()

Expand Down Expand Up @@ -151,6 +151,8 @@ def list_member_time_series(self, external_id: str, limit: int | None = DEFAULT_
>>> members = c.time_series.subscriptions.list_member_time_series("my_subscription")
>>> timeseries_external_ids = members.as_external_ids()
"""
self._warning.warn()

return self._list(
method="GET",
limit=limit,
Expand Down Expand Up @@ -188,7 +190,7 @@ def update(self, update: DataPointSubscriptionUpdate) -> DatapointSubscription:
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import DataPointSubscriptionUpdate
>>> c = CogniteClient()
>>> update = DataPointSubscriptionUpdate("my_subscription").time_series_ids.add("MyNewTimeSeriesExternalId")
>>> update = DataPointSubscriptionUpdate("my_subscription").time_series_ids.add(["MyNewTimeSeriesExternalId"])
>>> updated = c.time_series.subscriptions.update(update)
"""
self._warning.warn()
Expand Down Expand Up @@ -236,14 +238,19 @@ def iterate_data(
>>> for batch in c.time_series.subscriptions.iterate_data("my_subscription"):
... print(f"Added {len(batch.subscription_changes.added)} timeseries")
... print(f"Removed {len(batch.subscription_changes.removed)} timeseries")
... print(f"Changed data in {len(batch.updates)} timeseries")
... print(f"Changed timeseries data in {len(batch.updates)} updates")
... if not batch.has_next:
... break
Iterate over all changes in the subscripted timeseries the last 3 days:
Iterate continuously over all changes to the subscription newer than 3 days:
>>> import time
>>> for batch in c.time_series.subscriptions.iterate_data("my_subscription", "3d-ago"):
... print(f"Added {len(batch.subscription_changes.added)} timeseries")
... print(f"Removed {len(batch.subscription_changes.removed)} timeseries")
... print(f"Changed data in {len(batch.updates)} timeseries")
... print(f"Changed timeseries data in {len(batch.updates)} updates")
... if not batch.has_next:
... time.sleep(1)
"""
self._warning.warn()

Expand Down

0 comments on commit 7dd5259

Please sign in to comment.