From 2e613eb5b296eef4b9f03d9560e3fceaa97b6c42 Mon Sep 17 00:00:00 2001 From: saraeq Date: Wed, 11 Dec 2024 12:56:20 +0100 Subject: [PATCH] add more usage examples of the sdk Also added some variables to test more easily for us --- examples/client_secret_auth.ipynb | 212 ++++++++++++++++++++++++++---- src/omnia_timeseries/api.py | 3 +- 2 files changed, 187 insertions(+), 28 deletions(-) diff --git a/examples/client_secret_auth.ipynb b/examples/client_secret_auth.ipynb index 6d03542..3ffe873 100644 --- a/examples/client_secret_auth.ipynb +++ b/examples/client_secret_auth.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -49,6 +49,66 @@ "api = TimeseriesAPI(azure_credential=credentials, environment=TimeseriesEnvironment.Test())" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "List of variables for testing" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "timeseries_id1 = \"7a259ea4-dc48-4179-a51e-f892105d1068\"\n", + "timeseries_id2 = \"8c7eb2c2-ca3f-42cd-8812-c8c7b7e178a2\"\n", + "timeseries_id3 = \"52a61a83-e2db-49b4-be41-ef873a5a6192\"\n", + "\n", + "timeseries_name1 = \"13F-PI___011T\"\n", + "timeseries_facility1 = \"SNA\"\n", + "\n", + "startTime1=\"2024-12-09T14:00:00.000Z\"\n", + "endTime1=\"2024-12-09T15:00:01.000Z\"\n", + "\n", + "federationSource_IMS = \"IMS\"\n", + "federationSource_TSDB = \"TSDB\"\n", + "federationSource_DataLake = \"DataLake\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Search Timeseries API by name" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.search_timeseries(name=\"*P9*\",limit=10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Search Timeseries API by description" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.search_timeseries(description=\"*Pressure*\",limit=10)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -62,8 +122,7 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", - "api.get_timeseries(id=timeseries_id)" + "api.get_timeseries_by_id(id=timeseries_id3)" ] }, { @@ -79,8 +138,24 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", - "api.get_history(id=timeseries_id)" + "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", + "api.get_history(id=timeseries_id3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Query Timeseries API for first datapoint, by tag timeseries id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_first_datapoint(id=timeseries_id3)" ] }, { @@ -96,8 +171,8 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", - "api.get_latest_datapoint(id=timeseries_id)" + "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", + "api.get_latest_datapoint(id=timeseries_id3)" ] }, { @@ -113,9 +188,9 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_name = os.environ[\"OMNIA_TIMESERIES_FEDERATION_NAME\"]\n", - "timeseries_facility = os.environ[\"OMNIA_TIMESERIES_FEDERATION_FACILITY\"]\n", - "api.get_datapoints_by_name(timeseries_name, timeseries_facility, startTime=\"2021-03-20T20:00:00.000Z\", endTime=\"2021-03-20T20:00:01.000Z\")" + "timeseries_name = timeseries_name1 #os.environ[\"OMNIA_TIMESERIES_FEDERATION_NAME\"]\n", + "timeseries_facility = timeseries_facility1 #os.environ[\"OMNIA_TIMESERIES_FEDERATION_FACILITY\"]\n", + "api.get_datapoints_by_name(timeseries_name, timeseries_facility, startTime=startTime1, endTime=endTime1)" ] }, { @@ -131,8 +206,8 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", - "api.get_datapoints(id=timeseries_id, startTime=\"2021-03-20T20:00:00.000Z\", endTime=\"2021-03-20T20:00:01.000Z\", federationSource=\"IMS\")" + "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", + "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource_IMS)" ] }, { @@ -148,8 +223,8 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", - "api.get_datapoints(id=timeseries_id, startTime=\"2021-03-20T20:00:00.000Z\", endTime=\"2021-03-20T20:00:01.000Z\", federationSource=\"DataLake\")" + "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", + "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource_DataLake)" ] }, { @@ -165,20 +240,88 @@ "metadata": {}, "outputs": [], "source": [ - "timeseriesId1=\"\"\n", - "timeseriesId2=\"\"\n", "api.get_multi_datapoints([\n", " {\n", - " \"id\": timeseriesId1,\n", - " \"startTime\": \"2022-01-01T00:00:00.000Z\",\n", - " \"endTime\": \"2022-01-01T01:00:00.000Z\",\n", + " \"id\": timeseries_id1,\n", + " \"startTime\": startTime1,\n", + " \"endTime\": endTime1,\n", " \"aggregateFunctions\": [\"avg\"],\n", " \"processingInterval\": \"5m\",\n", " \"fill\": None,\n", " \"statusFilter\": [192]\n", " },\n", " {\n", - " \"id\": timeseriesId2,\n", + " \"id\": timeseries_id2,\n", + " \"startTime\": startTime1,\n", + " \"endTime\": endTime1,\n", + " \"aggregateFunctions\": [\"count\"],\n", + " \"processingInterval\": \"15m\",\n", + " \"fill\": None,\n", + " \"statusFilter\": [192]\n", + " }\n", + "], federationSource=federationSource_IMS)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Query get first multiple datapoint from Timeseries API Aggregates" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_first_multi_datapoint([\n", + " {\n", + " \"id\": timeseries_id1,\n", + " \"startTime\": startTime1,\n", + " \"endTime\": endTime1,\n", + " \"aggregateFunctions\": [\"avg\"],\n", + " \"processingInterval\": \"5m\",\n", + " \"fill\": None,\n", + " \"statusFilter\": [192]\n", + " },\n", + " {\n", + " \"id\": timeseries_id2,\n", + " \"startTime\": \"2024-07-01T00:00:00.000Z\",\n", + " \"endTime\": \"2024-07-01T01:00:00.000Z\",\n", + " \"aggregateFunctions\": [\"count\"],\n", + " \"processingInterval\": \"15m\",\n", + " \"fill\": None,\n", + " \"statusFilter\": [192]\n", + " }\n", + "], federationSource=federationSource_IMS)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Query get latest multiple datapoint from Timeseries API Aggregates" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_latest_multi_datapoint([\n", + " {\n", + " \"id\": timeseries_id1,\n", + " \"startTime\": startTime1,\n", + " \"endTime\": endTime1,\n", + " \"aggregateFunctions\": [\"avg\"],\n", + " \"processingInterval\": \"5m\",\n", + " \"fill\": None,\n", + " \"statusFilter\": [192]\n", + " },\n", + " {\n", + " \"id\": timeseries_id2,\n", " \"startTime\": \"2024-07-01T00:00:00.000Z\",\n", " \"endTime\": \"2024-07-01T01:00:00.000Z\",\n", " \"aggregateFunctions\": [\"count\"],\n", @@ -186,7 +329,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=\"IMS\")" + "], federationSource=federationSource_IMS)" ] }, { @@ -202,16 +345,31 @@ "metadata": {}, "outputs": [], "source": [ - "timeseriesId=\"\"\n", "api.get_aggregates(\n", - " timeseriesId,\n", - " startTime=\"2022-01-01T00:00:00.000Z\",\n", - " endTime=\"2022-01-01T01:00:00.000Z\",\n", + " timeseries_id1,\n", + " startTime=startTime1,\n", + " endTime=endTime1,\n", " processingInterval=\"15m\",\n", " aggregateFunction=[\"avg\"],\n", " fill=None,\n", " status=[192])" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Query get subscriptions API" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_streaming_subscriptions()" + ] } ], "metadata": { @@ -230,7 +388,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.13.1" } }, "nbformat": 4, diff --git a/src/omnia_timeseries/api.py b/src/omnia_timeseries/api.py index ae561b1..5779868 100644 --- a/src/omnia_timeseries/api.py +++ b/src/omnia_timeseries/api.py @@ -313,6 +313,7 @@ def get_history(self, id: str) -> GetHistoryResponseModel: url=f"{self._base_url}/{id}/history", ) +#This endpoint is deprecated, use get_timeseries_by_id def get_timeseries( self, name: Optional[str] = None, @@ -444,7 +445,7 @@ def delete_stream_subscription(self, id: str) -> MessageModel: ) def get_streaming_subscriptions(self) -> StreamSubscriptionDataModel: - """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=getStreamSubscriptions""" + """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetSubscriptions""" return self._http_client.request( request_type='get', url=f"{self._base_url}/streaming/subscriptions"