Computed Attributes of digital entities
Computed attributes represent another possibility to quickly and effortlessly prepare data already during the process of processing them into the WorkSys system. It is a very efficient tool that allows you to asynchronously calculate a value from static or measured fields.
Typical examples of use are e.g. electricity consumption in local currency, where we calculate real financial costs through tariff prices and consumed energy.
It is similar, for example, when calculating OEE – Quality, where we can express the value of the parameter as a percentage through the ratio of qualitatively identical manufactured pieces / number of total manufactured pieces * 100.
You can certainly find other useful examples yourself, and then we will briefly show how to define it in the Entity Type. It is important to remember the basic facts:
- it is applicable for Attributes with a parameter “type” : “computed”
- only Attributes with a parameter can be included in the field calculation “type” : “static” or “type” : “telemetry”
- the values are calculated asynchronously, but they are always added up, so the calculation can sometimes take more than 1-2 seconds
- it is also possible to count with the attributes of other entities, but the condition is that the Entities are in the same logical line (at the same or higher level).
If you use a context Attribute from the current Entity instance and the result of the expression depends on its value and needs to be evaluated every time the value changes, you must add a parameter computed_attributes with a reference to the name of the computed attribute to the definition of the dependent attribute.
The following example describes the calculation of costs in local currency for the Electricity Meter Entity that measures the Total Energy Attribute. The attributes in the “computed_attributes” section determine which Computed fields are to be calculated if a value is entered in the “total_energy” field.
Let’s look at the definitions of the Attributes of the selected fields contained in computed_attributes.
The following example shows the definition of an Attribute with a conversion to kW, also an Attribute contained in computed_attributes.
If necessary, it is also possible to define local variables via the “context” parameter (such as the kilo variable). The calculation formula itself is defined using the “expression” parameter.
If it is necessary to include in the calculation an Attribute of an entity other than the one defined, it is possible to use the Parameter “entity_ids“, where you define the ID of the selected Entity. (see following image.)
In case you need to process more entities, the “entity_ids” field can be defined as an object with multiple values. (See the following picture)
Then the order of the objects in the “entities” definition is taken into account in the “expression” parameter in the patterns.