From 2e613eb5b296eef4b9f03d9560e3fceaa97b6c42 Mon Sep 17 00:00:00 2001 From: saraeq Date: Wed, 11 Dec 2024 12:56:20 +0100 Subject: [PATCH 01/13] 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" From e55c4607ecf9ccaa18a5c79854080e4c7f7c6577 Mon Sep 17 00:00:00 2001 From: saraeq Date: Thu, 2 Jan 2025 15:11:56 +0100 Subject: [PATCH 02/13] Add update and delete examples --- examples/client_secret_auth.ipynb | 179 +++++++++++++++++++++++++++--- 1 file changed, 164 insertions(+), 15 deletions(-) diff --git a/examples/client_secret_auth.ipynb b/examples/client_secret_auth.ipynb index 3ffe873..ff01b88 100644 --- a/examples/client_secret_auth.ipynb +++ b/examples/client_secret_auth.ipynb @@ -46,7 +46,7 @@ " client_id=os.environ[\"AZURE_CLIENT_ID\"],\n", " client_secret=os.environ['AZURE_CLIENT_SECRET'],\n", " tenant_id=os.environ[\"AZURE_TENANT_ID\"])\n", - "api = TimeseriesAPI(azure_credential=credentials, environment=TimeseriesEnvironment.Test())" + "api = TimeseriesAPI(azure_credential=credentials, environment=TimeseriesEnvironment.Dev())" ] }, { @@ -72,9 +72,7 @@ "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\"" + "federationSource = [\"IMS\", \"TSDB\", \"DataLake\"]" ] }, { @@ -90,7 +88,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.search_timeseries(name=\"*P9*\",limit=10)" + "api.search_timeseries(name=\"*Omnia IIoT write test*\",limit=10)" ] }, { @@ -106,7 +104,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.search_timeseries(description=\"*Pressure*\",limit=10)" + "api.search_timeseries(description=\"*GLV high-frequency amplitude on Simulator*\",limit=10)" ] }, { @@ -122,7 +120,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_timeseries_by_id(id=timeseries_id3)" + "api.get_timeseries_by_id(id=timeseries_id1)" ] }, { @@ -139,7 +137,7 @@ "outputs": [], "source": [ "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", - "api.get_history(id=timeseries_id3)" + "api.get_history(id=timeseries_id1)" ] }, { @@ -155,7 +153,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_first_datapoint(id=timeseries_id3)" + "api.get_first_datapoint(id=timeseries_id1)" ] }, { @@ -172,7 +170,7 @@ "outputs": [], "source": [ "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", - "api.get_latest_datapoint(id=timeseries_id3)" + "api.get_latest_datapoint(id=timeseries_id1)" ] }, { @@ -207,7 +205,7 @@ "outputs": [], "source": [ "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", - "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource_IMS)" + "api.get_datapoints(id=timeseries_id1, startTime=startTime1, endTime=endTime1, federationSource=federationSource[0])" ] }, { @@ -224,7 +222,7 @@ "outputs": [], "source": [ "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", - "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource_DataLake)" + "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource[2])" ] }, { @@ -259,7 +257,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource_IMS)" + "], federationSource=federationSource[0])" ] }, { @@ -294,7 +292,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource_IMS)" + "], federationSource=federationSource[0])" ] }, { @@ -329,7 +327,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource_IMS)" + "], federationSource=federationSource[0])" ] }, { @@ -370,6 +368,157 @@ "source": [ "api.get_streaming_subscriptions()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.post_timeseries(\n", + " {\n", + " \"name\":'Omnia IIoT write test python sdk',\n", + " \"facility\":\"ASGA\" \n", + " }\n", + ")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get/add timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "api.get_or_add_timeseries([\n", + " {\n", + " \"name\":'Omnia IIoT write test python sdk 2',\n", + " \"facility\":\"ASGA\" \n", + " }\n", + "])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Remember to delete the timeseries created after testing" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.delete_timeseries_by_id(id=\"ID_of_created_timeseries_above\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Partial update of a timeseries metadata with given id. Fields not specified are left unchanged." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.patch_timeseries(id=\"Timeseries_ID\", request= \n", + " {\n", + " \"name\":\"New name\",\n", + " \"description\":\"Description of the tag\",\n", + " \"unit\":\"kg\",\n", + " \"step\":True\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Update all fields of a timeseries metadata, all fields on the object will be overwritten." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.put_timeseries(id=\"Timeseries_ID_to_update\", request= \n", + " {\n", + " \"name\":\"New name\",\n", + " \"facility\":\"ASGA\"\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add/update datapoints to a timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.write_data(id=\"Timeseries_ID_to_update\", data=\n", + "{\n", + " \"datapoints\":[{\n", + " \"time\": \"2024-12-09T14:00:00.000Z\",\n", + " \"value\":10.3,\n", + " \"status\":192\n", + "}]\n", + "})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add/update datapoints to multiple timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#this is not working\n", + "api.write_multiple(items=\n", + "[{\n", + " \"id\":\"b6610f13-0081-4d85-a0f0-699ee51bb4ca\",\n", + " \"datapoints\":[{\n", + " \"time\": \"2024-12-10T14:00:00.000Z\",\n", + " \"value\":10.4,\n", + " \"status\":192\n", + " }]\n", + "}])" + ] } ], "metadata": { From 03679335c7e9e1d5835f4db247a40e5a585b847d Mon Sep 17 00:00:00 2001 From: Nina Edvardsdal Date: Mon, 6 Jan 2025 09:11:56 +0100 Subject: [PATCH 03/13] Add facility/source example Added some more examples for fetching facility and/or source --- examples/client_secret_auth.ipynb | 230 +++++++++++++++++++++++++++++- 1 file changed, 224 insertions(+), 6 deletions(-) diff --git a/examples/client_secret_auth.ipynb b/examples/client_secret_auth.ipynb index ff01b88..7224fa4 100644 --- a/examples/client_secret_auth.ipynb +++ b/examples/client_secret_auth.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -84,9 +84,55 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': {'items': [{'id': '1e95b249-5f3f-4b9e-ace1-d6e582897ff0',\n", + " 'name': 'Omnia IIoT write test',\n", + " 'description': 'test patch again 7',\n", + " 'step': False,\n", + " 'unit': None,\n", + " 'standardUnit': None,\n", + " 'assetId': None,\n", + " 'facility': '1190',\n", + " 'externalId': None,\n", + " 'source': 'IMS',\n", + " 'changedTime': '2023-06-29T05:58:52.3600000Z',\n", + " 'createdTime': '2021-04-29T05:12:12.8290000Z'},\n", + " {'id': '96236c02-4ca9-43bc-b8f2-427aa2545811',\n", + " 'name': 'Omnia IIoT write test2',\n", + " 'description': None,\n", + " 'step': False,\n", + " 'unit': None,\n", + " 'standardUnit': None,\n", + " 'assetId': None,\n", + " 'facility': '1131',\n", + " 'externalId': None,\n", + " 'source': 'IMS',\n", + " 'changedTime': '2023-10-05T12:25:26.3650000Z',\n", + " 'createdTime': '2023-10-05T12:25:26.3650000Z'},\n", + " {'id': 'fe8d8cc9-972c-4802-866f-a10e839d2429',\n", + " 'name': 'Omnia IIoT write test2',\n", + " 'description': None,\n", + " 'step': False,\n", + " 'unit': None,\n", + " 'standardUnit': None,\n", + " 'assetId': None,\n", + " 'facility': 'ASGA',\n", + " 'externalId': None,\n", + " 'source': 'IMS',\n", + " 'changedTime': '2023-10-05T08:33:39.0240000Z',\n", + " 'createdTime': '2023-10-05T08:33:39.0240000Z'}]}}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "api.search_timeseries(name=\"*Omnia IIoT write test*\",limit=10)" ] @@ -519,6 +565,178 @@ " }]\n", "}])" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get facilities" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': {'items': [{'facility': 'ASGA', 'count': 25964},\n", + " {'facility': 'JSV', 'count': 25020},\n", + " {'facility': 'SFC', 'count': 25001},\n", + " {'facility': 'SFB', 'count': 25000},\n", + " {'facility': 'GKR', 'count': 24632},\n", + " {'facility': 'SFA', 'count': 17480},\n", + " {'facility': 'AHA', 'count': 16355},\n", + " {'facility': 'KVB', 'count': 14029},\n", + " {'facility': 'VAL', 'count': 10746},\n", + " {'facility': 'MAR', 'count': 8780},\n", + " {'facility': 'TROL', 'count': 1227},\n", + " {'facility': 'SLA', 'count': 364},\n", + " {'facility': 'ASGB', 'count': 330},\n", + " {'facility': 'GRA', 'count': 97},\n", + " {'facility': 'GFC', 'count': 58},\n", + " {'facility': 'JCA', 'count': 50},\n", + " {'facility': 'SNA', 'count': 49},\n", + " {'facility': 'KRIS', 'count': 32},\n", + " {'facility': 'TROB', 'count': 31},\n", + " {'facility': 'VIS', 'count': 26},\n", + " {'facility': 'NOR', 'count': 18},\n", + " {'facility': 'TROC', 'count': 17},\n", + " {'facility': 'DRA', 'count': 11},\n", + " {'facility': 'NJA', 'count': 11},\n", + " {'facility': 'SNB', 'count': 10},\n", + " {'facility': 'GFA', 'count': 9},\n", + " {'facility': 'GDR', 'count': 6},\n", + " {'facility': 'KAA', 'count': 6},\n", + " {'facility': 'HD', 'count': 5},\n", + " {'facility': 'TROA', 'count': 5},\n", + " {'facility': 'OSA', 'count': 4},\n", + " {'facility': 'OSC', 'count': 3},\n", + " {'facility': 'PERA', 'count': 3},\n", + " {'facility': 'PERB', 'count': 3},\n", + " {'facility': 'DOW', 'count': 2},\n", + " {'facility': 'MON', 'count': 2},\n", + " {'facility': 'OSE', 'count': 2},\n", + " {'facility': 'BAC', 'count': 1},\n", + " {'facility': 'GFB', 'count': 1},\n", + " {'facility': 'KLAB', 'count': 1},\n", + " {'facility': 'MLA', 'count': 1},\n", + " {'facility': 'OSS', 'count': 1},\n", + " {'facility': 'SNO', 'count': 1},\n", + " {'facility': 'VFR', 'count': 1}]}}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#TEST\n", + "api.get_facilities()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get sources" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': {'items': [{'source': 'IMS', 'count': 195160},\n", + " {'source': 'FUGRO', 'count': 222},\n", + " {'source': 'IOC', 'count': 7},\n", + " {'source': 'INTEGRATIONTESTREADWRITE', 'count': 4},\n", + " {'source': 'NES', 'count': 1},\n", + " {'source': 'PENNTEST', 'count': 1}]}}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#TEST\n", + "api.get_sources()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get facilities by source" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': {'items': [{'facility': 'ASGA', 'count': 25961},\n", + " {'facility': 'JSV', 'count': 25020},\n", + " {'facility': 'SFC', 'count': 25001},\n", + " {'facility': 'SFB', 'count': 25000},\n", + " {'facility': 'GKR', 'count': 24632},\n", + " {'facility': 'SFA', 'count': 17459},\n", + " {'facility': 'AHA', 'count': 16355},\n", + " {'facility': 'KVB', 'count': 14029},\n", + " {'facility': 'VAL', 'count': 10746},\n", + " {'facility': 'MAR', 'count': 8780},\n", + " {'facility': 'TROL', 'count': 1225},\n", + " {'facility': 'SLA', 'count': 364},\n", + " {'facility': 'ASGB', 'count': 325},\n", + " {'facility': 'GRA', 'count': 93},\n", + " {'facility': 'JCA', 'count': 50},\n", + " {'facility': 'SNA', 'count': 27},\n", + " {'facility': 'NJA', 'count': 11},\n", + " {'facility': 'SNB', 'count': 10},\n", + " {'facility': 'GFA', 'count': 9},\n", + " {'facility': 'KRIS', 'count': 7},\n", + " {'facility': 'GDR', 'count': 6},\n", + " {'facility': 'KAA', 'count': 6},\n", + " {'facility': 'HD', 'count': 5},\n", + " {'facility': 'VIS', 'count': 5},\n", + " {'facility': 'OSA', 'count': 4},\n", + " {'facility': 'TROA', 'count': 4},\n", + " {'facility': 'GFC', 'count': 3},\n", + " {'facility': 'OSC', 'count': 3},\n", + " {'facility': 'PERA', 'count': 3},\n", + " {'facility': 'PERB', 'count': 3},\n", + " {'facility': 'MON', 'count': 2},\n", + " {'facility': 'NOR', 'count': 2},\n", + " {'facility': 'OSE', 'count': 2},\n", + " {'facility': 'BAC', 'count': 1},\n", + " {'facility': 'DOW', 'count': 1},\n", + " {'facility': 'GFB', 'count': 1},\n", + " {'facility': 'KLAB', 'count': 1},\n", + " {'facility': 'MLA', 'count': 1},\n", + " {'facility': 'OSS', 'count': 1},\n", + " {'facility': 'SNO', 'count': 1},\n", + " {'facility': 'VFR', 'count': 1}]}}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#TEST\n", + "api.get_facilities_by_source(source=federationSource[0])" + ] } ], "metadata": { From d8640e9fd2c289ade2cc1b9e774679973107dc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Mon, 6 Jan 2025 10:56:29 +0100 Subject: [PATCH 04/13] Add get_sources_by_facility --- examples/client_secret_auth.ipynb | 282 +++++++----------------------- 1 file changed, 67 insertions(+), 215 deletions(-) diff --git a/examples/client_secret_auth.ipynb b/examples/client_secret_auth.ipynb index 7224fa4..e302715 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": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +67,7 @@ "timeseries_id3 = \"52a61a83-e2db-49b4-be41-ef873a5a6192\"\n", "\n", "timeseries_name1 = \"13F-PI___011T\"\n", - "timeseries_facility1 = \"SNA\"\n", + "facility = \"SNA\"\n", "\n", "startTime1=\"2024-12-09T14:00:00.000Z\"\n", "endTime1=\"2024-12-09T15:00:01.000Z\"\n", @@ -84,55 +84,9 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'data': {'items': [{'id': '1e95b249-5f3f-4b9e-ace1-d6e582897ff0',\n", - " 'name': 'Omnia IIoT write test',\n", - " 'description': 'test patch again 7',\n", - " 'step': False,\n", - " 'unit': None,\n", - " 'standardUnit': None,\n", - " 'assetId': None,\n", - " 'facility': '1190',\n", - " 'externalId': None,\n", - " 'source': 'IMS',\n", - " 'changedTime': '2023-06-29T05:58:52.3600000Z',\n", - " 'createdTime': '2021-04-29T05:12:12.8290000Z'},\n", - " {'id': '96236c02-4ca9-43bc-b8f2-427aa2545811',\n", - " 'name': 'Omnia IIoT write test2',\n", - " 'description': None,\n", - " 'step': False,\n", - " 'unit': None,\n", - " 'standardUnit': None,\n", - " 'assetId': None,\n", - " 'facility': '1131',\n", - " 'externalId': None,\n", - " 'source': 'IMS',\n", - " 'changedTime': '2023-10-05T12:25:26.3650000Z',\n", - " 'createdTime': '2023-10-05T12:25:26.3650000Z'},\n", - " {'id': 'fe8d8cc9-972c-4802-866f-a10e839d2429',\n", - " 'name': 'Omnia IIoT write test2',\n", - " 'description': None,\n", - " 'step': False,\n", - " 'unit': None,\n", - " 'standardUnit': None,\n", - " 'assetId': None,\n", - " 'facility': 'ASGA',\n", - " 'externalId': None,\n", - " 'source': 'IMS',\n", - " 'changedTime': '2023-10-05T08:33:39.0240000Z',\n", - " 'createdTime': '2023-10-05T08:33:39.0240000Z'}]}}" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "api.search_timeseries(name=\"*Omnia IIoT write test*\",limit=10)" ] @@ -182,7 +136,6 @@ "metadata": {}, "outputs": [], "source": [ - "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", "api.get_history(id=timeseries_id1)" ] }, @@ -215,7 +168,6 @@ "metadata": {}, "outputs": [], "source": [ - "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_ID\"]\n", "api.get_latest_datapoint(id=timeseries_id1)" ] }, @@ -232,9 +184,7 @@ "metadata": {}, "outputs": [], "source": [ - "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)" + "api.get_datapoints_by_name(timeseries_name1, facility, startTime=startTime1, endTime=endTime1)" ] }, { @@ -250,7 +200,6 @@ "metadata": {}, "outputs": [], "source": [ - "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", "api.get_datapoints(id=timeseries_id1, startTime=startTime1, endTime=endTime1, federationSource=federationSource[0])" ] }, @@ -267,7 +216,6 @@ "metadata": {}, "outputs": [], "source": [ - "#timeseries_id = os.environ[\"OMNIA_TIMESERIES_FEDERATION_ID\"]\n", "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource[2])" ] }, @@ -431,7 +379,7 @@ "api.post_timeseries(\n", " {\n", " \"name\":'Omnia IIoT write test python sdk',\n", - " \"facility\":\"ASGA\" \n", + " \"facility\":facility \n", " }\n", ")\n" ] @@ -452,8 +400,8 @@ "\n", "api.get_or_add_timeseries([\n", " {\n", - " \"name\":'Omnia IIoT write test python sdk 2',\n", - " \"facility\":\"ASGA\" \n", + " \"name\":'Omnia IIoT write test python sdk 3',\n", + " \"facility\":facility \n", " }\n", "])" ] @@ -487,7 +435,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.patch_timeseries(id=\"Timeseries_ID\", request= \n", + "api.patch_timeseries(id=\"Timeseries_ID_to_update\", request= \n", " {\n", " \"name\":\"New name\",\n", " \"description\":\"Description of the tag\",\n", @@ -513,7 +461,7 @@ "api.put_timeseries(id=\"Timeseries_ID_to_update\", request= \n", " {\n", " \"name\":\"New name\",\n", - " \"facility\":\"ASGA\"\n", + " \"facility\":facility\n", " }\n", ")" ] @@ -533,11 +481,19 @@ "source": [ "api.write_data(id=\"Timeseries_ID_to_update\", data=\n", "{\n", - " \"datapoints\":[{\n", - " \"time\": \"2024-12-09T14:00:00.000Z\",\n", - " \"value\":10.3,\n", - " \"status\":192\n", - "}]\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-02T14:00:00.000Z\",\n", + " \"value\":10.3,\n", + " \"status\":192\n", + " },\n", + " {\n", + " \"time\": \"2024-12-03T14:00:00.000Z\",\n", + " \"value\":10.4,\n", + " \"status\":192\n", + " }\n", + " ]\n", "})" ] }, @@ -555,15 +511,19 @@ "outputs": [], "source": [ "#this is not working\n", - "api.write_multiple(items=\n", - "[{\n", - " \"id\":\"b6610f13-0081-4d85-a0f0-699ee51bb4ca\",\n", - " \"datapoints\":[{\n", - " \"time\": \"2024-12-10T14:00:00.000Z\",\n", - " \"value\":10.4,\n", - " \"status\":192\n", - " }]\n", - "}])" + "api.write_multiple(items=[\n", + " {\n", + " \"id\":\"Timeseries_ID_to_update\",\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-10T14:00:00.000Z\",\n", + " \"value\":10.4,\n", + " \"status\":192\n", + " }\n", + " ]\n", + " }\n", + "])" ] }, { @@ -575,65 +535,10 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'data': {'items': [{'facility': 'ASGA', 'count': 25964},\n", - " {'facility': 'JSV', 'count': 25020},\n", - " {'facility': 'SFC', 'count': 25001},\n", - " {'facility': 'SFB', 'count': 25000},\n", - " {'facility': 'GKR', 'count': 24632},\n", - " {'facility': 'SFA', 'count': 17480},\n", - " {'facility': 'AHA', 'count': 16355},\n", - " {'facility': 'KVB', 'count': 14029},\n", - " {'facility': 'VAL', 'count': 10746},\n", - " {'facility': 'MAR', 'count': 8780},\n", - " {'facility': 'TROL', 'count': 1227},\n", - " {'facility': 'SLA', 'count': 364},\n", - " {'facility': 'ASGB', 'count': 330},\n", - " {'facility': 'GRA', 'count': 97},\n", - " {'facility': 'GFC', 'count': 58},\n", - " {'facility': 'JCA', 'count': 50},\n", - " {'facility': 'SNA', 'count': 49},\n", - " {'facility': 'KRIS', 'count': 32},\n", - " {'facility': 'TROB', 'count': 31},\n", - " {'facility': 'VIS', 'count': 26},\n", - " {'facility': 'NOR', 'count': 18},\n", - " {'facility': 'TROC', 'count': 17},\n", - " {'facility': 'DRA', 'count': 11},\n", - " {'facility': 'NJA', 'count': 11},\n", - " {'facility': 'SNB', 'count': 10},\n", - " {'facility': 'GFA', 'count': 9},\n", - " {'facility': 'GDR', 'count': 6},\n", - " {'facility': 'KAA', 'count': 6},\n", - " {'facility': 'HD', 'count': 5},\n", - " {'facility': 'TROA', 'count': 5},\n", - " {'facility': 'OSA', 'count': 4},\n", - " {'facility': 'OSC', 'count': 3},\n", - " {'facility': 'PERA', 'count': 3},\n", - " {'facility': 'PERB', 'count': 3},\n", - " {'facility': 'DOW', 'count': 2},\n", - " {'facility': 'MON', 'count': 2},\n", - " {'facility': 'OSE', 'count': 2},\n", - " {'facility': 'BAC', 'count': 1},\n", - " {'facility': 'GFB', 'count': 1},\n", - " {'facility': 'KLAB', 'count': 1},\n", - " {'facility': 'MLA', 'count': 1},\n", - " {'facility': 'OSS', 'count': 1},\n", - " {'facility': 'SNO', 'count': 1},\n", - " {'facility': 'VFR', 'count': 1}]}}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#TEST\n", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "api.get_facilities()" ] }, @@ -646,27 +551,10 @@ }, { "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'data': {'items': [{'source': 'IMS', 'count': 195160},\n", - " {'source': 'FUGRO', 'count': 222},\n", - " {'source': 'IOC', 'count': 7},\n", - " {'source': 'INTEGRATIONTESTREADWRITE', 'count': 4},\n", - " {'source': 'NES', 'count': 1},\n", - " {'source': 'PENNTEST', 'count': 1}]}}" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#TEST\n", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "api.get_sources()" ] }, @@ -679,64 +567,28 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'data': {'items': [{'facility': 'ASGA', 'count': 25961},\n", - " {'facility': 'JSV', 'count': 25020},\n", - " {'facility': 'SFC', 'count': 25001},\n", - " {'facility': 'SFB', 'count': 25000},\n", - " {'facility': 'GKR', 'count': 24632},\n", - " {'facility': 'SFA', 'count': 17459},\n", - " {'facility': 'AHA', 'count': 16355},\n", - " {'facility': 'KVB', 'count': 14029},\n", - " {'facility': 'VAL', 'count': 10746},\n", - " {'facility': 'MAR', 'count': 8780},\n", - " {'facility': 'TROL', 'count': 1225},\n", - " {'facility': 'SLA', 'count': 364},\n", - " {'facility': 'ASGB', 'count': 325},\n", - " {'facility': 'GRA', 'count': 93},\n", - " {'facility': 'JCA', 'count': 50},\n", - " {'facility': 'SNA', 'count': 27},\n", - " {'facility': 'NJA', 'count': 11},\n", - " {'facility': 'SNB', 'count': 10},\n", - " {'facility': 'GFA', 'count': 9},\n", - " {'facility': 'KRIS', 'count': 7},\n", - " {'facility': 'GDR', 'count': 6},\n", - " {'facility': 'KAA', 'count': 6},\n", - " {'facility': 'HD', 'count': 5},\n", - " {'facility': 'VIS', 'count': 5},\n", - " {'facility': 'OSA', 'count': 4},\n", - " {'facility': 'TROA', 'count': 4},\n", - " {'facility': 'GFC', 'count': 3},\n", - " {'facility': 'OSC', 'count': 3},\n", - " {'facility': 'PERA', 'count': 3},\n", - " {'facility': 'PERB', 'count': 3},\n", - " {'facility': 'MON', 'count': 2},\n", - " {'facility': 'NOR', 'count': 2},\n", - " {'facility': 'OSE', 'count': 2},\n", - " {'facility': 'BAC', 'count': 1},\n", - " {'facility': 'DOW', 'count': 1},\n", - " {'facility': 'GFB', 'count': 1},\n", - " {'facility': 'KLAB', 'count': 1},\n", - " {'facility': 'MLA', 'count': 1},\n", - " {'facility': 'OSS', 'count': 1},\n", - " {'facility': 'SNO', 'count': 1},\n", - " {'facility': 'VFR', 'count': 1}]}}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#TEST\n", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "api.get_facilities_by_source(source=federationSource[0])" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get source by facility" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_sources_by_facility(facility=facility)" + ] } ], "metadata": { From 87ee7a84e7c95b64174175f44af763034e2f25d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Mon, 6 Jan 2025 12:53:29 +0100 Subject: [PATCH 05/13] Add subscription examples Also fix some structure, have removed id's and solved write_multiple issue --- examples/client_secret_auth.ipynb | 223 +++++++++++++++++++----------- 1 file changed, 144 insertions(+), 79 deletions(-) diff --git a/examples/client_secret_auth.ipynb b/examples/client_secret_auth.ipynb index e302715..f0aadf2 100644 --- a/examples/client_secret_auth.ipynb +++ b/examples/client_secret_auth.ipynb @@ -62,11 +62,10 @@ "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", + "timeseries_id1 = \"Timeseries_ID\"\n", + "timeseries_id2 = \"Timeseries_ID2\"\n", "\n", - "timeseries_name1 = \"13F-PI___011T\"\n", + "timeseries_name1 = \"Name_of_timeseries_id1\"\n", "facility = \"SNA\"\n", "\n", "startTime1=\"2024-12-09T14:00:00.000Z\"\n", @@ -88,7 +87,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.search_timeseries(name=\"*Omnia IIoT write test*\",limit=10)" + "api.search_timeseries(name=\"*Omnia timeseries test*\",limit=10)" ] }, { @@ -104,7 +103,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.search_timeseries(description=\"*GLV high-frequency amplitude on Simulator*\",limit=10)" + "api.search_timeseries(description=\"*Description of a tag*\",limit=10)" ] }, { @@ -216,7 +215,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id3, startTime=startTime1, endTime=endTime1, federationSource=federationSource[2])" + "api.get_datapoints(id=timeseries_id2, startTime=startTime1, endTime=endTime1, federationSource=federationSource[2])" ] }, { @@ -351,7 +350,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Query get subscriptions API" + "Get facilities" ] }, { @@ -360,14 +359,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_streaming_subscriptions()" + "api.get_facilities()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Add timeseries" + "Get sources" ] }, { @@ -376,19 +375,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.post_timeseries(\n", - " {\n", - " \"name\":'Omnia IIoT write test python sdk',\n", - " \"facility\":facility \n", - " }\n", - ")\n" + "api.get_sources()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Get/add timeseries" + "Get facilities by source" ] }, { @@ -397,20 +391,14 @@ "metadata": {}, "outputs": [], "source": [ - "\n", - "api.get_or_add_timeseries([\n", - " {\n", - " \"name\":'Omnia IIoT write test python sdk 3',\n", - " \"facility\":facility \n", - " }\n", - "])" + "api.get_facilities_by_source(source=federationSource[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Remember to delete the timeseries created after testing" + "Get source by facility" ] }, { @@ -419,14 +407,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.delete_timeseries_by_id(id=\"ID_of_created_timeseries_above\")" + "api.get_sources_by_facility(facility=facility)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Partial update of a timeseries metadata with given id. Fields not specified are left unchanged." + "Query get subscriptions API" ] }, { @@ -435,21 +423,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.patch_timeseries(id=\"Timeseries_ID_to_update\", request= \n", - " {\n", - " \"name\":\"New name\",\n", - " \"description\":\"Description of the tag\",\n", - " \"unit\":\"kg\",\n", - " \"step\":True\n", - " }\n", - ")" + "api.get_streaming_subscriptions()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Update all fields of a timeseries metadata, all fields on the object will be overwritten." + "Create subscription" ] }, { @@ -458,19 +439,20 @@ "metadata": {}, "outputs": [], "source": [ - "api.put_timeseries(id=\"Timeseries_ID_to_update\", request= \n", - " {\n", - " \"name\":\"New name\",\n", - " \"facility\":facility\n", - " }\n", - ")" + "api.create_stream_subscription(\n", + " subscriptions=\n", + " [\n", + " {\n", + " \"id\":timeseries_id1\n", + " }\n", + "])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Add/update datapoints to a timeseries" + "Delete subscription" ] }, { @@ -479,29 +461,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.write_data(id=\"Timeseries_ID_to_update\", data=\n", - "{\n", - " \"datapoints\":\n", - " [\n", - " {\n", - " \"time\": \"2024-12-02T14:00:00.000Z\",\n", - " \"value\":10.3,\n", - " \"status\":192\n", - " },\n", - " {\n", - " \"time\": \"2024-12-03T14:00:00.000Z\",\n", - " \"value\":10.4,\n", - " \"status\":192\n", - " }\n", - " ]\n", - "})" + "api.delete_stream_subscription(id=timeseries_id1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Add/update datapoints to multiple timeseries" + "Set stream destination to Azure Event Hub" ] }, { @@ -510,18 +477,48 @@ "metadata": {}, "outputs": [], "source": [ - "#this is not working\n", - "api.write_multiple(items=[\n", + "api.set_stream_destination(connectionString=\"Your_connection_String\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.post_timeseries(\n", " {\n", - " \"id\":\"Timeseries_ID_to_update\",\n", - " \"datapoints\":\n", - " [\n", - " {\n", - " \"time\": \"2024-12-10T14:00:00.000Z\",\n", - " \"value\":10.4,\n", - " \"status\":192\n", - " }\n", - " ]\n", + " \"name\":\"Name of the timeseries you add\",\n", + " \"facility\":facility \n", + " }\n", + ")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get/add timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "api.get_or_add_timeseries([\n", + " {\n", + " \"name\":\"Name of the timeseries you add\",\n", + " \"facility\":facility \n", " }\n", "])" ] @@ -530,7 +527,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get facilities" + "Remember to delete the timeseries created after testing" ] }, { @@ -539,14 +536,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_facilities()" + "api.delete_timeseries_by_id(id=\"ID_of_created_timeseries_above\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Get sources" + "Partial update of a timeseries metadata with given id. Fields not specified are left unchanged." ] }, { @@ -555,14 +552,23 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_sources()" + "api.patch_timeseries(\n", + " id=\"Timeseries_ID_to_update\",\n", + " request= \n", + " {\n", + " \"name\":\"New name\",\n", + " \"description\":\"Description of the tag\",\n", + " \"unit\":\"kg\",\n", + " \"step\":True\n", + " }\n", + ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Get facilities by source" + "Update all fields of a timeseries metadata, all fields on the object will be overwritten." ] }, { @@ -571,14 +577,21 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_facilities_by_source(source=federationSource[0])" + "api.put_timeseries(\n", + " id=\"Timeseries_ID_to_update\",\n", + " request= \n", + " {\n", + " \"name\":\"New name\",\n", + " \"facility\":facility\n", + " }\n", + ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Get source by facility" + "Add/update datapoints to a timeseries" ] }, { @@ -587,7 +600,59 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_sources_by_facility(facility=facility)" + "api.write_data(\n", + " id=\"Timeseries_ID_to_update\",\n", + " data=\n", + " {\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-02T14:00:00.000Z\",\n", + " \"value\":10.3,\n", + " \"status\":192\n", + " },\n", + " {\n", + " \"time\": \"2024-12-03T14:00:00.000Z\",\n", + " \"value\":10.4,\n", + " \"status\":192\n", + " }\n", + " ]\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add/update datapoints to multiple timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.write_multiple(\n", + " items=\n", + " {\n", + " \"items\":\n", + " [\n", + " {\n", + " \"id\":\"Timeseries_ID_to_update\",\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-10T14:00:00.000Z\",\n", + " \"value\": 10.4,\n", + " \"status\": 192\n", + " }\n", + " ]\n", + " }\n", + " ]\n", + " }\n", + ")" ] } ], From d9a5bb2f9ccbd2f5a22b6406e028125b1f2f7e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Mon, 6 Jan 2025 12:54:53 +0100 Subject: [PATCH 06/13] Change filename --- examples/{client_secret_auth.ipynb => usage_examples.ipynb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{client_secret_auth.ipynb => usage_examples.ipynb} (100%) diff --git a/examples/client_secret_auth.ipynb b/examples/usage_examples.ipynb similarity index 100% rename from examples/client_secret_auth.ipynb rename to examples/usage_examples.ipynb From ae4dc2e356e16bc88755c0f5916ead43fc25e6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Mon, 6 Jan 2025 13:03:00 +0100 Subject: [PATCH 07/13] Change name of variables --- examples/usage_examples.ipynb | 108 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index f0aadf2..b61c102 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -68,8 +68,8 @@ "timeseries_name1 = \"Name_of_timeseries_id1\"\n", "facility = \"SNA\"\n", "\n", - "startTime1=\"2024-12-09T14:00:00.000Z\"\n", - "endTime1=\"2024-12-09T15:00:01.000Z\"\n", + "startTime=\"2024-12-09T14:00:00.000Z\"\n", + "endTime=\"2024-12-09T15:00:01.000Z\"\n", "\n", "federationSource = [\"IMS\", \"TSDB\", \"DataLake\"]" ] @@ -183,7 +183,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints_by_name(timeseries_name1, facility, startTime=startTime1, endTime=endTime1)" + "api.get_datapoints_by_name(timeseries_name1, facility, startTime=startTime, endTime=endTime)" ] }, { @@ -199,7 +199,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id1, startTime=startTime1, endTime=endTime1, federationSource=federationSource[0])" + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=federationSource[0])" ] }, { @@ -215,7 +215,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id2, startTime=startTime1, endTime=endTime1, federationSource=federationSource[2])" + "api.get_datapoints(id=timeseries_id2, startTime=startTime, endTime=endTime, federationSource=federationSource[2])" ] }, { @@ -234,8 +234,8 @@ "api.get_multi_datapoints([\n", " {\n", " \"id\": timeseries_id1,\n", - " \"startTime\": startTime1,\n", - " \"endTime\": endTime1,\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"avg\"],\n", " \"processingInterval\": \"5m\",\n", " \"fill\": None,\n", @@ -243,8 +243,8 @@ " },\n", " {\n", " \"id\": timeseries_id2,\n", - " \"startTime\": startTime1,\n", - " \"endTime\": endTime1,\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"count\"],\n", " \"processingInterval\": \"15m\",\n", " \"fill\": None,\n", @@ -269,8 +269,8 @@ "api.get_first_multi_datapoint([\n", " {\n", " \"id\": timeseries_id1,\n", - " \"startTime\": startTime1,\n", - " \"endTime\": endTime1,\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"avg\"],\n", " \"processingInterval\": \"5m\",\n", " \"fill\": None,\n", @@ -278,8 +278,8 @@ " },\n", " {\n", " \"id\": timeseries_id2,\n", - " \"startTime\": \"2024-07-01T00:00:00.000Z\",\n", - " \"endTime\": \"2024-07-01T01:00:00.000Z\",\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"count\"],\n", " \"processingInterval\": \"15m\",\n", " \"fill\": None,\n", @@ -304,8 +304,8 @@ "api.get_latest_multi_datapoint([\n", " {\n", " \"id\": timeseries_id1,\n", - " \"startTime\": startTime1,\n", - " \"endTime\": endTime1,\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"avg\"],\n", " \"processingInterval\": \"5m\",\n", " \"fill\": None,\n", @@ -313,8 +313,8 @@ " },\n", " {\n", " \"id\": timeseries_id2,\n", - " \"startTime\": \"2024-07-01T00:00:00.000Z\",\n", - " \"endTime\": \"2024-07-01T01:00:00.000Z\",\n", + " \"startTime\": startTime,\n", + " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"count\"],\n", " \"processingInterval\": \"15m\",\n", " \"fill\": None,\n", @@ -338,8 +338,8 @@ "source": [ "api.get_aggregates(\n", " timeseries_id1,\n", - " startTime=startTime1,\n", - " endTime=endTime1,\n", + " startTime=startTime,\n", + " endTime=endTime,\n", " processingInterval=\"15m\",\n", " aggregateFunction=[\"avg\"],\n", " fill=None,\n", @@ -441,10 +441,10 @@ "source": [ "api.create_stream_subscription(\n", " subscriptions=\n", - " [\n", - " {\n", - " \"id\":timeseries_id1\n", - " }\n", + " [\n", + " {\n", + " \"id\":timeseries_id1\n", + " }\n", "])" ] }, @@ -603,21 +603,21 @@ "api.write_data(\n", " id=\"Timeseries_ID_to_update\",\n", " data=\n", - " {\n", - " \"datapoints\":\n", - " [\n", - " {\n", - " \"time\": \"2024-12-02T14:00:00.000Z\",\n", - " \"value\":10.3,\n", - " \"status\":192\n", - " },\n", - " {\n", - " \"time\": \"2024-12-03T14:00:00.000Z\",\n", - " \"value\":10.4,\n", - " \"status\":192\n", - " }\n", - " ]\n", - " }\n", + " {\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-02T14:00:00.000Z\",\n", + " \"value\":10.3,\n", + " \"status\":192\n", + " },\n", + " {\n", + " \"time\": \"2024-12-03T14:00:00.000Z\",\n", + " \"value\":10.4,\n", + " \"status\":192\n", + " }\n", + " ]\n", + " }\n", ")" ] }, @@ -636,22 +636,22 @@ "source": [ "api.write_multiple(\n", " items=\n", - " {\n", - " \"items\":\n", - " [\n", - " {\n", - " \"id\":\"Timeseries_ID_to_update\",\n", - " \"datapoints\":\n", - " [\n", - " {\n", - " \"time\": \"2024-12-10T14:00:00.000Z\",\n", - " \"value\": 10.4,\n", - " \"status\": 192\n", - " }\n", - " ]\n", - " }\n", - " ]\n", - " }\n", + " {\n", + " \"items\":\n", + " [\n", + " {\n", + " \"id\":\"Timeseries_ID_to_update\",\n", + " \"datapoints\":\n", + " [\n", + " {\n", + " \"time\": \"2024-12-10T14:00:00.000Z\",\n", + " \"value\": 10.4,\n", + " \"status\": 192\n", + " }\n", + " ]\n", + " }\n", + " ]\n", + " }\n", ")" ] } From 03978a0428a34e76b71cd7f315462063ca04456e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Mon, 6 Jan 2025 13:14:20 +0100 Subject: [PATCH 08/13] Update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3a9cb9e..d09a961 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "omnia_timeseries" -version = "1.3.11" +version = "1.3.12" authors = ["Equinor Omnia Industrial IoT Team "] homepage = "https://github.com/equinor/omnia-timeseries-python" repository = "https://github.com/equinor/omnia-timeseries-python" From f715131b63a0e27c0cbb778566af33b2f1e1ef91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Tue, 7 Jan 2025 10:39:27 +0100 Subject: [PATCH 09/13] Fix comments in PR Add enum for federationSource, updated url and added some more description --- examples/usage_examples.ipynb | 56 ++++++++++++++++++++++------------- src/omnia_timeseries/api.py | 7 ++++- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index b61c102..0bc2afb 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "outputs": [], "source": [ - "from omnia_timeseries.api import TimeseriesAPI, TimeseriesEnvironment\n", + "from omnia_timeseries.api import TimeseriesAPI, TimeseriesEnvironment, FederationSource\n", "from azure.identity import ClientSecretCredential\n", "import os" ] @@ -69,9 +69,7 @@ "facility = \"SNA\"\n", "\n", "startTime=\"2024-12-09T14:00:00.000Z\"\n", - "endTime=\"2024-12-09T15:00:01.000Z\"\n", - "\n", - "federationSource = [\"IMS\", \"TSDB\", \"DataLake\"]" + "endTime=\"2024-12-09T15:00:01.000Z\"" ] }, { @@ -174,7 +172,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Query Timeseries API by tag name and facility" + "Query Timeseries API by tag name and facility\n", + "
\n", + "*We recommend using timeseries id to search for data, even though it is possible to search by name and facility*" ] }, { @@ -199,7 +199,23 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=federationSource[0])" + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.IMS.value)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Query Timeseries API by federation source TSDB" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.TSDB.value)" ] }, { @@ -215,7 +231,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id2, startTime=startTime, endTime=endTime, federationSource=federationSource[2])" + "api.get_datapoints(id=timeseries_id2, startTime=startTime, endTime=endTime, federationSource=FederationSource.DataLake.value)" ] }, { @@ -250,7 +266,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource[0])" + "], federationSource=FederationSource.IMS.value)" ] }, { @@ -285,7 +301,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource[0])" + "], federationSource=FederationSource.IMS.value)" ] }, { @@ -320,7 +336,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=federationSource[0])" + "], federationSource=FederationSource.IMS.value)" ] }, { @@ -350,7 +366,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get facilities" + "Get facilities with the number (count) of timeseries tags on each facility" ] }, { @@ -366,7 +382,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get sources" + "Get sources with the number (count) of timeseries tags on each source" ] }, { @@ -382,7 +398,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get facilities by source" + "Get facilities with the number (count) of timeseries tags by a chosen source (e.g. \"IMS\")" ] }, { @@ -391,14 +407,14 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_facilities_by_source(source=federationSource[0])" + "api.get_facilities_by_source(source=\"IMS\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Get source by facility" + "Get source with the number (count) of timeseries tags by a chosen facility" ] }, { @@ -414,7 +430,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Query get subscriptions API" + "Query get subscriptions API to see which timeseries tags you have a subscription on" ] }, { @@ -430,7 +446,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Create subscription" + "Create subscription for a timeseries tag" ] }, { @@ -452,7 +468,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Delete subscription" + "Delete subscription for given timeseries tag ID" ] }, { @@ -484,7 +500,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Add timeseries" + "Add timeseries, name and facility are required fields" ] }, { @@ -505,7 +521,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Get/add timeseries" + "Get/add timeseries (if the timeseries already exist it will be queried)" ] }, { diff --git a/src/omnia_timeseries/api.py b/src/omnia_timeseries/api.py index d8a7d29..8b4d035 100644 --- a/src/omnia_timeseries/api.py +++ b/src/omnia_timeseries/api.py @@ -12,11 +12,16 @@ TimeseriesPatchRequestItem, TimeseriesRequestItem ) import logging +from enum import Enum TimeseriesVersion = Literal["1.6", "1.7"] logger = logging.getLogger(__name__) +class FederationSource(Enum): + IMS = 'IMS' + TSDB = 'TSDB' + DataLake = 'DataLake' class TimeseriesEnvironment: def __init__(self, resource_id: str, base_url: str): @@ -335,7 +340,7 @@ def get_timeseries( continuationToken: Optional[str] = None, **kwargs) -> GetTimeseriesResponseModel: """ - https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=getTimeseries + https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=Getall Note that maximum result set is 100.000 items. """ params = kwargs or {} From ce9c908800b1bfa61b28b183d6430ced73272f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Tue, 7 Jan 2025 14:59:37 +0100 Subject: [PATCH 10/13] Add federationSource as Enum --- examples/usage_examples.ipynb | 14 +++++++------- src/omnia_timeseries/api.py | 36 +++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index 0bc2afb..a356452 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -199,7 +199,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.IMS.value)" + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.IMS)" ] }, { @@ -215,7 +215,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.TSDB.value)" + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.TSDB)" ] }, { @@ -231,7 +231,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.get_datapoints(id=timeseries_id2, startTime=startTime, endTime=endTime, federationSource=FederationSource.DataLake.value)" + "api.get_datapoints(id=timeseries_id1, startTime=startTime, endTime=endTime, federationSource=FederationSource.DataLake)" ] }, { @@ -266,7 +266,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=FederationSource.IMS.value)" + "], federationSource=FederationSource.IMS)" ] }, { @@ -293,7 +293,7 @@ " \"statusFilter\": [192]\n", " },\n", " {\n", - " \"id\": timeseries_id2,\n", + " \"id\": timeseries_id1,\n", " \"startTime\": startTime,\n", " \"endTime\": endTime,\n", " \"aggregateFunctions\": [\"count\"],\n", @@ -301,7 +301,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=FederationSource.IMS.value)" + "], federationSource=FederationSource.IMS)" ] }, { @@ -336,7 +336,7 @@ " \"fill\": None,\n", " \"statusFilter\": [192]\n", " }\n", - "], federationSource=FederationSource.IMS.value)" + "], federationSource=FederationSource.IMS)" ] }, { diff --git a/src/omnia_timeseries/api.py b/src/omnia_timeseries/api.py index 8b4d035..ef3d02c 100644 --- a/src/omnia_timeseries/api.py +++ b/src/omnia_timeseries/api.py @@ -19,9 +19,19 @@ logger = logging.getLogger(__name__) class FederationSource(Enum): - IMS = 'IMS' - TSDB = 'TSDB' - DataLake = 'DataLake' + """ + Set source that Omnia Timeseries API will use when executing a given query: + - Use `IMS` to query the underlying PI or IP21 IMS source. + - Use `TSDB` for Omnia timeseries database which should be up-to-date with IMS. + - Use `DataLake` for historic Omnia timeseries data which is 2 days behind `TSDB` and may contain data older than `TSDB`. + """ + #Ensure that Enum string value is returned instead of Enum full name + def __str__(self): + return self.value + + IMS = "IMS" + TSDB = "TSDB" + DataLake = "DataLake" class TimeseriesEnvironment: def __init__(self, resource_id: str, base_url: str): @@ -72,7 +82,6 @@ def resource_id(self) -> str: def base_url(self) -> str: return self._base_url - class TimeseriesAPI: """ Wrapper class for interacting with the Omnia Industrial IIoT Timeseries API. @@ -114,7 +123,7 @@ def get_datapoints( includeOutsidePoints: Optional[bool] = None, limit: Optional[int] = None, continuationToken: Optional[str] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetDatapointsResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetData""" params = {} @@ -150,7 +159,7 @@ def get_datapoints_by_name( includeOutsidePoints: Optional[bool] = None, limit: Optional[int] = None, continuationToken: Optional[str] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetDatapointsResponseModel: """https://api.equinor.com/docs/services/Timeseries-api-v1-7/operations/getDataByName""" params = {} @@ -183,7 +192,7 @@ def get_multi_datapoints( self, request: List[GetMultipleDatapointsRequestItem], continuationToken: Optional[str] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetAggregatesResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetMultipleData""" params = {} @@ -210,7 +219,7 @@ def get_aggregates( fill: Optional[str] = None, limit: Optional[int] = None, continuationToken: Optional[str] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetAggregatesResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetAggregatedData""" params = {} @@ -245,7 +254,7 @@ def get_first_datapoint( afterTime: Optional[str] = None, beforeTime: Optional[str] = None, status: Optional[List[int]] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> DatapointModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetFirst""" params = {} @@ -270,7 +279,7 @@ def get_latest_datapoint( afterTime: Optional[str] = None, beforeTime: Optional[str] = None, status: Optional[List[int]] = None, - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetDatapointsResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetLatest""" params = {} @@ -291,7 +300,7 @@ def get_latest_datapoint( def get_first_multi_datapoint(self, request: List[GetMultipleDatapointsRequestItem], - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetDatapointsResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetMultipleFirst""" params = {} @@ -307,7 +316,7 @@ def get_first_multi_datapoint(self, def get_latest_multi_datapoint(self, request: List[GetMultipleDatapointsRequestItem], - federationSource: Optional[str] = None, + federationSource: Optional[Enum] = None, accept: ContentType = "application/json") -> GetDatapointsResponseModel: """https://api.equinor.com/api-details#api=Timeseries-api-v1-7&operation=GetMultipleLatest""" params = {} @@ -328,7 +337,6 @@ 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, @@ -522,4 +530,4 @@ def get_facilities_by_source(self, source: str) -> FacilityDataModel: return self._http_client.request( request_type='get', url=f"{self._base_url}/facets/facility?source={source}" - ) + ) \ No newline at end of file From 7f780670fd8f957fdae50cd755c64554a1eebe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Wed, 8 Jan 2025 08:36:11 +0100 Subject: [PATCH 11/13] Add one more example --- README.md | 2 +- examples/usage_examples.ipynb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6776060..b3acf5e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For fundamental questions please refer to the MSAL documentation which has [code You should also familiarize yourself with the [azure.identity](https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python) package, which we will use below. -Follow [client credentials flow example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/client_secret_auth.ipynb) to learn how to retrieve data in `Json` format. +Follow [client credentials flow example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/usage_example.ipynb) to learn how to retrieve data in `Json` format. Follow [get data as protobuf example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/get_data_protobuf.ipynb) to learn how to retrieve data in `Protobuf` format. ### Preparing Azure authentication diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index a356452..85098be 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -72,6 +72,22 @@ "endTime=\"2024-12-09T15:00:01.000Z\"" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Search Timeseries API" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "api.search_timeseries(limit=10)" + ] + }, { "cell_type": "markdown", "metadata": {}, From 032172c765aefc48bb94a8ce9f77372ad237aeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Bj=C3=B8rkelund=20Haugen?= Date: Wed, 8 Jan 2025 12:48:36 +0100 Subject: [PATCH 12/13] Add auth methods --- README.md | 2 +- examples/usage_examples.ipynb | 98 ++++++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b3acf5e..3a0f477 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For fundamental questions please refer to the MSAL documentation which has [code You should also familiarize yourself with the [azure.identity](https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python) package, which we will use below. -Follow [client credentials flow example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/usage_example.ipynb) to learn how to retrieve data in `Json` format. +Follow [usage example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/usage_example.ipynb) to learn how to retrieve data in `Json` format. Follow [get data as protobuf example](https://github.com/equinor/omnia-timeseries-python/blob/main/examples/get_data_protobuf.ipynb) to learn how to retrieve data in `Protobuf` format. ### Preparing Azure authentication diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index 85098be..b99940e 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -4,18 +4,25 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Client secret credentials example\n", + "# Timeseries API examples\n", "\n", - "This notebook shows how to use some of the Timeseries API endpoints with client secret credentials ref: \n", - "https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow \n", - "https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python" + "Please have a look at the README first.\n", + "
This notebook shows how to use some of the Timeseries API endpoints with different authentication methods using the Azure identity library:\n", + "
https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Import the required libraries. The `azure.identity` package will handle the actual authentication to the API" + "## Setup" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Import the required libraries." ] }, { @@ -25,7 +32,6 @@ "outputs": [], "source": [ "from omnia_timeseries.api import TimeseriesAPI, TimeseriesEnvironment, FederationSource\n", - "from azure.identity import ClientSecretCredential\n", "import os" ] }, @@ -33,7 +39,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Set up Timeseries API with the desired environment" + "___\n", + "Choose one of the authentication methods from the 3 cells below to authenticate aginst the Timeseries API.\n", + "
The `azure.identity` package will handle the actual authentication to the API." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Number 1 - Service principal credentials**" ] }, { @@ -42,13 +57,80 @@ "metadata": {}, "outputs": [], "source": [ + "from azure.identity import ClientSecretCredential\n", "credentials = ClientSecretCredential(\n", " client_id=os.environ[\"AZURE_CLIENT_ID\"],\n", " client_secret=os.environ['AZURE_CLIENT_SECRET'],\n", - " tenant_id=os.environ[\"AZURE_TENANT_ID\"])\n", + " tenant_id=os.environ[\"AZURE_TENANT_ID\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Number 2 - User impersonation**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azure.identity import DeviceCodeCredential\n", + "credential = DeviceCodeCredential(\n", + " tenant_id=os.environ['AZURE_TENANT_ID'],\n", + " client_id=os.environ['AZURE_CLIENT_ID']\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Number 3 - Default credentials**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azure.identity import DefaultAzureCredential\n", + "credential = DefaultAzureCredential()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "___" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Set up the Timeseries API with the desired environment (Dev(), Test(), Prod())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "api = TimeseriesAPI(azure_credential=credentials, environment=TimeseriesEnvironment.Dev())" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Examples" + ] + }, { "cell_type": "markdown", "metadata": {}, From 47e952959048170c3313e700e15888a5324d1fba Mon Sep 17 00:00:00 2001 From: saraeq Date: Thu, 9 Jan 2025 09:43:11 +0100 Subject: [PATCH 13/13] Change example to use get_timeseries --- examples/usage_examples.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/usage_examples.ipynb b/examples/usage_examples.ipynb index b99940e..b8a9061 100644 --- a/examples/usage_examples.ipynb +++ b/examples/usage_examples.ipynb @@ -144,10 +144,10 @@ "metadata": {}, "outputs": [], "source": [ - "timeseries_id1 = \"Timeseries_ID\"\n", + "timeseries_id1 = \"Timeseries_ID1\"\n", "timeseries_id2 = \"Timeseries_ID2\"\n", "\n", - "timeseries_name1 = \"Name_of_timeseries_id1\"\n", + "timeseries_name1 = \"Name_of_timeseries_ID1\"\n", "facility = \"SNA\"\n", "\n", "startTime=\"2024-12-09T14:00:00.000Z\"\n", @@ -158,7 +158,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Search Timeseries API" + "Get Timeseries metadata" ] }, { @@ -167,7 +167,7 @@ "metadata": {}, "outputs": [], "source": [ - "api.search_timeseries(limit=10)" + "api.get_timeseries(limit=10)" ] }, {