Skip to content

Commit

Permalink
Merge pull request #533 from rtdip/develop
Browse files Browse the repository at this point in the history
v0.8.3
  • Loading branch information
GBBBAS authored Oct 9, 2023
2 parents d1c223e + e0903c2 commit 6594179
Show file tree
Hide file tree
Showing 31 changed files with 977 additions and 307 deletions.
6 changes: 3 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ dependencies:
- azure-keyvault-secrets==4.7.0
- boto3==1.28.2
- pyodbc==4.0.39
- fastapi==0.100.1
- fastapi==0.103.2
- httpx==0.24.1
- trio==0.22.1
- pyspark>=3.3.0,<3.5.0
- delta-spark>=2.2.0,<3.1.0
- grpcio>=1.48.1
Expand All @@ -58,7 +57,7 @@ dependencies:
- semver==3.0.0
- xlrd==2.0.1
- pygithub==1.59.0
- strawberry-graphql[fastapi,pydantic]==0.194.4
- pydantic==2.4.2
- web3==6.5.0
- twine==4.0.2
- delta-sharing-python==1.0.0
Expand All @@ -76,4 +75,5 @@ dependencies:
- langchain==0.0.291
- build==0.10.0
- deltalake==0.10.1
- trio==0.22.1

4 changes: 2 additions & 2 deletions src/api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Do not include azure-functions-worker as it may conflict with the Azure Functions platform
azure-functions==1.15.0
fastapi==0.103.1
fastapi==0.103.2
nest_asyncio==1.5.6
strawberry-graphql[fastapi,pydantic]==0.194.4
pydantic==2.4.2
turbodbc==4.5.10
pyodbc==4.0.39
importlib_metadata>=1.0.0
Expand Down
11 changes: 4 additions & 7 deletions src/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@
resample,
interpolate,
interpolation_at_time,
circular_average,
circular_standard_deviation,
time_weighted_average,
graphql,
circular_average,
circular_standard_deviation,
)
from src.api.auth.azuread import oauth2_scheme

app.include_router(api_v1_router)
app.include_router(
graphql.graphql_router,
prefix="/graphql",
include_in_schema=False,
dependencies=[Depends(oauth2_scheme)],
)


async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
Expand Down
162 changes: 162 additions & 0 deletions src/api/v1/circular_average.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# 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
from typing import Union
import numpy as np
from requests import request
from src.api.FastAPIApp import api_v1_router
from fastapi import HTTPException, Depends, Body
import nest_asyncio
from pandas.io.json import build_table_schema
from src.sdk.python.rtdip_sdk.queries import circular_average
from src.api.v1.models import (
BaseQueryParams,
BaseHeaders,
ResampleInterpolateResponse,
PivotResponse,
HTTPError,
RawQueryParams,
TagsQueryParams,
TagsBodyParams,
CircularAverageQueryParams,
PivotQueryParams,
LimitOffsetQueryParams,
)
import src.api.v1.common

nest_asyncio.apply()


def circular_average_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_average_query_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
):
try:
(connection, parameters) = src.api.v1.common.common_api_setup_tasks(
base_query_parameters,
raw_query_parameters=raw_query_parameters,
tag_query_parameters=tag_query_parameters,
circular_average_query_parameters=circular_average_query_parameters,
pivot_query_parameters=pivot_parameters,
limit_offset_query_parameters=limit_offset_parameters,
base_headers=base_headers,
)

data = circular_average.get(connection, parameters)
if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
)
else:
return ResampleInterpolateResponse(
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 = """
## Circular Average
Circular Average of timeseries data.
"""


@api_v1_router.get(
path="/events/circularaverage",
name="Circular Average GET",
description=get_description,
tags=["Events"],
responses={
200: {"model": Union[ResampleInterpolateResponse, PivotResponse]},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Circular Average Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/circular-average/",
}
},
)
async def circular_average_get(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsQueryParams = Depends(),
circular_average_parameters: CircularAverageQueryParams = Depends(),
pivot_parameters: PivotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return circular_average_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_average_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
)


post_description = """
## Circular Average
Circular Average of timeseries data 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/circularaverage",
name="Circular Average POST",
description=post_description,
tags=["Events"],
responses={
200: {"model": Union[ResampleInterpolateResponse, PivotResponse]},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Circular Average Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/circular-average/",
}
},
)
async def resample_post(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsBodyParams = Body(default=...),
circular_average_parameters: CircularAverageQueryParams = Depends(),
pivot_parameters: PivotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return circular_average_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_average_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
)
162 changes: 162 additions & 0 deletions src/api/v1/circular_standard_deviation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# 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
from typing import Union
import numpy as np
from requests import request
from src.api.FastAPIApp import api_v1_router
from fastapi import HTTPException, Depends, Body
import nest_asyncio
from pandas.io.json import build_table_schema
from src.sdk.python.rtdip_sdk.queries import circular_standard_deviation
from src.api.v1.models import (
BaseQueryParams,
BaseHeaders,
ResampleInterpolateResponse,
PivotResponse,
HTTPError,
RawQueryParams,
TagsQueryParams,
TagsBodyParams,
PivotQueryParams,
LimitOffsetQueryParams,
CircularAverageQueryParams,
)
import src.api.v1.common

nest_asyncio.apply()


def circular_standard_deviation_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_standard_deviation_query_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
):
try:
(connection, parameters) = src.api.v1.common.common_api_setup_tasks(
base_query_parameters,
raw_query_parameters=raw_query_parameters,
tag_query_parameters=tag_query_parameters,
circular_standard_deviation_query_parameters=circular_standard_deviation_query_parameters,
pivot_query_parameters=pivot_parameters,
limit_offset_query_parameters=limit_offset_parameters,
base_headers=base_headers,
)

data = circular_standard_deviation.get(connection, parameters)
if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
)
else:
return ResampleInterpolateResponse(
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 = """
## Circular Standard Deviation
Circular Standard Deviation of timeseries data.
"""


@api_v1_router.get(
path="/events/circularstandarddeviation",
name="Circular Standard Deviation GET",
description=get_description,
tags=["Events"],
responses={
200: {"model": Union[ResampleInterpolateResponse, PivotResponse]},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Circular Standard Deviation Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/circular-standard-deviation/",
}
},
)
async def circular_standard_deviation_get(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsQueryParams = Depends(),
circular_standard_deviation_parameters: CircularAverageQueryParams = Depends(),
pivot_parameters: PivotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return circular_standard_deviation_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_standard_deviation_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
)


post_description = """
## Circular Standard Deviation
Circular Standard Deviation of timeseries data 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/circularstandarddeviation",
name="Circular Standard Deviation POST",
description=post_description,
tags=["Events"],
responses={
200: {"model": Union[ResampleInterpolateResponse, PivotResponse]},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Circular Standard Deviation Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/circular-standard-deviation/",
}
},
)
async def resample_post(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsBodyParams = Body(default=...),
circular_standard_deviation_parameters: CircularAverageQueryParams = Depends(),
pivot_parameters: PivotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return circular_standard_deviation_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
circular_standard_deviation_parameters,
pivot_parameters,
limit_offset_parameters,
base_headers,
)
Loading

0 comments on commit 6594179

Please sign in to comment.