From 839ae2f3da6c5483bc72a768c9210c28574cb9dc Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 16 Jul 2025 15:34:58 +0200 Subject: [PATCH 01/15] feat: add reactor registration and handling in ChildRegistrationUtils --- src/helper/childRegistrationUtils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index f9b9cef..8f3106d 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -87,6 +87,11 @@ class ChildRegistrationUtils { this.logger.debug(`Registering linear actuator child: ${id}`); this.connectActuator(child,positionVsParent); break; + + case "reactor": + this.logger.debug(`Registering reactor child: ${id}`); + this.connectReactor(child); + break; default: this.logger.error(`Child registration unrecognized desc: ${desc}`); @@ -222,6 +227,20 @@ class ChildRegistrationUtils { } } + connectReactor(reactor) { + if (!reactor) { + this.logger.warn("Invalid reactor provided."); + return; + } + this.mainClass.upstreamReactor = reactor; // Add reactor to the main class + this.logger.info(`Reactor registered successfully.`); + + reactor.emitter.on("stateChange", (data) => { + this.mainClass.logger.debug(`State change of reactor detected: ${data}`); + this.mainClass.setInflux = data; + }); + } + //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) } From 7cdfc87c834486ea4b9b3500bfc6a551bba49266 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 16 Jul 2025 16:04:32 +0200 Subject: [PATCH 02/15] Add state update on recieving child signal --- src/helper/childRegistrationUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 8f3106d..8b90cb1 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -226,6 +226,8 @@ class ChildRegistrationUtils { } } } + + //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) connectReactor(reactor) { if (!reactor) { @@ -238,10 +240,10 @@ class ChildRegistrationUtils { reactor.emitter.on("stateChange", (data) => { this.mainClass.logger.debug(`State change of reactor detected: ${data}`); this.mainClass.setInflux = data; + this.mainClass.updateState(data.timestamp); }); } - //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) } module.exports = ChildRegistrationUtils; From 8c9301b128d8f9d107a6a6012af5f483141184bf Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Mon, 21 Jul 2025 14:14:30 +0200 Subject: [PATCH 03/15] Remove undefined reference to 'desc' --- src/helper/childRegistrationUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index f9b9cef..e018a0b 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -89,7 +89,6 @@ class ChildRegistrationUtils { break; default: - this.logger.error(`Child registration unrecognized desc: ${desc}`); this.logger.error(`Unrecognized softwareType: ${softwareType}`); } } From 475caa90db60c35b491f82340069a1ea4ba6757d Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Mon, 21 Jul 2025 17:32:00 +0200 Subject: [PATCH 04/15] Fixed bugs in connectReactor --- src/helper/childRegistrationUtils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 8db49d8..7b3cbb7 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -237,9 +237,8 @@ class ChildRegistrationUtils { this.logger.info(`Reactor registered successfully.`); reactor.emitter.on("stateChange", (data) => { - this.mainClass.logger.debug(`State change of reactor detected: ${data}`); - this.mainClass.setInflux = data; - this.mainClass.updateState(data.timestamp); + this.mainClass.logger.debug(`State change of upstream reactor detected.`); + this.mainClass.updateState(data); }); } From 71643375fc1ace033bc6d4b2149e81464dab8e05 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Thu, 24 Jul 2025 15:09:04 +0200 Subject: [PATCH 05/15] Added additional reactor handling --- src/helper/childRegistrationUtils.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 7b3cbb7..0a2aaac 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -233,7 +233,18 @@ class ChildRegistrationUtils { this.logger.warn("Invalid reactor provided."); return; } - this.mainClass.upstreamReactor = reactor; // Add reactor to the main class + + // this is poor code, it should be fixed at some point + if (this.mainClass?.upstreamReactor){ + this.mainClass.upstreamReactor = reactor; // Add reactor to the main class + } else { + if (positionVsParent == "downstream") { + this.mainClass.reactors[0] = reactor; + } + if (positionVsParent == "upstream") { + this.mainClass.reactors[1] = reactor; + } + } this.logger.info(`Reactor registered successfully.`); reactor.emitter.on("stateChange", (data) => { From aec2d3692dbe59f73cf3a2fc91d920db55cb9442 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Thu, 31 Jul 2025 11:36:42 +0200 Subject: [PATCH 06/15] Fixed missing reference to position --- src/helper/childRegistrationUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 0a2aaac..1d1a723 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -85,12 +85,12 @@ class ChildRegistrationUtils { case "actuator": this.logger.debug(`Registering linear actuator child: ${id}`); - this.connectActuator(child,positionVsParent); + this.connectActuator(child, positionVsParent); break; case "reactor": this.logger.debug(`Registering reactor child: ${id}`); - this.connectReactor(child); + this.connectReactor(child, positionVsParent); break; default: @@ -228,7 +228,7 @@ class ChildRegistrationUtils { //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) - connectReactor(reactor) { + connectReactor(reactor, positionVsParent) { if (!reactor) { this.logger.warn("Invalid reactor provided."); return; From 7191e57aeaa864dafa0b5be331b040a82b9ecd73 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Thu, 31 Jul 2025 14:57:38 +0200 Subject: [PATCH 07/15] Improved reactor registration --- src/helper/childRegistrationUtils.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 1d1a723..3ba661a 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -234,18 +234,20 @@ class ChildRegistrationUtils { return; } - // this is poor code, it should be fixed at some point if (this.mainClass?.upstreamReactor){ this.mainClass.upstreamReactor = reactor; // Add reactor to the main class - } else { + this.logger.info(`Upstream reactor registered successfully.`); + } + + if (this.mainClass?.reactors) { if (positionVsParent == "downstream") { this.mainClass.reactors[0] = reactor; } if (positionVsParent == "upstream") { this.mainClass.reactors[1] = reactor; } + this.logger.info(`Reactor registered successfully.`); } - this.logger.info(`Reactor registered successfully.`); reactor.emitter.on("stateChange", (data) => { this.mainClass.logger.debug(`State change of upstream reactor detected.`); From 0bccad05f8eaa925f05a07bfefcf9416c7e32a59 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Fri, 1 Aug 2025 12:30:12 +0200 Subject: [PATCH 08/15] Added error message to node registration --- src/helper/childRegistrationUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 3ba661a..532e414 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -237,9 +237,7 @@ class ChildRegistrationUtils { if (this.mainClass?.upstreamReactor){ this.mainClass.upstreamReactor = reactor; // Add reactor to the main class this.logger.info(`Upstream reactor registered successfully.`); - } - - if (this.mainClass?.reactors) { + } else if (this.mainClass?.reactors) { if (positionVsParent == "downstream") { this.mainClass.reactors[0] = reactor; } @@ -247,6 +245,8 @@ class ChildRegistrationUtils { this.mainClass.reactors[1] = reactor; } this.logger.info(`Reactor registered successfully.`); + } else { + this.logger.error(`Reactor not registered!`) } reactor.emitter.on("stateChange", (data) => { From 958ec2269c902f3ebb11b13527fbc860ee9381e7 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 3 Sep 2025 11:13:00 +0200 Subject: [PATCH 09/15] Print reactors state after configuration --- src/helper/childRegistrationUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 532e414..eac2e7d 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -244,7 +244,7 @@ class ChildRegistrationUtils { if (positionVsParent == "upstream") { this.mainClass.reactors[1] = reactor; } - this.logger.info(`Reactor registered successfully.`); + this.logger.info(`Reactor registered successfully: ${this.mainClass.reactors}`); } else { this.logger.error(`Reactor not registered!`) } From 302e12238745766a679ef11ca6ed5f4ea1548f87 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Fri, 5 Sep 2025 13:39:15 +0200 Subject: [PATCH 10/15] Fixing the same bug in reference, again --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d542a17..d2c2ec6 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,12 @@ const outputUtils = require('./src/helper/outputUtils.js'); const logger = require('./src/helper/logger.js'); const validation = require('./src/helper/validationUtils.js'); const configUtils = require('./src/helper/configUtils.js'); +const assertions = require('./src/helper/assertionUtils.js') // Domain-specific modules const { MeasurementContainer } = require('./src/measurements/index.js'); const configManager = require('./src/configs/index.js'); -const nrmse = require('./src/nrmse/ErrorMetrics.js'); +const nrmse = require('./src/nrmse/errorMetrics.js'); const state = require('./src/state/state.js'); const convert = require('./src/convert/index.js'); const MenuManager = require('./src/menu/index.js'); @@ -34,6 +35,7 @@ module.exports = { configUtils, logger, validation, + assertions, MeasurementContainer, nrmse, state, From 16e202e84122f8d63d3270f47ab6bf1cf2850b60 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 17 Sep 2025 13:21:35 +0200 Subject: [PATCH 11/15] Refactor position handling in MeasurementContainer to use position values instead of names --- src/measurements/MeasurementContainer.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/measurements/MeasurementContainer.js b/src/measurements/MeasurementContainer.js index 20099f8..97b7f7d 100644 --- a/src/measurements/MeasurementContainer.js +++ b/src/measurements/MeasurementContainer.js @@ -88,11 +88,11 @@ class MeasurementContainer { return this; } - position(positionName) { + position(positionValue) { if (!this._currentVariant) { throw new Error('Variant must be specified before position'); } - this._currentPosition = positionName; + this._currentPosition = positionValue; return this; } @@ -243,10 +243,12 @@ class MeasurementContainer { const savedPosition = this._currentPosition; // Get upstream and downstream measurements - this._currentPosition = 'upstream'; + const positions = this.getPositions(); + + this._currentPosition = Math.min(...positions); const upstream = this.get(); - this._currentPosition = 'downstream'; + this._currentPosition = Math.max(...positions); const downstream = this.get(); this._currentPosition = savedPosition; From 6d30e25daa0f09511060a8a9b5393069616f5d4d Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 17 Sep 2025 14:52:25 +0200 Subject: [PATCH 12/15] Add string handling for position --- src/measurements/MeasurementContainer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/measurements/MeasurementContainer.js b/src/measurements/MeasurementContainer.js index 97b7f7d..4a6d107 100644 --- a/src/measurements/MeasurementContainer.js +++ b/src/measurements/MeasurementContainer.js @@ -92,7 +92,16 @@ class MeasurementContainer { if (!this._currentVariant) { throw new Error('Variant must be specified before position'); } + + // Turn string positions into numeric values + if (typeof positionValue == "string") { + positionValue = positionValue == "upstream" ? Number.NEGATIVE_INFINITY : positionValue; + positionValue = positionValue == "atEquipment" ? 0.0 : positionValue; + positionValue = positionValue == "downstream" ? Number.POSITIVE_INFINITY : positionValue; + } + this._currentPosition = positionValue; + return this; } From 3f90685834fa78e2aad1daeca1c54949f01a869e Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Tue, 23 Sep 2025 14:17:42 +0200 Subject: [PATCH 13/15] Enhance position handling by adding utility methods for conversion --- src/measurements/MeasurementContainer.js | 38 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/measurements/MeasurementContainer.js b/src/measurements/MeasurementContainer.js index 4a6d107..f48110a 100644 --- a/src/measurements/MeasurementContainer.js +++ b/src/measurements/MeasurementContainer.js @@ -95,9 +95,7 @@ class MeasurementContainer { // Turn string positions into numeric values if (typeof positionValue == "string") { - positionValue = positionValue == "upstream" ? Number.NEGATIVE_INFINITY : positionValue; - positionValue = positionValue == "atEquipment" ? 0.0 : positionValue; - positionValue = positionValue == "downstream" ? Number.POSITIVE_INFINITY : positionValue; + positionValue = this._convertPositionStr2Num(positionValue); } this._currentPosition = positionValue; @@ -330,7 +328,7 @@ class MeasurementContainer { Object.keys(this.measurements[this._currentType]) : []; } - getPositions() { + getPositions(asNumber = false) { if (!this._currentType || !this._currentVariant) { throw new Error('Type and variant must be specified before listing positions'); } @@ -339,6 +337,10 @@ class MeasurementContainer { !this.measurements[this._currentType][this._currentVariant]) { return []; } + + if (asNumber) { + return Object.keys(this.measurements[this._currentType][this._currentVariant]).map(this._convertPositionNum2Str); + } return Object.keys(this.measurements[this._currentType][this._currentVariant]); } @@ -415,6 +417,34 @@ class MeasurementContainer { } } + _convertPositionStr2Num(positionString) { + switch(positionString) { + case "atEquipment": + return 0; + case "upstream": + return Number.POSITIVE_INFINITY; + case "downstream": + return Number.NEGATIVE_INFINITY; + + default: + this.logger.error(`Invalid positionVsParent provided: ${positionString}`); + return; + } + } + + _convertPositionNum2Str(positionValue) { + if (positionValue == 0) { + return "atEquipment"; + } + if (positionValue < 0) { + return "upstream"; + } + if (positionValue > 0) { + return "downstream"; + } + this.logger.error(`Invalid position provided: ${positionValue}`); + } + } module.exports = MeasurementContainer; From 8d7d98f12610b706b893dbeebd1c4671492ee873 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Tue, 23 Sep 2025 14:31:09 +0200 Subject: [PATCH 14/15] Fix inversion bug --- src/measurements/MeasurementContainer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/measurements/MeasurementContainer.js b/src/measurements/MeasurementContainer.js index f48110a..317fcee 100644 --- a/src/measurements/MeasurementContainer.js +++ b/src/measurements/MeasurementContainer.js @@ -339,10 +339,10 @@ class MeasurementContainer { } if (asNumber) { - return Object.keys(this.measurements[this._currentType][this._currentVariant]).map(this._convertPositionNum2Str); + return Object.keys(this.measurements[this._currentType][this._currentVariant]); } - - return Object.keys(this.measurements[this._currentType][this._currentVariant]); + + return Object.keys(this.measurements[this._currentType][this._currentVariant]).map(this._convertPositionNum2Str); } clear() { From c261335df53e5af042f506129e68024d8a1dc60d Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Thu, 25 Sep 2025 13:54:12 +0200 Subject: [PATCH 15/15] Fix comparison operator in _convertPositionNum2Str method --- src/measurements/MeasurementContainer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/measurements/MeasurementContainer.js b/src/measurements/MeasurementContainer.js index 317fcee..516e182 100644 --- a/src/measurements/MeasurementContainer.js +++ b/src/measurements/MeasurementContainer.js @@ -433,7 +433,7 @@ class MeasurementContainer { } _convertPositionNum2Str(positionValue) { - if (positionValue == 0) { + if (positionValue === 0) { return "atEquipment"; } if (positionValue < 0) {