Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"azureFunctions.projectRuntime": "~4",

"python.testing.pytestArgs": [
"--cache-clear",
"--cov=.",
"--cov-report=xml:cov.xml",
"tests",
"-vv",
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
15 changes: 15 additions & 0 deletions docs/sdk/code-reference/query/functions/time_series/plot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Plot Function
::: src.sdk.python.rtdip_sdk.queries.time_series.plot

## Example
```python
--8<-- "https://raw.githubusercontent.com/rtdip/samples/main/queries/Plot/plot.py"
```

This example is using [```DefaultAuth()```](../../../authentication/azure.md) and [```DatabricksSQLConnection()```](../../connectors/db-sql-connector.md) to authenticate and connect. You can find other ways to authenticate [here](../../../authentication/azure.md). The alternative built in connection methods are either by [```PYODBCSQLConnection()```](../../connectors/pyodbc-sql-connector.md), [```TURBODBCSQLConnection()```](../../connectors/turbodbc-sql-connector.md) or [```SparkConnection()```](../../connectors/spark-connector.md).

!!! note "Note"
See [Samples Repository](https://github.com/rtdip/samples/tree/main/queries) for full list of examples.

!!! note "Note"
</b>```server_hostname``` and ```http_path``` can be found on the [SQL Warehouses Page](../../../../queries/databricks/sql-warehouses.md). <br />
1 change: 1 addition & 0 deletions docs/sdk/examples/query/Plot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "https://raw.githubusercontent.com/rtdip/samples/main/queries/Plot/README.md"
12 changes: 12 additions & 0 deletions docs/sdk/queries/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ The RTDIP SDK enables users to perform complex queries, including aggregation on
- Time Interval Unit - The time interval unit (second, minute, day, hour)
- Aggregation Method - Aggregations including first, last, avg, min, max

!!! note "Note"
</b>Sample Rate and Sample Unit parameters are deprecated and will be removed in v1.0.0. Please use Time Interval Rate and Time Interval Unit instead.<br />

### Plot

[Plot](../code-reference/query/functions/time_series/plot.md) enables changing the frequency of time series observations and performing Average, Min, Max, First, Last and StdDev aggregations. This is achieved by providing the following parameters:

- Sample Rate - (<em>deprecated</em>)
- Sample Unit - (<em>deprecated</em>)
- Time Interval Rate - The time interval rate
- Time Interval Unit - The time interval unit (second, minute, day, hour)

!!! note "Note"
</b>Sample Rate and Sample Unit parameters are deprecated and will be removed in v1.0.0. Please use Time Interval Rate and Time Interval Unit instead.<br />

Expand Down
13 changes: 7 additions & 6 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ channels:
- defaults
dependencies:
- python>=3.9,<3.12
- mkdocs-material-extensions==1.1.1
- jinja2==3.1.3
- pytest==7.4.0
- pytest-mock==3.11.1
Expand All @@ -46,19 +45,20 @@ dependencies:
- googleapis-common-protos>=1.56.4
- openjdk==11.0.15
- openai==1.13.3
- mkdocs-material==9.3.1
- mkdocs-material==9.5.20
- mkdocs-material-extensions==1.3.1
- mkdocstrings==0.22.0
- mkdocstrings-python==1.4.0
- mkdocs-macros-plugin==1.0.1
- pygments==2.16.1
- pymdown-extensions==10.1.0
- pymdown-extensions==10.8.1
- databricks-sql-connector==3.1.0
- semver==3.0.0
- xlrd==2.0.1
- pygithub==1.59.0
- pydantic==2.6.0
- pyjwt==2.8.0
- web3==6.5.0
- web3==6.16.0
- twine==4.0.2
- delta-sharing-python==1.0.0
- polars==0.18.8
Expand All @@ -75,9 +75,10 @@ dependencies:
- azure-functions==1.15.0
- azure-mgmt-eventgrid==10.2.0
- hvac==1.1.1
- langchain==0.1.11
- langchain==0.1.17
- build==0.10.0
- deltalake==0.10.1
- trio==0.22.1
- sqlparams==5.1.0
- entsoe-py==0.5.10
- entsoe-py==0.5.10
- eth-typing==4.2.1
6 changes: 4 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ markdown_extensions:
- pymdownx.tabbed:
alternate_style: true
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg # Page tree
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg # Page tree
- pymdownx.snippets:
url_download: true

Expand Down Expand Up @@ -258,6 +258,7 @@ nav:
- Raw: sdk/code-reference/query/functions/time_series/raw.md
- Latest: sdk/code-reference/query/functions/time_series/latest.md
- Resample: sdk/code-reference/query/functions/time_series/resample.md
- Plot: sdk/code-reference/query/functions/time_series/plot.md
- Interpolate: sdk/code-reference/query/functions/time_series/interpolate.md
- Interpolation at Time: sdk/code-reference/query/functions/time_series/interpolation-at-time.md
- Time Weighted Average: sdk/code-reference/query/functions/time_series/time-weighted-average.md
Expand Down Expand Up @@ -289,6 +290,7 @@ nav:
- Metadata: sdk/examples/query/Metadata.md
- Raw: sdk/examples/query/Raw.md
- Resample: sdk/examples/query/Resample.md
- Plot: sdk/examples/query/Plot.md
- Time Weighted Average: sdk/examples/query/Time-Weighted-Average.md
- Circular Average: sdk/examples/query/Circular-Average.md
- Circular Standard Deviation: sdk/examples/query/Circular-Standard-Deviation.md
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"grpcio>=1.48.1",
"grpcio-status>=1.48.1",
"googleapis-common-protos>=1.56.4",
"langchain==0.1.11",
"langchain==0.1.17",
"openai==1.13.3",
"pydantic==2.6.0",
]
Expand All @@ -58,7 +58,7 @@
"boto3==1.28.2",
"hvac==1.1.1",
"azure-keyvault-secrets==4.7.0",
"web3==6.5.0",
"web3==6.16.0",
"polars[deltalake]==0.18.8",
"delta-sharing==1.0.0",
"xarray>=2023.1.0,<2023.8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ packaging==23.2
grpcio>=1.48.1
grpcio-status>=1.48.1
googleapis-common-protos>=1.56.4
langchain==0.1.11
langchain==0.1.17
openai==1.13.3
pyjwt==2.8.0
1 change: 1 addition & 0 deletions src/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
sql,
latest,
resample,
plot,
interpolate,
interpolation_at_time,
circular_average,
Expand Down
4 changes: 4 additions & 0 deletions src/api/v1/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def common_api_setup_tasks( # NOSONAR
sql_query_parameters=None,
tag_query_parameters=None,
resample_query_parameters=None,
plot_query_parameters=None,
interpolate_query_parameters=None,
interpolation_at_time_query_parameters=None,
time_weighted_average_query_parameters=None,
Expand Down Expand Up @@ -100,6 +101,9 @@ def common_api_setup_tasks( # NOSONAR
if resample_query_parameters != None:
parameters = dict(parameters, **resample_query_parameters.__dict__)

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

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

Expand Down
35 changes: 35 additions & 0 deletions src/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ class ResampleInterpolateRow(BaseModel):
Value: Union[float, int, str, None]


class PlotRow(BaseModel):
EventTime: datetime
TagName: str
Average: float
Min: float
Max: float
First: float
Last: float
StdDev: float


class PivotRow(BaseModel):
EventTime: datetime

Expand Down Expand Up @@ -277,6 +288,30 @@ class TagsBodyParams(BaseModel):
tag_name: List[str]


class PlotQueryParams:
def __init__(
self,
sample_rate: str = Query(
...,
description="sample_rate is deprecated and will be removed in v1.0.0. Please use time_interval_rate instead.",
examples=[5],
deprecated=True,
),
sample_unit: str = Query(
...,
description="sample_unit is deprecated and will be removed in v1.0.0. Please use time_interval_unit instead.",
examples=["second", "minute", "hour", "day"],
deprecated=True,
),
time_interval_rate: str = DuplicatedQueryParameters.time_interval_rate,
time_interval_unit: str = DuplicatedQueryParameters.time_interval_unit,
):
self.sample_rate = sample_rate
self.sample_unit = sample_unit
self.time_interval_rate = time_interval_rate
self.time_interval_unit = time_interval_unit


class ResampleQueryParams:
def __init__(
self,
Expand Down
142 changes: 142 additions & 0 deletions src/api/v1/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# 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
from src.api.FastAPIApp import api_v1_router
from fastapi import HTTPException, Depends, Body

from src.sdk.python.rtdip_sdk.queries.time_series import plot
from src.api.v1.models import (
BaseQueryParams,
BaseHeaders,
ResampleInterpolateRow,
HTTPError,
RawQueryParams,
TagsQueryParams,
TagsBodyParams,
PlotQueryParams,
PivotQueryParams,
LimitOffsetQueryParams,
)
from src.api.v1.common import common_api_setup_tasks, json_response


def plot_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
plot_query_parameters,
limit_offset_parameters,
base_headers,
):
try:
(connection, parameters) = common_api_setup_tasks(
base_query_parameters,
raw_query_parameters=raw_query_parameters,
tag_query_parameters=tag_query_parameters,
plot_query_parameters=plot_query_parameters,
limit_offset_query_parameters=limit_offset_parameters,
base_headers=base_headers,
)

data = plot.get(connection, parameters)

return json_response(data, limit_offset_parameters)
except Exception as e:
logging.error(str(e))
raise HTTPException(status_code=400, detail=str(e))


get_description = """
## Plot

Plotting of resampled raw timeseries data and aggregated to Min, Max, First and Last and an Exception Value(Status = Bad) if it exists.
"""


@api_v1_router.get(
path="/events/plot",
name="Plot GET",
description=get_description,
tags=["Events"],
responses={
200: {"model": ResampleInterpolateRow},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Plot Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/functions/time_series/plot/",
}
},
)
async def plot_get(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsQueryParams = Depends(),
plot_query_parameters: PlotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return plot_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
plot_query_parameters,
limit_offset_parameters,
base_headers,
)


post_description = """
## Plot

Plotting of resampled raw timeseries data and aggregated to Average, Min, Max, First and Last and an Exception Value(Status = Bad) if it exists, 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/plot",
name="Plot POST",
description=post_description,
tags=["Events"],
responses={
200: {"model": ResampleInterpolateRow},
400: {"model": HTTPError},
},
openapi_extra={
"externalDocs": {
"description": "RTDIP Resample Query Documentation",
"url": "https://www.rtdip.io/sdk/code-reference/query/functions/time_series/plot/",
}
},
)
async def plot_post(
base_query_parameters: BaseQueryParams = Depends(),
raw_query_parameters: RawQueryParams = Depends(),
tag_query_parameters: TagsBodyParams = Body(default=...),
plot_query_parameters: PlotQueryParams = Depends(),
limit_offset_parameters: LimitOffsetQueryParams = Depends(),
base_headers: BaseHeaders = Depends(),
):
return plot_events_get(
base_query_parameters,
raw_query_parameters,
tag_query_parameters,
plot_query_parameters,
limit_offset_parameters,
base_headers,
)
Loading