working
This commit is contained in:
@@ -87,8 +87,6 @@ class nodeClass {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`position vs child for ${this.name} is ${this.config.functionality.positionVsParent} the distance is ${this.config.functionality.distance}`);
|
|
||||||
|
|
||||||
// Utility for formatting outputs
|
// Utility for formatting outputs
|
||||||
this._output = new outputUtils();
|
this._output = new outputUtils();
|
||||||
}
|
}
|
||||||
@@ -154,17 +152,34 @@ class nodeClass {
|
|||||||
*/
|
*/
|
||||||
_attachInputHandler() {
|
_attachInputHandler() {
|
||||||
this.node.on('input', (msg, send, done) => {
|
this.node.on('input', (msg, send, done) => {
|
||||||
|
try {
|
||||||
switch (msg.topic) {
|
switch (msg.topic) {
|
||||||
case 'simulator': this.source.toggleSimulation(); break;
|
case 'simulator':
|
||||||
case 'outlierDetection': this.source.toggleOutlierDetection(); break;
|
this.source.toggleSimulation();
|
||||||
case 'calibrate': this.source.calibrate(); break;
|
break;
|
||||||
|
case 'outlierDetection':
|
||||||
|
this.source.toggleOutlierDetection();
|
||||||
|
break;
|
||||||
|
case 'calibrate':
|
||||||
|
this.source.calibrate();
|
||||||
|
break;
|
||||||
case 'measurement':
|
case 'measurement':
|
||||||
if (typeof msg.payload === 'number') {
|
if (typeof msg.payload === 'number' || (typeof msg.payload === 'string' && msg.payload.trim() !== '')) {
|
||||||
this.source.inputValue = parseFloat(msg.payload);
|
const parsed = Number(msg.payload);
|
||||||
|
if (!Number.isNaN(parsed)) {
|
||||||
|
this.source.inputValue = parsed;
|
||||||
|
} else {
|
||||||
|
this.source.logger?.warn(`Invalid numeric measurement payload: ${msg.payload}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
this.source.logger?.warn(`Unknown topic: ${msg.topic}`);
|
||||||
}
|
}
|
||||||
done();
|
} catch (error) {
|
||||||
|
this.source.logger?.error(`Input handler failure: ${error.message}`);
|
||||||
|
}
|
||||||
|
if (typeof done === 'function') done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +190,7 @@ class nodeClass {
|
|||||||
this.node.on('close', (done) => {
|
this.node.on('close', (done) => {
|
||||||
clearInterval(this._tickInterval);
|
clearInterval(this._tickInterval);
|
||||||
//clearInterval(this._statusInterval);
|
//clearInterval(this._statusInterval);
|
||||||
done();
|
if (typeof done === 'function') done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const {logger,configUtils,configManager,MeasurementContainer} = require('generalFunctions');
|
const {logger,configUtils,configManager,MeasurementContainer} = require('generalFunctions');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Measurement domain model.
|
||||||
|
* Handles scaling, smoothing, outlier filtering and emits normalized measurement output.
|
||||||
|
*/
|
||||||
class Measurement {
|
class Measurement {
|
||||||
constructor(config={}) {
|
constructor(config={}) {
|
||||||
|
|
||||||
@@ -506,7 +510,10 @@ class Measurement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleOutlierDetection() {
|
toggleOutlierDetection() {
|
||||||
this.config.outlierDetection = !this.config.outlierDetection;
|
// Keep the outlier configuration shape stable and only toggle the enabled flag.
|
||||||
|
const currentState = Boolean(this.config?.outlierDetection?.enabled);
|
||||||
|
this.config.outlierDetection = this.config.outlierDetection || {};
|
||||||
|
this.config.outlierDetection.enabled = !currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOutput() {
|
getOutput() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict');
|
|||||||
const NodeClass = require('../../src/nodeClass');
|
const NodeClass = require('../../src/nodeClass');
|
||||||
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
|
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
|
||||||
|
|
||||||
test('measurement topic ignores non-number payloads (current behavior)', () => {
|
test('measurement topic accepts numeric strings and ignores non-numeric objects', () => {
|
||||||
const inst = Object.create(NodeClass.prototype);
|
const inst = Object.create(NodeClass.prototype);
|
||||||
const node = makeNodeStub();
|
const node = makeNodeStub();
|
||||||
const calls = [];
|
const calls = [];
|
||||||
@@ -24,5 +24,5 @@ test('measurement topic ignores non-number payloads (current behavior)', () => {
|
|||||||
onInput({ topic: 'measurement', payload: '42' }, () => {}, () => {});
|
onInput({ topic: 'measurement', payload: '42' }, () => {}, () => {});
|
||||||
onInput({ topic: 'measurement', payload: { value: 42 } }, () => {}, () => {});
|
onInput({ topic: 'measurement', payload: { value: 42 } }, () => {}, () => {});
|
||||||
|
|
||||||
assert.equal(calls.length, 0);
|
assert.deepEqual(calls, [42]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ const assert = require('node:assert/strict');
|
|||||||
|
|
||||||
const { makeMeasurementInstance } = require('../helpers/factories');
|
const { makeMeasurementInstance } = require('../helpers/factories');
|
||||||
|
|
||||||
test('toggleOutlierDetection currently converts config object to boolean (known gap)', () => {
|
test('toggleOutlierDetection toggles enabled flag while preserving config object', () => {
|
||||||
const m = makeMeasurementInstance();
|
const m = makeMeasurementInstance();
|
||||||
|
|
||||||
assert.equal(typeof m.config.outlierDetection, 'object');
|
assert.equal(typeof m.config.outlierDetection, 'object');
|
||||||
|
const before = Boolean(m.config.outlierDetection.enabled);
|
||||||
m.toggleOutlierDetection();
|
m.toggleOutlierDetection();
|
||||||
assert.equal(typeof m.config.outlierDetection, 'boolean');
|
assert.equal(typeof m.config.outlierDetection, 'object');
|
||||||
|
assert.equal(Boolean(m.config.outlierDetection.enabled), !before);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user