From 4ae6beba3767ae39b8e0fda306c151edec36b768 Mon Sep 17 00:00:00 2001 From: znetsixe <73483679+znetsixe@users.noreply.github.com> Date: Fri, 31 Oct 2025 18:35:40 +0100 Subject: [PATCH] updated measurement node to match selected units from user and convert it properly --- src/nodeClass.js | 4 ++-- src/specificClass.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/nodeClass.js b/src/nodeClass.js index 6d20326..7fc2acd 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -114,8 +114,8 @@ class nodeClass { try { const mode = m.currentMode; const state = m.state.getCurrentState(); - const flow = Math.round(m.measurements.type("flow").variant("predicted").position('downstream').getCurrentValue()); - const power = Math.round(m.measurements.type("power").variant("predicted").position('upstream').getCurrentValue()); + const flow = Math.round(m.measurements.type("flow").variant("predicted").position('downstream').getCurrentValue('m3/h')); + const power = Math.round(m.measurements.type("power").variant("predicted").position('atequipment').getCurrentValue('kW')); let symbolState; switch(state){ case "off": diff --git a/src/specificClass.js b/src/specificClass.js index c5e1a74..999443c 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -48,7 +48,17 @@ class Machine { this.errorMetrics = new nrmse(errorMetricsConfig, this.logger); // Initialize measurements - this.measurements = new MeasurementContainer(); + this.measurements = new MeasurementContainer({ + autoConvert: true, + windowSize: 50, + defaultUnits: { + pressure: 'mbar', + flow: this.config.general.unit, + power: 'kW', + temperature: 'C' + } + }); + this.interpolation = new interpolation(); this.flowDrift = null; @@ -68,11 +78,25 @@ class Machine { this.updatePosition(); }); + //When state changes look if we need to do other updates + this.state.emitter.on("stateChange", (newState) => { + this.logger.debug(`State change detected: ${newState}`); + this._updateState(); + }); + this.child = {}; // object to hold child information so we know on what to subscribe this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility } + _updateState(){ + const isOperational = this._isOperationalState(); + if(!isOperational){ + //overrule the last prediction this should be 0 now + this.measurements.type("flow").variant("predicted").position("downstream").value(0); + } + } + /*------------------- Register child events -------------------*/ registerChild(child, softwareType) { this.logger.debug('Setting up child event for softwaretype ' + softwareType); @@ -501,13 +525,14 @@ _callMeasurementHandler(measurementType, value, position, context) { // Update predicted flow if you have prediction capability if (this.predictFlow) { - this.measurements.type("flow").variant("predicted").position("atEquipment").value(this.predictFlow.outputY || 0); + this.measurements.type("flow").variant("predicted").position("downstream").value(this.predictFlow.outputY || 0); } } // Helper method for operational state check _isOperationalState() { const state = this.state.getCurrentState(); + this.logger.debug(`Checking operational state ${this.state.getCurrentState()} ? ${["operational", "accelerating", "decelerating"].includes(state)}`); return ["operational", "accelerating", "decelerating"].includes(state); } @@ -531,6 +556,9 @@ _callMeasurementHandler(measurementType, value, position, context) { this.calcDistanceBEP(efficiency,cog,minEfficiency); } + + + } calcDistanceFromPeak(currentEfficiency,peakEfficiency){ @@ -561,7 +589,6 @@ _callMeasurementHandler(measurementType, value, position, context) { }; } - // Calculate the center of gravity for current pressure calcCog() {