Skip to content

Commit

Permalink
add more usage examples of the sdk
Browse files Browse the repository at this point in the history
Also added some variables to test more easily for us
  • Loading branch information
saraeq committed Dec 11, 2024
1 parent a46d722 commit 2e613eb
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 28 deletions.
212 changes: 185 additions & 27 deletions examples/client_secret_auth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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": {},
Expand All @@ -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)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -165,28 +240,96 @@
"metadata": {},
"outputs": [],
"source": [
"timeseriesId1=\"<some timeseries id>\"\n",
"timeseriesId2=\"<some timeseries id>\"\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",
" \"processingInterval\": \"15m\",\n",
" \"fill\": None,\n",
" \"statusFilter\": [192]\n",
" }\n",
"], federationSource=\"IMS\")"
"], federationSource=federationSource_IMS)"
]
},
{
Expand All @@ -202,16 +345,31 @@
"metadata": {},
"outputs": [],
"source": [
"timeseriesId=\"<some timeseries id>\"\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": {
Expand All @@ -230,7 +388,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion src/omnia_timeseries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2e613eb

Please sign in to comment.