Difference between revisions of "Functions"

From webCoRE Wiki - Web-enabled Community's own Rule Engine
Jump to: navigation, search
Line 1: Line 1:
;Boolean
+
== Boolean ==
:bool()
+
;bool()
:boolean()
+
://todo
:contains('The quick brown fox jumped over the lazy dog', 'brown') - tests parameter 1 for parameter 2 as any word (case sensitive)
+
;boolean(anything)
:endsWith('The quick brown fox jumped over the lazy dog', 'brown') - tests parameter 1 for parameter 2 as the last word (case sensitive)
+
:converts a value to it's boolean value
:eq('123', '321') - checks if both parameters are equal.  This will return false
+
;contains(string, substring)
:ge(1000, 900) - Checks if parameter 1 is greater than or equal to parameter 2.  This will return true.
+
:returns true if a string contains a substring
:gt(1000, 900) - Checks if parameter 1 is greater than parameter 2.  This will return true.
+
;endsWith(string, substring)
:isEmpty()
+
:returns true if a string ends with a substring
:le(1000, 900) - Checks if parameter 1 is less than or equal to parameter 2. This will return false.
+
;eq(value1, value2)
:lt(1000, 900) - Checks if parameter 1 is less than parameter 2. This will return false.
+
:returns true if two values are equal
:not()
+
;ge(value1, value2)
:startsWith('The quick brown fox jumped over the lazy dog', 'brown') - tests parameter 1 for parameter 2 as the first word (case sensitive)
+
:returns true if value1 >= value2
 +
;gt(value1, value2)
 +
:returns true if value1 > value2
 +
;isBetween(value, startValue, endValue)
 +
:returns true if value >= startValue and value <= endValue
 +
;isEmpty(value)
 +
:returns true if the value is empty
 +
;le(value1, value2)
 +
:returns true if value1 <= value2
 +
;lt(value1, value2)
 +
:returns true if value1 < value2
 +
;not(value)
 +
:returns the negative boolean value
 +
;startsWith(string, substring)
 +
:returns true if a string starts with a substring
  
;Date
+
== Date ==
:date()
+
;date(value)
 +
:returns the value as a date type
  
;datetime
+
== datetime ==
:addDays()
+
;addDays(dateTime, days)
:addHours()
+
:returns the value as a time type
:addMinutes()
+
;addHours(dateTime, hours)
:addSeconds()
+
:returns the value as a time type
:addWeeks()
+
;addMinutes(dateTime, minutes)
 +
:returns the value as a time type
 +
;addSeconds(dateTime, seconds)
 +
:returns the value as a time type
 +
;addWeeks(dateTime, weeks)
 +
:returns the value as a time type
  
;Decimal
+
== Decimal ==
:avg([Device 1:temperature], [Device2:temperature], [Device 3:temperature]) - Gives you the average temperature of the three devices
+
;avg(values)
:ceil()
+
:calculates the average of a series of numeric values
:ceiling()
+
;ceil()
:celsius([Sensor:temperature]) - Gives the temperature reading in celsius
+
://todo
:decimal()
+
;ceiling(decimal or string)
:dewPoint([Sensor:temperature], [Sensor:humidity]) - Gives you the dewpoint temperature for that sensor
+
:converts a decimal value to it's closest higher integer value
:fahrenheit([Sensor:temperature]) - Gives the temperature reading in fahrenheit
+
;celsius(temperature)  
:float()
+
:converts temperature from Fahrenheit to Celsius
:floor()
+
;decimal(integer or string)
:max([Front Door :temperature], [Back Door :temperature], [test sensor :temperature]) - Returns the max value of selected devices
+
:converts an integer value to it's decimal value
:median([Front Door :temperature], [Back Door :temperature], [test sensor :temperature]) - Returns the median value of selected devices
+
;dewPoint(temperature, relativeHumidity[, scale])
:min([Front Door :temperature], [Back Door :temperature], [test sensor :temperature]) - Returns the min value of selected devices
+
:returns the calculated dew point temperature
:number()
+
;fahrenheit([Sensor;temperature])  
:power(10,3) - Evaluates parameter 1 to the parameter 2 power (e.g. 10*10*10 = 1000)
+
:converts temperature from Celsius to Fahrenheit
:round(75.6548, 1) -  Rounds a decimal based on value of parameter 2.  This will return 75.7
+
;float()
:sqr(100) - Gives the squared value of the parameter.  This returns 10000
+
://todo
:sqrt(100) - Gives the square root of the parameter.  This returns 10.0
+
;floor(decimal or string)
:stdev()
+
:converts a decimal value to it's closest lower integer value
:sum(1,5,6) - Adds all the values  
+
;max(values)
:variance()
+
:calculates the maximum of a series of numeric values
 +
;median(values)
 +
:returns the value in the middle of a sorted array
 +
;min(values)
 +
:calculates the minimum of a series of numeric values
 +
;number()
 +
://todo
 +
;power(integer or decimal or string, power)  
 +
:converts a decimal value to it's power decimal value
 +
;round(decimal or string, [precision])  
 +
:converts a decimal value to it's rounded value
 +
;sqr(integer or decimal or string)  
 +
:converts a decimal value to it's square decimal value
 +
;sqrt(integer or decimal or string)  
 +
:converts a decimal value to it's square root decimal value
 +
;stdev(values)
 +
:calculates the standard deviation of a series of numeric values
 +
;sum(values)
 +
:calculates the sum of a series of numeric values
 +
;variance(values)
 +
:calculates the standard deviation of a series of numeric values
  
;Dynamic
+
== Dynamic ==
:if()
+
;if(condition, valueIfTrue, valueIfFalse)
:least()
+
:evaluates a boolean and returns value1 if true, or value2 otherwise
:most()
+
;least(values)
:previousValue()
+
: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
+
== Integers ==
:age([Device:switch) - Gives you the time in MS the device has been on
+
;age([device;attribute])
:count([Device 1:contact], [Device 2:contact], [Device 3:contact], [Device 4:contact]) - Returns the number of open doors
+
:returns the number of milliseconds an attribute had the current value
:int()
+
;count(values)
:integer()
+
:calculates the number of true/non-zero/non-empty items in a series of numeric values
:newer()
+
;int()
:older()
+
://todo
:previousAge()
+
;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
  
;String
+
== String ==
:concat('abc', 'def') - Returns the two strings as 'abcdef'
+
;concat(string1, string2)  
:format("%.2f", celsius([Sensor:temperature])) - Returns the Celsius temperature formatted with two decimals
+
:returns two strings appended together
:left('abcdef', 2) - Returns the first two characters in the string value or variable (ex: 'ab')
+
;format()  
:lower("HELLO, WORLD") - Returns as "hello, world"
+
://todo
:mid('abcdef', 2, 3) - Skips the first 2 characters and returns the next 3
+
;left(string, count)  
:replace()
+
:returns a substring of a value
:right('abcdef', 2) - Returns the last two characters in the string value or variable (ex: 'ef')
+
;lower(string)
:sprintf()
+
:returns a lower case value of a string
:string()
+
;mid(string, start, count)
:substring("abcdef", 2, 4) - Skips the first 2 characters and returns the next 4
+
::returns a substring of a value
:text()
+
;replace(string, search, replace[, [..], search, replace])
:title("hello, world") - Returns as "Hello, World"
+
:replaces a search text inside of a value
:upper("hello, world") - Returns as "HELLO, WORLD"
+
;right(string, count)
 +
:returns a substring of a value
 +
;sprintf(format, arguments)
 +
:formats a series of values into a string
 +
;string(anything)
 +
:converts a value to it's string value
 +
;substring(string, start, count)
 +
:returns a substring of a value
 +
;text()
 +
://todo
 +
;title(string)
 +
:returns a title case value of a string
 +
;upper(string)
 +
:returns an upper case value of a string
  
;Time
+
== Time ==
time()
+
;time(value)
 +
:returns the value as a time type

Revision as of 22:46, 15 April 2017

Boolean

bool()
//todo
boolean(anything)
converts a value to it's boolean value
contains(string, substring)
returns true if a string contains a substring
endsWith(string, substring)
returns true if a string ends with a substring
eq(value1, value2)
returns true if two values are equal
ge(value1, value2)
returns true if value1 >= value2
gt(value1, value2)
returns true if value1 > value2
isBetween(value, startValue, endValue)
returns true if value >= startValue and value <= endValue
isEmpty(value)
returns true if the value is empty
le(value1, value2)
returns true if value1 <= value2
lt(value1, value2)
returns true if value1 < value2
not(value)
returns the negative boolean value
startsWith(string, substring)
returns true if a string starts with a substring

Date

date(value)
returns the value as a date type

datetime

addDays(dateTime, days)
returns the value as a time type
addHours(dateTime, hours)
returns the value as a time type
addMinutes(dateTime, minutes)
returns the value as a time type
addSeconds(dateTime, seconds)
returns the value as a time type
addWeeks(dateTime, weeks)
returns the value as a time type

Decimal

avg(values)
calculates the average of a series of numeric values
ceil()
//todo
ceiling(decimal or string)
converts a decimal value to it's closest higher integer value
celsius(temperature)
converts temperature from Fahrenheit to Celsius
decimal(integer or string)
converts an integer value to it's decimal value
dewPoint(temperature, relativeHumidity[, scale])
returns the calculated dew point temperature
fahrenheit([Sensor;temperature])
converts temperature from Celsius to Fahrenheit
float()
//todo
floor(decimal or string)
converts a decimal value to it's closest lower integer value
max(values)
calculates the maximum of a series of numeric values
median(values)
returns the value in the middle of a sorted array
min(values)
calculates the minimum of a series of numeric values
number()
//todo
power(integer or decimal or string, power)
converts a decimal value to it's power decimal value
round(decimal or string, [precision])
converts a decimal value to it's rounded value
sqr(integer or decimal or string)
converts a decimal value to it's square decimal value
sqrt(integer or decimal or string)
converts a decimal value to it's square root decimal value
stdev(values)
calculates the standard deviation of a series of numeric values
sum(values)
calculates the sum of a series of numeric values
variance(values)
calculates the standard deviation of a series of numeric values

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

String

concat(string1, string2)
returns two strings appended together
format()
//todo
left(string, count)
returns a substring of a value
lower(string)
returns a lower case value of a string
mid(string, start, count)
returns a substring of a value
replace(string, search, replace[, [..], search, replace])
replaces a search text inside of a value
right(string, count)
returns a substring of a value
sprintf(format, arguments)
formats a series of values into a string
string(anything)
converts a value to it's string value
substring(string, start, count)
returns a substring of a value
text()
//todo
title(string)
returns a title case value of a string
upper(string)
returns an upper case value of a string

Time

time(value)
returns the value as a time type