node package manager

iwwa-formula-resolver

npm version Build Status codecov Dependency Status devDependency Status

Utility lib for resolving virtual sensor's formulas.

Installation

npm install iwwa-formula-resolver --save

Usage

evaluateFormula

import {evaluateFormula} from "iwwa-formula-resolver";
 
const result = evaluateFormula(formula, sensorsData, measurementDelta);
formula

Object containing the formula to be resolved, aka:

{
    formula: "(x+y+z)/2"
}
sensorsData

An array containing all objects data to be evaluated within the formula, aka:

[{
    symbol: "x",
    measurementValues: "1,2,3,4,5,6,7,9,10",
    measurementTimes: "1453939200000,1453939500000,1453939800000,1453940100000,1453940400000,1453940700000,1453941000000,1453941300000,1453941600000"
}, ... ]
measurementDelta

Measurement sample delta (not mandatory, if not specified 300000)

decomposeFormula

import {decomposeFormula} from "iwwa-formula-resolver";
 
const result = decomposeFormula(formula, sensorsData, measurementDelta);
formula

Object containing the formula to be decomposed, aka:

{
    formula: "(x-y-z)^3.2*x/totalizator(y)"
}
sensorsData

An array containing all objects id to be decomposed within the formula, aka:

[{
    symbol: "x"
}, {
    symbol: "y"
}, ... ]

Custom operators

Following custom operators are provided:

  • totalizator: returns the difference with the previous available value
  • time shift: returns the value in the moment specified by the shifter

usage

import {
    A_1D_FORWARD_SHIFT,
    TOTALIZATOR
} from "iwwa-formula-resolver";
 
const formula = TOTALIZATOR + "(sensorX)*" + A_1D_FORWARD_SHIFT + "(sensorY)";
const result = evaluateFormula(formula, sensorsData, measurementDelta);