Phi function reference

 

IoT-specific function reference

The following functions from PHP and Twig are available in Phi:

  • dump(string)

    returns null

    An alias of print(), this allows you to check the value of variables while testing your code. The data processor ignores this function.

  • fireTrigger(triggerCodeName, explanation)

    returns null

    If you create a trigger, and choose the ”Triggered from the Phi code“ option, then the trigger will not be set until you call the fireTrigger() function in your Phi code for the asset or data pool.

    Note that if the trigger was set the last time the Phi code was run, and you call the fireTrigger() function again, then there will be no further effect. However if the trigger was set the last time the Phi code was run, and you don't call the fireTrigger() function again, then the trigger will turn off.

  • getAllChildIds([schema[, nodeId]])

    returns ids

    This gives you all of the children of the current asset or data pool.

    You can optionally filter by a specific schema.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getAllChildAssetIds([nodeId])

    returns ids

    Returns the IDs of all assets (as opposed to data pools) under the current data pool (not just immediately below, but at any level below).

    By default the function starts from the current data pool, but you may pass the id of a different data pool to override this. (This id might be obtained from the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() functions.)

  • getAllChildDataPoolIds([nodeId])

    returns ids

    This gives you all of the data pools under the current data pool.

    This checks from the current data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getAssetReliability(fromTimestamp, toTimestamp[, assetId])

    returns value

    Reports on how reliable an asset's connectivity was between the specified timestamps.

    This function takes a time range, adds up all of the duty cycle time for and asset in that time range, and returns a value between 0 and 1. Where 0 means completely unreliably, and 1 means completely reliable.

    This will only return a meaningful result if the Asset communicates regularly and Normal communication interval options are set on the asset's schema.

  • getHistoricValue(key, timestamp[, nodeId])

    returns value

    Looks up the value of a field at the specified timestamp.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getImmediateChildIds([schema[, nodeId]])

    returns ids

    This gives you all of the immediate children of the current asset or data pool.

    You can optionally filter by a specific schema.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getInheritedMetadata(key[, nodeId])

    returns value

    Looks up the value of a metadata field.

    This gets the value of a metadata field for the current node (asset or data pool). If the field doesn't exist on this node's schema, or it exists but this node has the field set to ”inherit“, then the Phi script looks at the parent node, grandparent node and so on, up to location level, in order to find the value from a higher level. This means you can define the field at a high level in the hierarchy, such as on a location, and set a value there, and if need be override it at a lower level. When this function is called it will get either the broader value, or a more specific one if it exists.

    This check starts from the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this starting position.

  • getMetadata(key[, nodeId])

    returns value

    An alias of getInheritedMetadata().

    As of version 9.0, this function is deprecated, and may be removed in a future version.

  • getMetricValue(key, fromTimestamp[, nodeId])

    returns value

    Looks up the value of a field from a metric at the specified timestamp.

    Metrics are indexed by their fromTimestamp time, and not their toTimestamp time. E.g. if you wish to get the value of a monthly metric in June, you should use a timestamp from June (e.g. 1st June 00:00:00 is best, but any timestamp from June will work).

    Note that a timestamp of 1st July 00:00:00 would not work in this example, as this would give you the metric from July.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getMinValue(key, fromTimestamp, toTimestamp[, assetIds])

    returns value

    Looks up the smallest value of a field between the specified timestamps.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getMaxValue(key, fromTimestamp, toTimestamp[, assetIds])

    returns value

    Looks up the largest value of a field between the specified timestamps.

    This checks the current asset or data pool, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getParentNodeId([schema[, nodeId]])

    returns id

    This gives you the node id of the data pool above the current node.

    You can optionally filter by a specific schema, in which case you'll get an id of a data pool above the current node that has the specified schema. If you don't specify a schema then you'll get the id of the data pool immediately above the current node.

    This checks from the current asset or data pool by default, but you may pass in an id obtained from either the getParentNodeId(), getImmediateChildIds(), getAllChildIds(), getAllChildAssetIds() or getAllChildDataPoolIds() function to override this.

  • getTimestamp(description[, timestamp])

    returns number

    Generates a timestamp as described above.

  • query(fromTimestamp, toTimestamp, nodeIds)

    returns value

    This finds all of the data for the specified assets, between the specified timestamps.

    This returns a cursor of results that you can loop through using a for () loop.

  • setValue(key, value)

    returns null

    Sets the value of a calculated field, as described above.