From 37e6523c5527e3bfd9d9dbb4f021e018f45be3cf Mon Sep 17 00:00:00 2001
From: HorriblePerson555 <47578455+HorriblePerson555@users.noreply.github.com>
Date: Thu, 16 Oct 2025 16:32:20 +0200
Subject: [PATCH 1/6] Refactor child registration to use dedicated connection
methods for measurement and reactor types
---
src/specificClass.js | 90 ++++++++++++++++++++++++--------------------
1 file changed, 50 insertions(+), 40 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index 245946b..a0f3853 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -77,52 +77,62 @@ class Machine {
registerChild(child, softwareType) {
this.logger.debug('Setting up child event for softwaretype ' + softwareType);
- if(softwareType === "measurement"){
- const position = child.config.functionality.positionVsParent;
- const distance = child.config.functionality.distanceVsParent || 0;
- const measurementType = child.config.asset.type;
- const key = `${measurementType}_${position}`;
- //rebuild to measurementype.variant no position and then switch based on values not strings or names.
- const eventName = `${measurementType}.measured.${position}`;
-
- this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`);
- // Register event listener for measurement updates
- child.measurements.emitter.on(eventName, (eventData) => {
- this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
+ switch (softwareType) {
+ case "measurement":
+ this._connectMeasurement(child);
+ break;
+ case "reactor":
+ this._connectReactor(child);
+ break;
-
- console.log(` Emitting... ${eventName} with data:`);
- // Store directly in parent's measurement container
- this.measurements
- .type(measurementType)
- .variant("measured")
- .position(position)
- .value(eventData.value, eventData.timestamp, eventData.unit);
-
- // Call the appropriate handler
- this._callMeasurementHandler(measurementType, eventData.value, position, eventData);
- });
+ default:
+ this.logger.error(`Unrecognized softwareType: ${softwareType}`);
}
}
-// Centralized handler dispatcher
-_callMeasurementHandler(measurementType, value, position, context) {
- switch (measurementType) {
- case 'pressure':
- this.updateMeasuredPressure(value, position, context);
- break;
+ _connectMeasurement(measurementChild) {
+ const position = measurementChild.config.functionality.positionVsParent;
+ const distance = measurementChild.config.functionality.distanceVsParent || 0;
+ const measurementType = measurementChild.config.asset.type;
+ const key = `${measurementType}_${position}`;
+ //rebuild to measurementype.variant no position and then switch based on values not strings or names.
+ const eventName = `${measurementType}.measured.${position}`;
+
+ this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`);
+ // Register event listener for measurement updates
+ measurementChild.measurements.emitter.on(eventName, (eventData) => {
+ this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
+
+
+ console.log(` Emitting... ${eventName} with data:`);
+ // Store directly in parent's measurement container
+ this.measurements
+ .type(measurementType)
+ .variant("measured")
+ .position(position)
+ .value(eventData.value, eventData.timestamp, eventData.unit);
- case 'flow':
- this.updateMeasuredFlow(value, position, context);
- break;
-
- default:
- this.logger.warn(`No handler for measurement type: ${measurementType}`);
- // Generic handler - just update position
- this.updatePosition();
- break;
+ // Call the appropriate handler
+ switch (measurementType) {
+ case 'pressure':
+ this.updateMeasuredPressure(eventData.value, position, eventData);
+ break;
+
+ case 'flow':
+ this.updateMeasuredFlow(eventData.value, position, eventData);
+ break;
+
+ default:
+ this.logger.warn(`No handler for measurement type: ${measurementType}`);
+ // Generic handler - just update position
+ this.updatePosition();
+ }
+ });
+ }
+
+ _connectReactor(reactorChild) {
+ this.logger.error("Reactor child not implemented yet.");
}
-}
//---------------- END child stuff -------------//
From d7cc6a4a8b1f35a12dd2a69fddd25b81767fac23 Mon Sep 17 00:00:00 2001
From: HorriblePerson555 <47578455+HorriblePerson555@users.noreply.github.com>
Date: Fri, 17 Oct 2025 13:38:05 +0200
Subject: [PATCH 2/6] Enhance child registration logging and add validation for
measurement child
---
src/specificClass.js | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index a0f3853..3ad3fa5 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -75,13 +75,13 @@ class Machine {
/*------------------- Register child events -------------------*/
registerChild(child, softwareType) {
- this.logger.debug('Setting up child event for softwaretype ' + softwareType);
-
switch (softwareType) {
case "measurement":
+ this.logger.debug(`Registering measurement child...`);
this._connectMeasurement(child);
break;
case "reactor":
+ this.logger.debug(`Registering reactor child...`);
this._connectReactor(child);
break;
@@ -91,10 +91,14 @@ class Machine {
}
_connectMeasurement(measurementChild) {
+ if (!measurementChild) {
+ this.logger.warn("Invalid measurement provided.");
+ return;
+ }
+
const position = measurementChild.config.functionality.positionVsParent;
const distance = measurementChild.config.functionality.distanceVsParent || 0;
const measurementType = measurementChild.config.asset.type;
- const key = `${measurementType}_${position}`;
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
const eventName = `${measurementType}.measured.${position}`;
From a8fb56bfb8ceb5d11ab7748844d5b5b986eb2289 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Wed, 22 Oct 2025 14:41:35 +0200
Subject: [PATCH 3/6] Add upstream and downstream reactor handling; improve
error logging
---
src/specificClass.js | 56 ++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 20 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index 3ad3fa5..aba5570 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -68,6 +68,10 @@ class Machine {
this.updatePosition();
});
+ // used for holding the source and sink unit operations or other object with setInfluent / getEffluent method for e.g. recirculation.
+ this.upstreamReactor = null;
+ this.downstreamReactor = null;
+
this.child = {}; // object to hold child information so we know on what to subscribe
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
@@ -92,7 +96,7 @@ class Machine {
_connectMeasurement(measurementChild) {
if (!measurementChild) {
- this.logger.warn("Invalid measurement provided.");
+ this.logger.error("Invalid measurement provided.");
return;
}
@@ -107,14 +111,12 @@ class Machine {
measurementChild.measurements.emitter.on(eventName, (eventData) => {
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
-
- console.log(` Emitting... ${eventName} with data:`);
// Store directly in parent's measurement container
this.measurements
.type(measurementType)
.variant("measured")
.position(position)
- .value(eventData.value, eventData.timestamp, eventData.unit);
+ .value(eventData.value, eventData.timestamp, eventData.unit);
// Call the appropriate handler
switch (measurementType) {
@@ -135,26 +137,31 @@ class Machine {
}
_connectReactor(reactorChild) {
- this.logger.error("Reactor child not implemented yet.");
+ if (!reactorChild) {
+ this.logger.error("Invalid measurement provided.");
+ return;
+ }
+
+ this.downstreamReactor = reactorChild; // downstream from the pumps perpective
}
-//---------------- END child stuff -------------//
+ //---------------- END child stuff -------------//
- // Method to assess drift using errorMetrics
- assessDrift(measurement, processMin, processMax) {
- this.logger.debug(`Assessing drift for measurement: ${measurement} processMin: ${processMin} processMax: ${processMax}`);
- const predictedMeasurement = this.measurements.type(measurement).variant("predicted").position("downstream").getAllValues().values;
- const measuredMeasurement = this.measurements.type(measurement).variant("measured").position("downstream").getAllValues().values;
+ // Method to assess drift using errorMetrics
+ assessDrift(measurement, processMin, processMax) {
+ this.logger.debug(`Assessing drift for measurement: ${measurement} processMin: ${processMin} processMax: ${processMax}`);
+ const predictedMeasurement = this.measurements.type(measurement).variant("predicted").position("downstream").getAllValues().values;
+ const measuredMeasurement = this.measurements.type(measurement).variant("measured").position("downstream").getAllValues().values;
- if (!predictedMeasurement || !measuredMeasurement) return null;
-
- return this.errorMetrics.assessDrift(
- predictedMeasurement,
- measuredMeasurement,
- processMin,
- processMax
- );
- }
+ if (!predictedMeasurement || !measuredMeasurement) return null;
+
+ return this.errorMetrics.assessDrift(
+ predictedMeasurement,
+ measuredMeasurement,
+ processMin,
+ processMax
+ );
+ }
reverseCurve(curve) {
const reversedCurve = {};
@@ -499,12 +506,17 @@ class Machine {
// NEW: Flow handler
updateMeasuredFlow(value, position, context = {}) {
+
if (!this._isOperationalState()) {
this.logger.warn(`Machine not operational, skipping flow update from ${context.childName || 'unknown'}`);
return;
}
this.logger.debug(`Flow update: ${value} at ${position} from ${context.childName || 'child'}`);
+
+ if (this.upstreamReactor && this.downstreamReactor){
+ this._updateConnectedReactor();
+ }
// Store in parent's measurement container
this.measurements.type("flow").variant("measured").position(position).value(value, context.timestamp, context.unit);
@@ -515,6 +527,10 @@ class Machine {
}
}
+ _updateConnectedReactor() {
+ this.downstreamReactor.setInfluent = this.upstreamReactor.getEffluent[1];
+ }
+
// Helper method for operational state check
_isOperationalState() {
const state = this.state.getCurrentState();
From ac40a93ef1728a777eb1d7855695c851e7e1e8bb Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Fri, 31 Oct 2025 13:07:52 +0100
Subject: [PATCH 4/6] Simplify child registration error handling
---
src/specificClass.js | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index aba5570..f1d8123 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -79,6 +79,11 @@ class Machine {
/*------------------- Register child events -------------------*/
registerChild(child, softwareType) {
+ if(!child) {
+ this.logger.error(`Invalid ${softwareType} child provided.`);
+ return;
+ }
+
switch (softwareType) {
case "measurement":
this.logger.debug(`Registering measurement child...`);
@@ -95,11 +100,6 @@ class Machine {
}
_connectMeasurement(measurementChild) {
- if (!measurementChild) {
- this.logger.error("Invalid measurement provided.");
- return;
- }
-
const position = measurementChild.config.functionality.positionVsParent;
const distance = measurementChild.config.functionality.distanceVsParent || 0;
const measurementType = measurementChild.config.asset.type;
@@ -137,11 +137,6 @@ class Machine {
}
_connectReactor(reactorChild) {
- if (!reactorChild) {
- this.logger.error("Invalid measurement provided.");
- return;
- }
-
this.downstreamReactor = reactorChild; // downstream from the pumps perpective
}
From 303dfc477d7f25461c59f1cde6b5db1d8f8a1d1c Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Fri, 31 Oct 2025 14:16:00 +0100
Subject: [PATCH 5/6] Add flow number configuration and UI input for rotating
machine
---
rotatingMachine.html | 5 +++++
src/specificClass.js | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/rotatingMachine.html b/rotatingMachine.html
index 6d54b66..e2a0a69 100644
--- a/rotatingMachine.html
+++ b/rotatingMachine.html
@@ -25,6 +25,7 @@
shutdown: { value: 0 },
cooldown: { value: 0 },
machineCurve : { value: {}},
+ flowNumber : { value: 1, required: true },
//define asset properties
uuid: { value: "" },
@@ -127,6 +128,10 @@
+
+
+
+
diff --git a/src/specificClass.js b/src/specificClass.js
index f1d8123..1579611 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -523,7 +523,8 @@ class Machine {
}
_updateConnectedReactor() {
- this.downstreamReactor.setInfluent = this.upstreamReactor.getEffluent[1];
+ // Handles flow according to the configured "flow number"
+ this.downstreamReactor.setInfluent = this.upstreamReactor.getEffluent[this.config.flowNumber];
}
// Helper method for operational state check
From b6d268659a9d2d5b9e42dd922c24eaf63f80321a Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Thu, 6 Nov 2025 14:50:40 +0100
Subject: [PATCH 6/6] Refactor flow handling: rename reactor references to
source and sink and fix config minor bug
---
rotatingMachine.html | 4 ++--
src/nodeClass.js | 3 ++-
src/specificClass.js | 16 ++++++++--------
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/rotatingMachine.html b/rotatingMachine.html
index e2a0a69..93473b4 100644
--- a/rotatingMachine.html
+++ b/rotatingMachine.html
@@ -24,8 +24,8 @@
warmup: { value: 0 },
shutdown: { value: 0 },
cooldown: { value: 0 },
- machineCurve : { value: {}},
- flowNumber : { value: 1, required: true },
+ machineCurve: { value: {}},
+ flowNumber: { value: 1, required: true },
//define asset properties
uuid: { value: "" },
diff --git a/src/nodeClass.js b/src/nodeClass.js
index 6d20326..7bb504e 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -63,7 +63,8 @@ class nodeClass {
},
functionality: {
positionVsParent: uiConfig.positionVsParent
- }
+ },
+ flowNumber: uiConfig.flowNumber
};
// Utility for formatting outputs
diff --git a/src/specificClass.js b/src/specificClass.js
index 1579611..55a4b32 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -69,8 +69,8 @@ class Machine {
});
// used for holding the source and sink unit operations or other object with setInfluent / getEffluent method for e.g. recirculation.
- this.upstreamReactor = null;
- this.downstreamReactor = null;
+ this.upstreamSource = null;
+ this.downstreamSink = null;
this.child = {}; // object to hold child information so we know on what to subscribe
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
@@ -93,7 +93,6 @@ class Machine {
this.logger.debug(`Registering reactor child...`);
this._connectReactor(child);
break;
-
default:
this.logger.error(`Unrecognized softwareType: ${softwareType}`);
}
@@ -137,7 +136,7 @@ class Machine {
}
_connectReactor(reactorChild) {
- this.downstreamReactor = reactorChild; // downstream from the pumps perpective
+ this.downstreamSink = reactorChild; // downstream from the pumps perpective
}
//---------------- END child stuff -------------//
@@ -509,8 +508,8 @@ class Machine {
this.logger.debug(`Flow update: ${value} at ${position} from ${context.childName || 'child'}`);
- if (this.upstreamReactor && this.downstreamReactor){
- this._updateConnectedReactor();
+ if (this.upstreamSource && this.downstreamSink) {
+ this._updateSourceSink();
}
// Store in parent's measurement container
@@ -522,9 +521,10 @@ class Machine {
}
}
- _updateConnectedReactor() {
+ _updateSourceSink() {
// Handles flow according to the configured "flow number"
- this.downstreamReactor.setInfluent = this.upstreamReactor.getEffluent[this.config.flowNumber];
+ this.logger.debug(`Updating source-sink pair: ${this.upstreamSource.config.functionality.softwareType} - ${this.downstreamSink.config.functionality.softwareType}`);
+ this.downstreamSink.setInfluent = this.upstreamSource.getEffluent[this.config.flowNumber];
}
// Helper method for operational state check