Difference between revisions of "Functions"
From webCoRE Wiki - Web-enabled Community's own Rule Engine
								
												
				| Line 1: | Line 1: | ||
Functions are extensions to expressions that allow data processing and conversion. Here is a list of all defined functions  | Functions are extensions to expressions that allow data processing and conversion. Here is a list of all defined functions  | ||
| + | |||
| + | |||
| + | =[[Variable_data_types#String|String]] functions=  | ||
| + | |||
| + | ==concat==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' concat(''dynamic'' value1, ''dynamic'' value2[, .., ''dynamic'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns a string that is the concatenation of all the supplied values. This function accepts two or more input values.  | ||
| + | |||
| + | ==contains==  | ||
| + | :Syntax  | ||
| + | ::<code>''boolean'' contains(''string'' haystack, ''string'' needle)</code>  | ||
| + | :Returns  | ||
| + | ::Returns true if the <code>needle</code> is found anywhere in the <code>haystack</code>  | ||
| + | |||
| + | ==endsWith==  | ||
| + | :Syntax  | ||
| + | ::<code>''boolean'' endsWith(''string'' haystack, ''string'' needle)</code>  | ||
| + | :Returns  | ||
| + | ::Returns true if <code>haystack</code> ends with the <code>needle</code>  | ||
| + | |||
| + | ==format==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' format(''string'' formatString[, ''dynamic'' value1[, .., ''dynamic'' valueN]])</code>  | ||
| + | :Returns  | ||
| + | ::Returns a string that is built based on the <code>formatString</code> with arguments replaced by their corresponding values. Follows the java syntax for <code>printf()</code>. See a quick reference [https://www.cs.colostate.edu/~cs160/.Summer16/resources/Java_printf_method_quick_reference.pdf here], or a more detailed reference [https://sharkysoft.com/archive/printf/docs/javadocs/lava/clib/stdio/doc-files/specification.htm Reference here].  | ||
| + | ::Each % in the format string represents an argument and corresponds to a value (in order of appearance) in the value list. Each argument can have formatting settings, according to the reference provided.   | ||
| + | :Example  | ||
| + | ::<code>format('The temperature outside is %.2f degrees Fahrenheit', [Temp sensor:temperature])</code> outputs <code>The temperature outside is 71.26 degrees Fahrenheit</code>  | ||
| + | ::The <code>%.2f</code> translates to "format as <code>f</code>loat and use <code>.2</code> decimal places.  | ||
| + | |||
| + | ==left==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' left(''string'' value, ''integer'' length)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the first <code>length</code> characters in <code>value</code>  | ||
| + | :Examples  | ||
| + | ::<code>left("hello world", 2)</code> outputs <code>he</code>  | ||
| + | |||
| + | ==lower==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' lower(''string'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the <code>value</code> but with all lower case letters.  | ||
| + | :Examples  | ||
| + | ::<code>lower("Hello World")</code> outputs <code>hello world</code>  | ||
| + | |||
| + | ==mid==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' mid(''string'' value, ''integer'' start[, ''integer'' count = remaining])</code>  | ||
| + | :Arguments  | ||
| + | ::<code>start</code> - provides the 0-based index of the first character to copy. If <code>start</code> is negative, the counting starts from the end of <code>value</code>.  | ||
| + | ::<code>count</code> - provides the number of characters to copy from <code>value</code>. If not provided, all of the remaining characters from <code>value</code> are returned, starting with character number <code>start</code>. If <code>count</code> is negative, prior characters are returned.  | ||
| + | :Returns  | ||
| + | ::Returns a substring of <code>value</code>, <code>count</code> characters long, starting at character number <code>start</code>. Note that the first character in any string has index 0.  | ||
| + | :Examples  | ||
| + | ::<code>mid("Hello World", 2, 3)</code> outputs <code>llo</code>  | ||
| + | ::<code>mid("Hello World", 2)</code> outputs <code>llo World</code>  | ||
| + | ::<code>mid("Hello World", -5, 2)</code> outputs <code>Wo</code>  | ||
| + | ::<code>mid("Hello World", -1, -3)</code> outputs <code>orl</code>  | ||
| + | |||
| + | ==replace==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' replace(''string'' haystack, ''string'' needle1, ''string'' replacement1[, .., ''string'' needleN, ''string'' replacementN])</code>  | ||
| + | :Returns  | ||
| + | ::Replaces all the occurrences of <code>needle</code> inside <code>haystack</code> with its respective <code>replacement</code>. Multiple pairs of <code>needle</code>/<code>replacement</code> can be provided in one function call.  | ||
| + | :Regular expressions  | ||
| + | ::Needles support regular expressions when their value starts and ends with a <code>/</code>. For example, <code>'/(\s)/'</code> will match all spaces.  | ||
| + | :Examples  | ||
| + | ::<code>replace("Hello World", 'World', 'Earth')</code> outputs <code>Hello Earth</code>  | ||
| + | ::<code>replace("Hello World", 'World', 'Earth', 'Hello', 'Hi')</code> outputs <code>Hi Earth</code>  | ||
| + | ::<code>replace("Hello World", 'World', 'Earth', 'Earth', 'Planet')</code> outputs <code>Hello Planet</code>  | ||
| + | |||
| + | ==right==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' right(''string'' value, ''integer'' length)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the last <code>length</code> characters in <code>value</code>  | ||
| + | :Examples  | ||
| + | ::<code>right("hello world", 4)</code> outputs <code>orld</code>  | ||
| + | |||
| + | ==startsWith==  | ||
| + | :Syntax  | ||
| + | ::<code>''boolean'' startsWith(''string'' haystack, ''string'' needle)</code>  | ||
| + | :Returns  | ||
| + | ::Returns true if <code>haystack</code> starts with the <code>needle</code>  | ||
| + | |||
| + | ==string==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' string(''dynamic'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns <code>value</code> as a string.  | ||
| + | |||
| + | ==substr==  | ||
| + | :Alias of <code>mid()</code>  | ||
| + | |||
| + | ==substring==  | ||
| + | :Alias of <code>mid()</code>  | ||
| + | |||
| + | ==title==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' title(''string'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the <code>value</code> but in its title case format (each word starts with a capitalized letter).  | ||
| + | :Examples  | ||
| + | ::<code>lower("Hello there world")</code> outputs <code>Hello There World</code>  | ||
| + | |||
| + | ==upper==  | ||
| + | :Syntax  | ||
| + | ::<code>''string'' upper(''string'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the <code>value</code> but with all upper case letters.  | ||
| + | :Examples  | ||
| + | ::<code>lower("Hello World")</code> outputs <code>HELLO WORLD</code>  | ||
| + | |||
| + | ==text==  | ||
| + | :Alias of <code>string()</code>  | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | =Numeric functions=  | ||
| + | |||
| + | ==avg==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' avg(''decimal'' value1, ''decimal'' value2[, .., ''decimal'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the mean average of all the values provided.  | ||
| + | |||
| + | ==ceil==  | ||
| + | :Syntax  | ||
| + | ::<code>''integer'' ceil(''decimal'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the integer part of a decimal, equivalent to rounding the decimal down.  | ||
| + | |||
| + | ==ceiling==  | ||
| + | :Alias of <code>ceil</code>  | ||
| + | |||
| + | ==decimal==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' decimal(''dynamic'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Converts <code>value</code> into a decimal. Returns <code>0</code> if <code>value</code> is not numeric.  | ||
| + | |||
| + | ==float==  | ||
| + | :Alias of <code>decimal</code>  | ||
| + | |||
| + | ==floor==  | ||
| + | :Syntax  | ||
| + | ::<code>''integer'' ceil(''decimal'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the immediately higher integer, equivalent to rounding the decimal up.  | ||
| + | |||
| + | ==max==  | ||
| + | :Syntax  | ||
| + | ::<code>''dynamic'' max(''dynamic'' value1, ''dynamic'' value2[, .., ''dynamic'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the maximum of all the values provided. Note: this function works with both numbers and strings.  | ||
| + | |||
| + | ==median==  | ||
| + | :Syntax  | ||
| + | ::<code>''dynamic'' median(''dynamic'' value1, ''dynamic'' value2[, .., ''dynamic'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the median average of all the values provided. Note: this function works with both numbers and strings.  | ||
| + | |||
| + | ==min==  | ||
| + | :Syntax  | ||
| + | ::<code>''dynamic'' min(''dynamic'' value1, ''dynamic'' value2[, .., ''dynamic'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the minimum of all the values provided. Note: this function works with both numbers and strings.  | ||
| + | |||
| + | ==number==  | ||
| + | :Alias of <code>decimal</code>  | ||
| + | |||
| + | ==power==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' power(''decimal'' value, ''decimal'' exponent)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the <code>value</code> at the power of <code>exponent</code>  | ||
| + | |||
| + | ==round==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' round(''decimal'' value[, ''integer'' precision = 0])</code>  | ||
| + | :Arguments  | ||
| + | ::<code>precision</code> - the number of decimal places to be retained. If not provided, defaults to <code>0</code>  | ||
| + | :Returns  | ||
| + | ::Returns the rounded <code>value</code> with <code>precision</code> decimal places.  | ||
| + | |||
| + | ==sqr==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' sqr(''decimal'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the squared <code>value</code>, equivalent to <code>value</code> multiplied by itself.  | ||
| + | |||
| + | ==sqrt==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' sqrt(''decimal'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Returns the square root of <code>value</code>.  | ||
| + | |||
| + | ==stdev==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' stdev(''decimal'' value1, ''decimal'' value2[, .., ''decimal'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the standard deviation of all the values provided.  | ||
| + | |||
| + | ==sum==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' sum(''decimal'' value1, ''decimal'' value2[, .., ''decimal'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the sum of sum of all the values provided.  | ||
| + | |||
| + | ==variance==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' variance(''decimal'' value1, ''decimal'' value2[, .., ''decimal'' valueN])</code>  | ||
| + | :Returns  | ||
| + | ::Returns the variance of all the values provided.  | ||
| + | |||
| + | |||
| + | |||
| + | |||
=[[Variable_data_types#Boolean|Boolean]] functions=  | =[[Variable_data_types#Boolean|Boolean]] functions=  | ||
| Line 60: | Line 283: | ||
::Returns the negated truth state of <code>value</code>. This is the logical negation of <code>[[Functions#bool|bool]](''dynamic'' value)</code>.  | ::Returns the negated truth state of <code>value</code>. This is the logical negation of <code>[[Functions#bool|bool]](''dynamic'' value)</code>.  | ||
| − | =[[Variable_data_types#  | + | =[[Variable_data_types#Date_and_Time|Date and time]] functions=  | 
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
==addDays==  | ==addDays==  | ||
| Line 100: | Line 315: | ||
::Returns a datetime that is <code>weeks</code> weeks after the <code>value</code>. For negative values of <code>weeks</code>, it returns a datetime that is <code>weeks</code> weeks before <code>value</code>.  | ::Returns a datetime that is <code>weeks</code> weeks after the <code>value</code>. For negative values of <code>weeks</code>, it returns a datetime that is <code>weeks</code> weeks before <code>value</code>.  | ||
| − | =   | + | ==date==  | 
| − | + | :Syntax  | |
| − | :  | + | ::<code>date(''datetime'' value)</code>  | 
| − | + | :Returns  | |
| − | :  | + | ::Returns the date portion of <code>value</code> by stripping off time information.  | 
| − | + | ||
| − | :  | + | ==datetime==  | 
| − | + | :Syntax  | |
| − | :  | + | ::<code>''datetime'' datetime(''dynamic'' value)</code>  | 
| − | + | :Returns  | |
| − | + | ::Tries to convert any value into a datetime. Accepts strings in common date/time formats.  | |
| − | + | ||
| − | :  | + | |
| − | + | ==formatDuration==  | |
| − | :  | + | :Syntax  | 
| − | + | ::<code>''string'' formatDuration(''datetime'' value[, ''boolean'' friendly = false[, ''string'' granularity = 's'[, ''boolean'' showAdverbs = false]]])</code>  | |
| − | ://  | + | :Arguments  | 
| − | + | ::<code>friendly</code> - <code>false</code> makes the output compact, in the form of <code>0d 00:00:00.000</code>, while <code>true</code> makes the output more human friendly, in the form of <code> 0 days, 0 hours, 0 minutes, and 0 seconds</code>. Defaults to <code>false</code>.  | |
| − | + | ::<code>granularity</code> - represents the smallest time unit to be output. One of <code>d</code> for days, <code>h</code> for hours, <code>m</code> for minutes, <code>s</code> for seconds, or <code>ms</code> for milliseconds. Any time unit below the selected granularity will not be output. Defaults to <code>s</code>  | |
| − | + | ::<code>showAdverbs</code> - only affects the friendly output, when <code>true</code> the words <code>in</code> (for future durations - positive input) or <code>ago</code> (for past durations - negative input) are prepended or appended respectively to the output  | |
| − | :  | + | :Returns  | 
| − | + | ::Returns a string that represents the duration in a human readable format  | |
| − | :  | + | :Examples  | 
| − | + | ::<code>formatDuration(12029)</code> will output <code>00:00:12</code>  | |
| − | :  | + | ::<code>formatDuration(68493, true)</code> will output <code>1 minute and 8 seconds</code>  | 
| − | + | ::<code>formatDuration(68493, false, 'ms')</code> will output <code>00:01:08</code>  | |
| − | ://  | + | ::<code>formatDuration(68493, true, 'm', true)</code> will output <code>in 1 minute</code>  | 
| − | + | ||
| − | :  | + | ==time==  | 
| − | + | :Syntax  | |
| − | :  | + | ::<code>''time'' time(''datetime'' value)</code>  | 
| − | + | :Returns  | |
| − | :  | + | ::Returns the time portion of <code>value</code> by stripping off date information.  | 
| − | + | ||
| − | :  | + | |
| − | + | ||
| − | :  | + | =Weather related functions=  | 
| − | + | ||
| − | :  | + | ==celsius==  | 
| − | + | :Syntax  | |
| − | :  | + | ::<code>''decimal'' celsius(''decimal'' value)</code>  | 
| + | :Returns  | ||
| + | ::Converts a temperature value from Fahrenheit to Celsius.  | ||
| + | |||
| + | ==dewPoint==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' dewPoint(''decimal'' temperature, ''decimal'' relativeHumidity[, ''string'' scale = 'F'])</code>  | ||
| + | :Parameters  | ||
| + | ::<code>scale</code> - optional, one of <code>C</code> or <code>F</code>, corresponding to the temperature range used for <code>temperature</code>. The result will be provided in the same scale. If no scale is provided, the Fahrenheit scale will be used.  | ||
| + | :Returns  | ||
| + | ::Returns the due temperature for a given temperature and relative humidity  | ||
| + | |||
| + | ==fahrenheit==  | ||
| + | :Syntax  | ||
| + | ::<code>''decimal'' fahrenheit(''decimal'' value)</code>  | ||
| + | :Returns  | ||
| + | ::Converts a temperature value from Celsius to Fahrenheit.  | ||
| + | |||
| + | |||
= [[Variable_data_types#Dynamic|Dynamic]] =  | = [[Variable_data_types#Dynamic|Dynamic]] =  | ||
| Line 168: | Line 401: | ||
:returns the number of milliseconds an attribute had the previous value  | :returns the number of milliseconds an attribute had the previous value  | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
= [[Variable_data_types#Time|Time]] =  | = [[Variable_data_types#Time|Time]] =  | ||
Revision as of 16:44, 6 May 2017
Functions are extensions to expressions that allow data processing and conversion. Here is a list of all defined functions
Contents
String functions
concat
- Syntax
string concat(dynamic value1, dynamic value2[, .., dynamic valueN])
 - Returns
- Returns a string that is the concatenation of all the supplied values. This function accepts two or more input values.
 
 
contains
- Syntax
boolean contains(string haystack, string needle)
 - Returns
- Returns true if the 
needleis found anywhere in thehaystack 
 - Returns true if the 
 
endsWith
- Syntax
boolean endsWith(string haystack, string needle)
 - Returns
- Returns true if 
haystackends with theneedle 
 - Returns true if 
 
format
- Syntax
string format(string formatString[, dynamic value1[, .., dynamic valueN]])
 - Returns
- Returns a string that is built based on the 
formatStringwith arguments replaced by their corresponding values. Follows the java syntax forprintf(). See a quick reference here, or a more detailed reference Reference here. - Each % in the format string represents an argument and corresponds to a value (in order of appearance) in the value list. Each argument can have formatting settings, according to the reference provided.
 
 - Returns a string that is built based on the 
 - Example
format('The temperature outside is %.2f degrees Fahrenheit', [Temp sensor:temperature])outputsThe temperature outside is 71.26 degrees Fahrenheit- The 
%.2ftranslates to "format asfloat and use.2decimal places. 
 
left
- Syntax
string left(string value, integer length)
 - Returns
- Returns the first 
lengthcharacters invalue 
 - Returns the first 
 - Examples
left("hello world", 2)outputshe
 
lower
- Syntax
string lower(string value)
 - Returns
- Returns the 
valuebut with all lower case letters. 
 - Returns the 
 - Examples
lower("Hello World")outputshello world
 
mid
- Syntax
string mid(string value, integer start[, integer count = remaining])
 - Arguments
start- provides the 0-based index of the first character to copy. Ifstartis negative, the counting starts from the end ofvalue.count- provides the number of characters to copy fromvalue. If not provided, all of the remaining characters fromvalueare returned, starting with character numberstart. Ifcountis negative, prior characters are returned.
 - Returns
- Returns a substring of 
value,countcharacters long, starting at character numberstart. Note that the first character in any string has index 0. 
 - Returns a substring of 
 - Examples
mid("Hello World", 2, 3)outputsllomid("Hello World", 2)outputsllo Worldmid("Hello World", -5, 2)outputsWomid("Hello World", -1, -3)outputsorl
 
replace
- Syntax
string replace(string haystack, string needle1, string replacement1[, .., string needleN, string replacementN])
 - Returns
- Replaces all the occurrences of 
needleinsidehaystackwith its respectivereplacement. Multiple pairs ofneedle/replacementcan be provided in one function call. 
 - Replaces all the occurrences of 
 - Regular expressions
- Needles support regular expressions when their value starts and ends with a 
/. For example,'/(\s)/'will match all spaces. 
 - Needles support regular expressions when their value starts and ends with a 
 - Examples
replace("Hello World", 'World', 'Earth')outputsHello Earthreplace("Hello World", 'World', 'Earth', 'Hello', 'Hi')outputsHi Earthreplace("Hello World", 'World', 'Earth', 'Earth', 'Planet')outputsHello Planet
 
right
- Syntax
string right(string value, integer length)
 - Returns
- Returns the last 
lengthcharacters invalue 
 - Returns the last 
 - Examples
right("hello world", 4)outputsorld
 
startsWith
- Syntax
boolean startsWith(string haystack, string needle)
 - Returns
- Returns true if 
haystackstarts with theneedle 
 - Returns true if 
 
string
- Syntax
string string(dynamic value)
 - Returns
- Returns 
valueas a string. 
 - Returns 
 
substr
- Alias of 
mid() 
substring
- Alias of 
mid() 
title
- Syntax
string title(string value)
 - Returns
- Returns the 
valuebut in its title case format (each word starts with a capitalized letter). 
 - Returns the 
 - Examples
lower("Hello there world")outputsHello There World
 
upper
- Syntax
string upper(string value)
 - Returns
- Returns the 
valuebut with all upper case letters. 
 - Returns the 
 - Examples
lower("Hello World")outputsHELLO WORLD
 
text
- Alias of 
string() 
Numeric functions
avg
- Syntax
decimal avg(decimal value1, decimal value2[, .., decimal valueN])
 - Returns
- Returns the mean average of all the values provided.
 
 
ceil
- Syntax
integer ceil(decimal value)
 - Returns
- Returns the integer part of a decimal, equivalent to rounding the decimal down.
 
 
ceiling
- Alias of 
ceil 
decimal
- Syntax
decimal decimal(dynamic value)
 - Returns
- Converts 
valueinto a decimal. Returns0ifvalueis not numeric. 
 - Converts 
 
float
- Alias of 
decimal 
floor
- Syntax
integer ceil(decimal value)
 - Returns
- Returns the immediately higher integer, equivalent to rounding the decimal up.
 
 
max
- Syntax
dynamic max(dynamic value1, dynamic value2[, .., dynamic valueN])
 - Returns
- Returns the maximum of all the values provided. Note: this function works with both numbers and strings.
 
 
median
- Syntax
dynamic median(dynamic value1, dynamic value2[, .., dynamic valueN])
 - Returns
- Returns the median average of all the values provided. Note: this function works with both numbers and strings.
 
 
min
- Syntax
dynamic min(dynamic value1, dynamic value2[, .., dynamic valueN])
 - Returns
- Returns the minimum of all the values provided. Note: this function works with both numbers and strings.
 
 
number
- Alias of 
decimal 
power
- Syntax
decimal power(decimal value, decimal exponent)
 - Returns
- Returns the 
valueat the power ofexponent 
 - Returns the 
 
round
- Syntax
decimal round(decimal value[, integer precision = 0])
 - Arguments
precision- the number of decimal places to be retained. If not provided, defaults to0
 - Returns
- Returns the rounded 
valuewithprecisiondecimal places. 
 - Returns the rounded 
 
sqr
- Syntax
decimal sqr(decimal value)
 - Returns
- Returns the squared 
value, equivalent tovaluemultiplied by itself. 
 - Returns the squared 
 
sqrt
- Syntax
decimal sqrt(decimal value)
 - Returns
- Returns the square root of 
value. 
 - Returns the square root of 
 
stdev
- Syntax
decimal stdev(decimal value1, decimal value2[, .., decimal valueN])
 - Returns
- Returns the standard deviation of all the values provided.
 
 
sum
- Syntax
decimal sum(decimal value1, decimal value2[, .., decimal valueN])
 - Returns
- Returns the sum of sum of all the values provided.
 
 
variance
- Syntax
decimal variance(decimal value1, decimal value2[, .., decimal valueN])
 - Returns
- Returns the variance of all the values provided.
 
 
Boolean functions
bool
- Syntax
bool(dynamic value)
 - Returns
- Returns the truth value of the input. Accepts anything as input and will return true if 
valueis either a non-zero number, a non-empty string (with some exceptions, see below), a non-empty device list, a non-empty date/time/datetime 
 - Returns the truth value of the input. Accepts anything as input and will return true if 
 
boolean
- This is an alias of bool
 
eq
- Syntax
eq(dynamic value1, dynamic value2)
 - Returns
- Returns true if 
value1is equivalent tovalue2 
 - Returns true if 
 
ge
- Syntax
ge(dynamic value1, dynamic value2)
 - Returns
- Returns true if 
value1is greater than or equal tovalue2 
 - Returns true if 
 
gt
- Syntax
gt(dynamic value1, dynamic value2)
 - Returns
- Returns true if 
value1is greater thanvalue2 
 - Returns true if 
 
isBetween
- Syntax
isBetween(dynamic value, dynamic startValue, dynamic startValue)
 - Returns
- Returns true if 
valueis greater then or equal tostartValueand less than or equal toendValue 
 - Returns true if 
 
isEmpty
- Syntax
isEmpty(dynamic value)
 - Returns
- Returns true if 
valueis not set, an empty string, or zero 
 - Returns true if 
 
le
- Syntax
le(dynamic value1, dynamic value2)
 - Returns
- Returns true if 
value1is less than or equal tovalue2 
 - Returns true if 
 
lt
- Syntax
lt(dynamic value1, dynamic value2)
 - Returns
- Returns true if 
value1is less thanvalue2 
 - Returns true if 
 
not
- Syntax
not(dynamic value)
 - Returns
- Returns the negated truth state of 
value. This is the logical negation ofbool(dynamic value). 
 - Returns the negated truth state of 
 
Date and time functions
addDays
- Syntax
addDays(datetime value, integer days)
 - Returns
- Returns a datetime that is 
daysdays after thevalue. For negative values ofdays, it returns a datetime that isdaysdays beforevalue. 
 - Returns a datetime that is 
 
addHours
- Syntax
addHours(datetime value, integer hours)
 - Returns
- Returns a datetime that is 
hourshours after thevalue. For negative values ofhours, it returns a datetime that ishourshours beforevalue. 
 - Returns a datetime that is 
 
addMinutes
- Syntax
addMinutes(datetime value, integer minutes)
 - Returns
- Returns a datetime that is 
minutesminutes after thevalue. For negative values ofminutes, it returns a datetime that isminutesminutes beforevalue. 
 - Returns a datetime that is 
 
addSeconds
- Syntax
addSeconds(datetime value, integer seconds)
 - Returns
- Returns a datetime that is 
secondsseconds after thevalue. For negative values ofseconds, it returns a datetime that issecondsseconds beforevalue. 
 - Returns a datetime that is 
 
addWeeks
- Syntax
addWeeks(datetime value, integer weeks)
 - Returns
- Returns a datetime that is 
weeksweeks after thevalue. For negative values ofweeks, it returns a datetime that isweeksweeks beforevalue. 
 - Returns a datetime that is 
 
date
- Syntax
date(datetime value)
 - Returns
- Returns the date portion of 
valueby stripping off time information. 
 - Returns the date portion of 
 
datetime
- Syntax
datetime datetime(dynamic value)
 - Returns
- Tries to convert any value into a datetime. Accepts strings in common date/time formats.
 
 
formatDuration
- Syntax
string formatDuration(datetime value[, boolean friendly = false[, string granularity = 's'[, boolean showAdverbs = false]]])
 - Arguments
friendly-falsemakes the output compact, in the form of0d 00:00:00.000, whiletruemakes the output more human friendly, in the form of0 days, 0 hours, 0 minutes, and 0 seconds. Defaults tofalse.granularity- represents the smallest time unit to be output. One ofdfor days,hfor hours,mfor minutes,sfor seconds, ormsfor milliseconds. Any time unit below the selected granularity will not be output. Defaults tosshowAdverbs- only affects the friendly output, whentruethe wordsin(for future durations - positive input) orago(for past durations - negative input) are prepended or appended respectively to the output
 - Returns
- Returns a string that represents the duration in a human readable format
 
 - Examples
formatDuration(12029)will output00:00:12formatDuration(68493, true)will output1 minute and 8 secondsformatDuration(68493, false, 'ms')will output00:01:08formatDuration(68493, true, 'm', true)will outputin 1 minute
 
time
- Syntax
time time(datetime value)
 - Returns
- Returns the time portion of 
valueby stripping off date information. 
 - Returns the time portion of 
 
celsius
- Syntax
decimal celsius(decimal value)
 - Returns
- Converts a temperature value from Fahrenheit to Celsius.
 
 
dewPoint
- Syntax
decimal dewPoint(decimal temperature, decimal relativeHumidity[, string scale = 'F'])
 - Parameters
scale- optional, one ofCorF, corresponding to the temperature range used fortemperature. The result will be provided in the same scale. If no scale is provided, the Fahrenheit scale will be used.
 - Returns
- Returns the due temperature for a given temperature and relative humidity
 
 
fahrenheit
- Syntax
decimal fahrenheit(decimal value)
 - Returns
- Converts a temperature value from Celsius to Fahrenheit.
 
 
Dynamic
- if(condition, valueIfTrue, valueIfFalse)
 - evaluates a boolean and returns value1 if true, or value2 otherwise
 - least(values)
 - returns the value that is least found a series of numeric values
 - most(values)
 - returns the value that is most found a series of numeric values
 - previousValue([device;attribute])
 - returns the previous value of the attribute
 
Integers
- age([device;attribute])
 - returns the number of milliseconds an attribute had the current value
 - count(values)
 - calculates the number of true/non-zero/non-empty items in a series of numeric values
 - int()
 - //todo
 - integer(decimal or string)
 - converts a decimal value to it's integer value
 - newer([device;attribute],[...], [device;attribute], threshold)
 - returns the number of devices whose attribute had the current value for less than the specified number of milliseconds
 - older([device;attribute],[...], [device;attribute], threshold)
 - returns the number of devices whose attribute had the current value for more than the specified number of milliseconds
 - previousAge([device;attribute])
 - returns the number of milliseconds an attribute had the previous value
 
Time
- time(value)
 - returns the value as a time type
 - addSeconds(dateTime, seconds)
 - adds seconds to time, returns the value as a time type
 - addMinutes(dateTime, minutes)
 - adds minutes to time, returns the value as a time type
 - addHours(dateTime, hours)
 - adds hours to time, returns the value as a time type
 - addDays(dateTime, days)
 - adds days to time, returns the value as a time type
 - addWeeks(dateTime, weeks)
 - adds weeks to time, returns the value as a time type
 


