Skip to content

Commit

Permalink
Add update and delete examples
Browse files Browse the repository at this point in the history
  • Loading branch information
saraeq committed Jan 2, 2025
1 parent e2eab97 commit e55c460
Showing 1 changed file with 164 additions and 15 deletions.
179 changes: 164 additions & 15 deletions examples/client_secret_auth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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())"
]
},
{
Expand All @@ -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\"]"
]
},
{
Expand All @@ -90,7 +88,7 @@
"metadata": {},
"outputs": [],
"source": [
"api.search_timeseries(name=\"*P9*\",limit=10)"
"api.search_timeseries(name=\"*Omnia IIoT write test*\",limit=10)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -122,7 +120,7 @@
"metadata": {},
"outputs": [],
"source": [
"api.get_timeseries_by_id(id=timeseries_id3)"
"api.get_timeseries_by_id(id=timeseries_id1)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -155,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"api.get_first_datapoint(id=timeseries_id3)"
"api.get_first_datapoint(id=timeseries_id1)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand Down Expand Up @@ -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])"
]
},
{
Expand All @@ -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])"
]
},
{
Expand Down Expand Up @@ -259,7 +257,7 @@
" \"fill\": None,\n",
" \"statusFilter\": [192]\n",
" }\n",
"], federationSource=federationSource_IMS)"
"], federationSource=federationSource[0])"
]
},
{
Expand Down Expand Up @@ -294,7 +292,7 @@
" \"fill\": None,\n",
" \"statusFilter\": [192]\n",
" }\n",
"], federationSource=federationSource_IMS)"
"], federationSource=federationSource[0])"
]
},
{
Expand Down Expand Up @@ -329,7 +327,7 @@
" \"fill\": None,\n",
" \"statusFilter\": [192]\n",
" }\n",
"], federationSource=federationSource_IMS)"
"], federationSource=federationSource[0])"
]
},
{
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit e55c460

Please sign in to comment.