@machinemetrics/io-adapter-lib 2.38.0 → 2.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -10,13 +10,13 @@ const TransformState = require('./transformState');
|
|
|
10
10
|
* the counter will be incremented before the output value is emitted.
|
|
11
11
|
*/
|
|
12
12
|
class RisingEdgeCounterFilter extends TransformState {
|
|
13
|
-
constructor({ engine, path, args: { mergeWindow,
|
|
13
|
+
constructor({ engine, path, args: { mergeWindow, amount = {}, reset = {} } }) {
|
|
14
14
|
super();
|
|
15
15
|
|
|
16
16
|
this.mergeWindow = mergeWindow || 0;
|
|
17
17
|
this.engine = engine;
|
|
18
|
-
this.accumExpression =
|
|
19
|
-
this.accumSources = engine.expressionService.expressionTriggers(`${path}.
|
|
18
|
+
this.accumExpression = amount.compiledExpression;
|
|
19
|
+
this.accumSources = engine.expressionService.expressionTriggers(`${path}.amount`);
|
|
20
20
|
this.resetExpression = reset.compiledExpression;
|
|
21
21
|
this.resetSources = engine.expressionService.expressionTriggers(`${path}.reset`);
|
|
22
22
|
|
|
@@ -37,12 +37,12 @@ class RisingEdgeCounterFilter extends TransformState {
|
|
|
37
37
|
defaultAttribute: 'amount',
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
let
|
|
41
|
-
if (!_.isUndefined(
|
|
40
|
+
let amount = _.get(defn.args, 'amount', defn.args.count);
|
|
41
|
+
if (!_.isUndefined(amount)) {
|
|
42
42
|
try {
|
|
43
|
-
const expression =
|
|
43
|
+
const expression = amount.toString();
|
|
44
44
|
const compiledExpression = configUtil.compileExpression(expression, this.op);
|
|
45
|
-
|
|
45
|
+
amount = { expression, compiledExpression };
|
|
46
46
|
} catch (err) {
|
|
47
47
|
configUtil.throwConfigError(`Problem evaluating expression: ${err.message}`, this.op);
|
|
48
48
|
}
|
|
@@ -64,12 +64,12 @@ class RisingEdgeCounterFilter extends TransformState {
|
|
|
64
64
|
configUtil.requirePositive(mergeWindow, 'merge-window', this.op);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
defn.args = {
|
|
67
|
+
defn.args = { amount, reset, mergeWindow };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
static getExpressions(configUtil, body, info) {
|
|
71
71
|
return [
|
|
72
|
-
...configUtil.getExpressions(body, { ...info, field: '
|
|
72
|
+
...configUtil.getExpressions(body, { ...info, field: 'amount' }, true),
|
|
73
73
|
...configUtil.getExpressions(body, { ...info, field: 'reset' }),
|
|
74
74
|
];
|
|
75
75
|
}
|
package/package.json
CHANGED
|
@@ -224,4 +224,23 @@ describe('rising-edge-counter full engine config file tests', function () {
|
|
|
224
224
|
[14, 8], [17, 10], [17, 12], [20, 14],
|
|
225
225
|
]);
|
|
226
226
|
});
|
|
227
|
+
|
|
228
|
+
it('count by expression 3', function () {
|
|
229
|
+
const engine = new EngineV2(config);
|
|
230
|
+
const builder = new Builder(config);
|
|
231
|
+
builder.build(engine);
|
|
232
|
+
|
|
233
|
+
const source = testUtils.valueSource();
|
|
234
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var8, source);
|
|
235
|
+
|
|
236
|
+
source.sendValue('ppc', 7, 0);
|
|
237
|
+
source.sendValues('active', [[false, 0], [true, 2], [false, 4], [true, 6]]);
|
|
238
|
+
source.sendValue('ppc', 3, 7);
|
|
239
|
+
source.sendValues('active', [[false, 8], [true, 10], [false, 12], [true, 14]]);
|
|
240
|
+
|
|
241
|
+
engine.validateFilter([
|
|
242
|
+
[0, 0], [7, 2], [7, 4], [14, 6], [14, 7],
|
|
243
|
+
[14, 8], [17, 10], [17, 12], [20, 14],
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
227
246
|
});
|