Make your calculations more robust by using Attributes instead of hard coding values in the expressions
When writing an expression it is not a good idea to hard code things like upper/lower limits, time ranges, and other parameters. This is a great use for Child-Attributes. Hardcoding values in expressions only achieves two things: it is faster now and gets you in potential trouble later. It also does not provide for easy visibility and ability to change parameters based on different assets. For example, there might be different control limits on different pumps. The examples below show how to pass time ranges, and upper/lower control limits to expressions.
Passing time parameters:
In this example, I want to calculate the average value of the Volume Attribute over a time range that will be different for different Elements. To do this, create Attributes in the Template
to retrieve the EndTime, StartTime, and OffSet from a PI AF Table, which will return different values based on the Element in question.
Below are two equivalent expressions to calculate the average value of the Volume Attribute; one uses the EndTime and OffSet Attributes, and the other uses the EndTime and StartTime Attributes.
Note: you need to use the ParseTime() function to convert the Attribute values, which are of value type String, to a time format.
If you were to hardcode the times it would look like the HardCoded Variable in the Figure below.
Note: you do not use the ParseTime() function in this case, you just type in the strings in between the single quotation signs. As I stated before, I strongly discourage you to use this approach unless you are absolutely certain that you will not want to change the time range and that it will not vary between different Elements.
Passing control limits parameters:
The Child-Attributes are best used for items like PI Tag name, control limits, specifications, etc. that relate to the Parent-Attribute. To do this create Child-Attributes called Maximum and Minimum under the Mass Attribute, and configure them to retrieve the Maximum and Minimum from a PI AF Table, which will return different values
based on the Element in question.
Easiest thing to do when writing the Analysis is to create Variables that get the value from the Child-Attributes and then use these Variables in the evaluation of the operational status of the Element. When you start typing the name of the Child-Attribute, the Intellisense does not display the Child-Attributes. So you need to type the Child-Attributes yourself using the |
symbol, in this case ‘Mass|Maximum’ and ‘Mass|Minimum’.
You can also use the Attributes at the bottom right of the analysis by selecting the Attribute and clicking Relative. This inserts the Child-Attribute name into the variable as shown below.