Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
GBBBAS committed Oct 9, 2023
2 parents d342b9a + 514651c commit 1e7328d
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 18 deletions.
5 changes: 4 additions & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ changelog:
- documentation
- title: Pipelines
labels:
- pipelines
- pipelines
- title: Queries
labels:
- queries
- title: Other Changes
labels:
- "*"
2 changes: 2 additions & 0 deletions src/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
interpolate,
interpolation_at_time,
time_weighted_average,
circular_average,
circular_standard_deviation,
graphql,
)
from src.api.auth.azuread import oauth2_scheme
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,
)
10 changes: 10 additions & 0 deletions src/api/v1/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def common_api_setup_tasks(
interpolate_query_parameters=None,
interpolation_at_time_query_parameters=None,
time_weighted_average_query_parameters=None,
circular_average_query_parameters=None,
circular_standard_deviation_query_parameters=None,
pivot_query_parameters=None,
limit_offset_query_parameters=None,
):
Expand Down Expand Up @@ -96,6 +98,14 @@ def common_api_setup_tasks(
if time_weighted_average_query_parameters != None:
parameters = dict(parameters, **time_weighted_average_query_parameters.__dict__)

if circular_average_query_parameters != None:
parameters = dict(parameters, **circular_average_query_parameters.__dict__)

if circular_standard_deviation_query_parameters != None:
parameters = dict(
parameters, **circular_standard_deviation_query_parameters.__dict__
)

if pivot_query_parameters != None:
parameters = dict(parameters, **pivot_query_parameters.__dict__)

Expand Down
Loading

0 comments on commit 1e7328d

Please sign in to comment.