Time Weighted Average
get(connection, parameters_dict)
A function that recieves a dataframe of raw tag data and performs a timeweighted average, returning the results.
This function requires the input of a pandas dataframe acquired via the rtdip.functions.raw() method and the user to input a dictionary of parameters. (See Attributes table below)
Pi data points will either have step enabled (True) or step disabled (False). You can specify whether you want step to be fetched by "Pi" or you can set the step parameter to True/False in the dictionary below.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection |
object
|
Connection chosen by the user (Databricks SQL Connect, PYODBC SQL Connect, TURBODBC SQL Connect) |
required |
parameters_dict |
dict
|
A dictionary of parameters (see Attributes table below) |
required |
Attributes:
Name | Type | Description |
---|---|---|
business_unit |
str
|
Business unit |
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 |
start_date |
str
|
Start date (Either a utc date in the format YYYY-MM-DD or a utc datetime in the format YYYY-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 utc date in the format YYYY-MM-DD or a utc datetime in the format YYYY-MM-DDTHH:MM:SS or specify the timezone offset in the format YYYY-MM-DDTHH:MM:SS+zz:zz) |
window_size_mins |
int
|
Window size in minutes |
window_length |
int
|
(Optional) add longer window time for the start or end of specified date to cater for edge cases |
include_bad_data |
bool
|
Include "Bad" data points with True or remove "Bad" data points with False |
step |
str
|
data points with step "enabled" or "disabled". The options for step are "metadata", "true" or "false". "metadata" will get the step requirements from the metadata table if applicable. |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
pd.DataFrame
|
A dataframe containing the time weighted averages. |
Source code in src/sdk/python/rtdip_sdk/queries/time_series/time_weighted_average.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
Example
from rtdip_sdk.authentication.azure import DefaultAuth
from rtdip_sdk.connectors import DatabricksSQLConnection
from rtdip_sdk.queries import time_weighted_average
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", #options:["float", "double", "integer", "string"]
"tag_names": ["tag_1", "tag_2"], #list of tags
"start_date": "2023-01-01", #start_date can be a date in the format "YYYY-MM-DD" or a datetime in the format "YYYY-MM-DDTHH:MM:SS" or specify the timezone offset in the format "YYYY-MM-DDTHH:MM:SS+zz:zz"
"end_date": "2023-01-31", #end_date can be a date in the format "YYYY-MM-DD" or a datetime in the format "YYYY-MM-DDTHH:MM:SS" or specify the timezone offset in the format "YYYY-MM-DDTHH:MM:SS+zz:zz"
"window_size_mins": 15, #numeric input
"window_length": 20, #numeric input
"include_bad_data": True, #options: [True, False]
"step": True
}
x = time_weighted_average.get(connection, parameters)
print(x)
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()
.
Note
server_hostname
and http_path
can be found on the SQL Warehouses Page.