Model

The Model stage is used to reshape data in an event data into a model definition without requiring an instance. Unlike instances, the Model stage can only work with data from the event. It cannot read data from other sources. If it’s required to mix data from multiple sources, use a Read Stage followed by a Model Stage.

model_stage.png

Model

The model used to shape the event data. Once set, select the Configure Attributes button to launch the model definition and map event data to each attribute.

Object Name

The name assigned to the event after it’s been re-shaped. Note this is equivalent to an instance name, and populates the _name metadata.

Initialization Block

Similar to instances, the initialization block is used to set variables or calculated values that are shared across attribute expressions.

Example initialization block:

variables.mySetPoint = event.value.temp - event.value.tempOffset

Example attribute expression:

return (event.value.valveTemp - variables.mySetPoint)

model_stage_attributes.png

Configuring Attributes

Select Configure Attributes to see all the attributes defined in the model and map each attribute to an event value. Both expressions and default values are available.

When configuring attributes there are two expression options:

  • Reference - For simple mapping and improved performance (see Performance for more information)
  • Expression - For complex mapping and custom JavaScript

Using Expressions

Both expression types have access to the following custom variables:

Name Description
event Input event information
System Information about the hub

Reference

Allows for simple mapping of values. This uses the same syntax as Expression but does not support JavaScript.

Examples:

event.value.temp
System.Internal.DateTime

Expression

Similar to Instances, event data can be mapped to each attribute via a JavaScript expression.

Note the {{ }} syntax used in Instances is not required as the event is bound to a JavaScript object.

return (event.value.temp - event.metadata.pressureOffset)

Intellisense (Expression type only)

Both of the custom variables available in this stage have rich intellisense/autocomplete information that can be accessed while typing the names of the variables.

Start typing the name of one of the custom objects and then navigate with the arrow-keys for detailed information on how to use the property/method.

intellisense

Default Value

Use the default value to populate the value in cases where the expression is omitted or results in an error.

Performance

Reference type expression can offer improved performance for simple mapping scenarios.

*Improved performance is only realized if all attributes in the model stage are using “Reference” type expressions.

If any attribute in the model stage uses the “Expression” type there will be no performance increase.

Example on improving performance

The following example could be both simplified and benefit from increased performance by leveraging Reference type expressions and default values:

slow example

Here is an example of the improved expression:

improved example