Skip to content

Resample

Resample enables changing the frequency of time series observations. This is achieved by providing the following parameters:

Sample Rate - (deprecated) Sample Unit - (deprecated) Time Interval Rate - The time interval rate Time Interval Unit - The time interval unit (second, minute, day, hour) Aggregation Method - Aggregations including first, last, avg, min, max

Prerequisites

Ensure you have installed the RTDIP SDK as specified in the Getting Started section.

This example is using DefaultAuth() and DatabricksSQLConnection() to authenticate and connect. You can find other ways to authenticate here. The alternative built in connection methods are either by PYODBCSQLConnection(), TURBODBCSQLConnection() or SparkConnection().

Parameters

Name Type Description
business_unit str Business unit of the data
region str Region
asset str Asset
data_security_level str Level of data security
data_type str Type of the data (float, integer, double, string)
tag_names list List of tagname or tagnames ["tag_1", "tag_2"]
start_date str Start date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
end_date str End date (Either a date in the format YY-MM-DD or a datetime in the format YYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz)
sample_rate int (deprecated) Please use time_interval_rate instead. See below.
sample_unit str (deprecated) Please use time_interval_unit instead. See below.
time_interval_rate str The time interval rate (numeric input)
time_interval_unit str The time interval unit (second, minute, day, hour)
agg_method str Aggregation Method (first, last, avg, min, max)
include_bad_data bool Include "Bad" data points with True or remove "Bad" data points with False

Example

from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import resample

auth = DefaultAuth().authenticate()
token = auth.get_token("2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default").token
connection = DatabricksSQLConnection("{server_hostname}", "{http_path}", token)

parameters = {
    "business_unit": "{business_unit}",
    "region": "{region}", 
    "asset": "{asset_name}", 
    "data_security_level": "{security_level}", 
    "data_type": "float",
    "tag_names": ["{tag_name_1}", "{tag_name_2}"],
    "start_date": "2023-01-01",
    "end_date": "2023-01-31",
    "time_interval_rate": "15",
    "time_interval_unit": "minute",
    "agg_method": "first",
    "include_bad_data": True,
}
x = resample.get(connection, parameters)
print(x)