Minor optimisations

This commit is contained in:
2025-07-21 17:28:09 +02:00
parent b1719376cf
commit 57aafe3e0b
2 changed files with 8 additions and 5 deletions

View File

@@ -28,14 +28,12 @@ class nodeClass {
*/ */
_attachInputHandler() { _attachInputHandler() {
this.node.on('input', (msg, send, done) => { this.node.on('input', (msg, send, done) => {
let toggleUpdate = false;
switch (msg.topic) { switch (msg.topic) {
case "clock": case "clock":
toggleUpdate = true;
this.source.updateState(msg.timestamp); this.source.updateState(msg.timestamp);
send([this.source.getEffluent, null, null]); send([this.source.getEffluent, null, null]);
send([msg, null, null]) send([msg, null, null]);
break; break;
case "Fluent": case "Fluent":
this.source.setInfluent = msg; this.source.setInfluent = msg;
@@ -53,7 +51,6 @@ class nodeClass {
// Register this node as a child of the parent node // Register this node as a child of the parent node
const childId = msg.payload; const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId); const childObj = this.RED.nodes.getNode(childId);
console.log(childObj.source);
this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent); this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
break; break;
default: default:
@@ -139,6 +136,7 @@ class nodeClass {
this.source = new_reactor; // protect from reassignment this.source = new_reactor; // protect from reassignment
this.node.source = this.source; this.node.source = this.source;
} }
} }
module.exports = nodeClass; module.exports = nodeClass;

View File

@@ -25,6 +25,7 @@ class Reactor {
this.logger = new logger(undefined, undefined, config.general.name); this.logger = new logger(undefined, undefined, config.general.name);
this.emitter = new EventEmitter(); this.emitter = new EventEmitter();
this.measurements = new MeasurementContainer(); this.measurements = new MeasurementContainer();
this.upstreamReactor = null;
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
this.asm = new ASM3(); this.asm = new ASM3();
@@ -115,6 +116,10 @@ class Reactor {
updateState(newTime) { // expect update with timestamp updateState(newTime) { // expect update with timestamp
const day2ms = 1000 * 60 * 60 * 24; const day2ms = 1000 * 60 * 60 * 24;
if (this.upstreamReactor) {
this.setInfluent = this.upstreamReactor.getEffluent;
}
let n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*day2ms)); let n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*day2ms));
if (n_iter) { if (n_iter) {
let n = 0; let n = 0;
@@ -123,7 +128,7 @@ class Reactor {
n += 1; n += 1;
} }
this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor; this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor;
this.emitter.emit("stateChange", this.getEffluent); this.emitter.emit("stateChange", newTime);
} }
} }
} }