@machinemetrics/io-adapter-lib 2.35.0 → 2.35.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 +4 -0
- package/lib/transform/valueDecrease.js +9 -1
- package/lib/transform/valueIncrease.js +9 -1
- package/package.json +1 -1
- package/test/configFiles/transform/value-decrease.yml +10 -0
- package/test/configFiles/transform/value-increase.yml +10 -0
- package/test/transform/valueDecrease.test.js +29 -2
- package/test/transform/valueIncrease.test.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -25,7 +25,7 @@ class ValueDecreaseFilter extends TransformState {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
emitUpdate(context) {
|
|
28
|
-
if (this.
|
|
28
|
+
if (this.value < this.previousValue && this.valueTime === this.lastSampleTime) {
|
|
29
29
|
this.forceEmit = false;
|
|
30
30
|
this.lastEmitValue = this.value;
|
|
31
31
|
this.lastEmitTime = this.lastSampleTime;
|
|
@@ -33,6 +33,14 @@ class ValueDecreaseFilter extends TransformState {
|
|
|
33
33
|
}
|
|
34
34
|
this.emit('update', false, this.lastSampleTime, context);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
setUnavailable(context, time) {
|
|
38
|
+
this.available = false;
|
|
39
|
+
this.previousValue = this.value;
|
|
40
|
+
this.previousValueTime = this.valueTime;
|
|
41
|
+
this.valueTime = time;
|
|
42
|
+
this.emit('unavailable', time, context);
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
module.exports = ValueDecreaseFilter;
|
|
@@ -25,7 +25,7 @@ class ValueIncreaseFilter extends TransformState {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
emitUpdate(context) {
|
|
28
|
-
if (this.
|
|
28
|
+
if (this.value > this.previousValue && this.valueTime === this.lastSampleTime) {
|
|
29
29
|
this.forceEmit = false;
|
|
30
30
|
this.lastEmitValue = this.value;
|
|
31
31
|
this.lastEmitTime = this.lastSampleTime;
|
|
@@ -33,6 +33,14 @@ class ValueIncreaseFilter extends TransformState {
|
|
|
33
33
|
}
|
|
34
34
|
this.emit('update', false, this.lastSampleTime, context);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
setUnavailable(context, time) {
|
|
38
|
+
this.available = false;
|
|
39
|
+
this.previousValue = this.value;
|
|
40
|
+
this.previousValueTime = this.valueTime;
|
|
41
|
+
this.valueTime = time;
|
|
42
|
+
this.emit('unavailable', time, context);
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
module.exports = ValueIncreaseFilter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ValueDecrease = require('../../lib/transform').valueDecrease;
|
|
4
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
5
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
4
6
|
const testUtils = require('../util/testUtils');
|
|
5
7
|
|
|
6
8
|
describe('value-decrease transform tests', function () {
|
|
@@ -12,7 +14,7 @@ describe('value-decrease transform tests', function () {
|
|
|
12
14
|
[1, 2], [1, 4], [2, 6], [4, 10], [0, 14], [1, 15], [3, 16], [1, 21],
|
|
13
15
|
]);
|
|
14
16
|
filter.validate([
|
|
15
|
-
[
|
|
17
|
+
[false, 2], [false, 4], [false, 6], [false, 10], [true, 14], [false, 14],
|
|
16
18
|
[false, 15], [false, 16], [true, 21], [false, 21],
|
|
17
19
|
]);
|
|
18
20
|
});
|
|
@@ -25,8 +27,33 @@ describe('value-decrease transform tests', function () {
|
|
|
25
27
|
['1', 2], ['1', 4], ['2', 6], ['10', 10], ['0', 14], ['1', 15], ['3', 16], ['1', 21],
|
|
26
28
|
]);
|
|
27
29
|
filter.validate([
|
|
28
|
-
[
|
|
30
|
+
[false, 2], [false, 4], [false, 6], [false, 10], [true, 14], [false, 14],
|
|
29
31
|
[false, 15], [false, 16], [true, 21], [false, 21],
|
|
30
32
|
]);
|
|
31
33
|
});
|
|
32
34
|
});
|
|
35
|
+
|
|
36
|
+
describe('value-decrease full engine config file tests', function () {
|
|
37
|
+
let config;
|
|
38
|
+
before(async function () {
|
|
39
|
+
config = await testUtils.loadConfig('transform/value-decrease.yml');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('does not emit true when source sends UNAVAILABLE', function () {
|
|
43
|
+
const engine = new EngineV2(config);
|
|
44
|
+
const builder = new Builder(config);
|
|
45
|
+
builder.build(engine);
|
|
46
|
+
|
|
47
|
+
const source = testUtils.valueSource();
|
|
48
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.decreased, source);
|
|
49
|
+
|
|
50
|
+
source.sendValues('level', [
|
|
51
|
+
[1, 0], [2, 1], [0, 2], [1, 3], [2, 4], ['UNAVAILABLE', 5], [3, 6],
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
engine.validateFilter([
|
|
55
|
+
[false, 0], [false, 1], [true, 2], [false, 2], [false, 3], [false, 4],
|
|
56
|
+
[false, 6],
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ValueIncrease = require('../../lib/transform').valueIncrease;
|
|
4
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
5
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
4
6
|
const testUtils = require('../util/testUtils');
|
|
5
7
|
|
|
6
8
|
describe('value-increase transform tests', function () {
|
|
@@ -30,3 +32,28 @@ describe('value-increase transform tests', function () {
|
|
|
30
32
|
]);
|
|
31
33
|
});
|
|
32
34
|
});
|
|
35
|
+
|
|
36
|
+
describe('value-increase full engine config file tests', function () {
|
|
37
|
+
let config;
|
|
38
|
+
before(async function () {
|
|
39
|
+
config = await testUtils.loadConfig('transform/value-increase.yml');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('does not emit true when source sends UNAVAILABLE', function () {
|
|
43
|
+
const engine = new EngineV2(config);
|
|
44
|
+
const builder = new Builder(config);
|
|
45
|
+
builder.build(engine);
|
|
46
|
+
|
|
47
|
+
const source = testUtils.valueSource();
|
|
48
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.increased, source);
|
|
49
|
+
|
|
50
|
+
source.sendValues('level', [
|
|
51
|
+
[1, 0], [2, 1], [0, 2], [1, 3], [2, 4], ['UNAVAILABLE', 5], [2, 6], [3, 7],
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
engine.validateFilter([
|
|
55
|
+
[true, 0], [false, 0], [true, 1], [false, 1], [false, 2], [true, 3], [false, 3],
|
|
56
|
+
[true, 4], [false, 4], [false, 6], [true, 7], [false, 7],
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
});
|