-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from rtdip/develop
v0.8.0
- Loading branch information
Showing
17 changed files
with
755 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Raw Function | ||
::: src.sdk.python.rtdip_sdk.queries.time_series.latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
from src.api.v1 import ( | ||
metadata, | ||
raw, | ||
latest, | ||
resample, | ||
interpolate, | ||
interpolation_at_time, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Copyright 2022 RTDIP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import logging | ||
import numpy as np | ||
from pandas.io.json import build_table_schema | ||
from fastapi import Query, HTTPException, Depends, Body | ||
import nest_asyncio | ||
from src.sdk.python.rtdip_sdk.queries import latest | ||
from src.api.v1.models import ( | ||
BaseQueryParams, | ||
BaseHeaders, | ||
MetadataQueryParams, | ||
TagsBodyParams, | ||
LatestResponse, | ||
LimitOffsetQueryParams, | ||
HTTPError, | ||
) | ||
from src.api.auth.azuread import oauth2_scheme | ||
from src.api.FastAPIApp import api_v1_router | ||
from src.api.v1 import common | ||
|
||
nest_asyncio.apply() | ||
|
||
|
||
def latest_retrieval_get( | ||
query_parameters, metadata_query_parameters, limit_offset_parameters, base_headers | ||
): | ||
try: | ||
(connection, parameters) = common.common_api_setup_tasks( | ||
query_parameters, | ||
metadata_query_parameters=metadata_query_parameters, | ||
limit_offset_query_parameters=limit_offset_parameters, | ||
base_headers=base_headers, | ||
) | ||
|
||
data = latest.get(connection, parameters) | ||
return LatestResponse( | ||
schema=build_table_schema(data, index=False, primary_key=False), | ||
data=data.replace({np.nan: None}).to_dict(orient="records"), | ||
) | ||
except Exception as e: | ||
logging.error(str(e)) | ||
raise HTTPException(status_code=400, detail=str(e)) | ||
|
||
|
||
get_description = """ | ||
## Latest | ||
Retrieval of latest event values for a given tag name or list of tag names. | ||
""" | ||
|
||
|
||
@api_v1_router.get( | ||
path="/events/latest", | ||
name="Latest GET", | ||
description=get_description, | ||
tags=["Events"], | ||
dependencies=[Depends(oauth2_scheme)], | ||
responses={200: {"model": LatestResponse}, 400: {"model": HTTPError}}, | ||
openapi_extra={ | ||
"externalDocs": { | ||
"description": "RTDIP Latest Query Documentation", | ||
"url": "https://www.rtdip.io/sdk/code-reference/query/latest/", | ||
} | ||
}, | ||
) | ||
async def latest_get( | ||
query_parameters: BaseQueryParams = Depends(), | ||
metadata_query_parameters: MetadataQueryParams = Depends(), | ||
limit_offset_parameters: LimitOffsetQueryParams = Depends(), | ||
base_headers: BaseHeaders = Depends(), | ||
): | ||
return latest_retrieval_get( | ||
query_parameters, | ||
metadata_query_parameters, | ||
limit_offset_parameters, | ||
base_headers, | ||
) | ||
|
||
|
||
post_description = """ | ||
## Metadata | ||
Retrieval of latest event values for a given tag name or list of tag names via a POST method to enable providing a list of tag names that can exceed url length restrictions via GET Query Parameters. | ||
""" | ||
|
||
|
||
@api_v1_router.post( | ||
path="/events/latest", | ||
name="Latest POST", | ||
description=post_description, | ||
tags=["Events"], | ||
dependencies=[Depends(oauth2_scheme)], | ||
responses={200: {"model": LatestResponse}, 400: {"model": HTTPError}}, | ||
openapi_extra={ | ||
"externalDocs": { | ||
"description": "RTDIP Latest Query Documentation", | ||
"url": "https://www.rtdip.io/sdk/code-reference/query/latest/", | ||
} | ||
}, | ||
) | ||
async def latest_post( | ||
query_parameters: BaseQueryParams = Depends(), | ||
metadata_query_parameters: TagsBodyParams = Body(default=...), | ||
limit_offset_parameters: LimitOffsetQueryParams = Depends(), | ||
base_headers: BaseHeaders = Depends(), | ||
): | ||
return latest_retrieval_get( | ||
query_parameters, | ||
metadata_query_parameters, | ||
limit_offset_parameters, | ||
base_headers, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2022 RTDIP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging | ||
|
||
logging.warning( | ||
"Module rtdip_sdk.functions is deprecated and will be removed in v1.0.0. Please import rtdip_sdk.queries instead." | ||
) | ||
|
||
from ..queries.metadata import * # NOSONAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
from .time_series import ( | ||
raw, | ||
latest, | ||
resample, | ||
interpolate, | ||
interpolation_at_time, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.