Posted On: Jan 12, 2021
AWS IoT SiteWise now supports usage of methods in formula expressions through Uniform Function Call Syntax (UFCS).
Users could earlier define expressions for transforms and metrics in AWS IoT SiteWise using nested functions, but starting today, they can also do so by chaining method calls with the UFCS feature. This syntax helps with readability and traceability of complex formulae for metrics and transforms in the AWS IoT SiteWise asset model. UFCS can be used with all current function types supported in AWS IoT SiteWise — common, comparison, conditional, string, aggregation and temporal functions. UFCS can be used in the AWS IoT SiteWise console or Command Line Interface (CLI). To learn more about UFCS and function types, visit AWS IoT SiteWise formula expressions.
The UFCS feature allows users to reference any function available in AWS IoT SiteWise today f(n) as n.f() using method calls. More generally, users can replace functions f(a,b,c...) using the syntax for method chaining as a.f(b,c..) where ‘a’ can be a variable or in itself a function a= f1(x). As a sample customer use case, if a user wants to define a metric that returns the log of a cosine function, log(cos(a)), they can now express it as cos(a).log() using UFCS. AWS IoT SiteWise also supports chaining of if-else functions using UFCS, making it easier to define and trace multiple levels of nested conditional logic. As a generic format, a nested if statement earlier written as:
if(condition1, on_true_1, if(condition2, on_true_2, on_false_2))
can now also be written using if-elif nesting under UFCS format as:
if(condition1, on_true_1). elif(condition2, on_true_2, on_false_2)
As an example, if a renewable energy site operator wants to test if the power output of a solar panel is within a certain range (1-4 kilowatt), they have the flexibility to encode it in two ways- efficiency= if(power.lt(1000),0).elif(power.gt(4000),0,1) using UFCS or if(lt(power, 1000), 0, if(gt(power,4000), 0,1)) using nested functions. In addition, UFCS can be used for method chaining with string operations. For example, a user can detect equipment status in a JSON message as status= contains(lower(jp(message, ‘$.status’)),‘fail’) using nested functions, or status= message.jp(‘$.status’).lower().contains(‘fail’) using the UFCS syntax. This allows for better traceability and troubleshooting in computations with multiple functions.