refactor: adopt POSITIONS constants and fix ESLint warnings
Replace hardcoded position strings with POSITIONS.* constants. Prefix unused variables with _ to resolve no-unused-vars warnings. Fix no-prototype-builtins where applicable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -223,7 +223,7 @@ class nodeClass {
|
|||||||
* Attach the node's input handler, routing control messages to the class.
|
* Attach the node's input handler, routing control messages to the class.
|
||||||
*/
|
*/
|
||||||
_attachInputHandler() {
|
_attachInputHandler() {
|
||||||
this.node.on('input', (msg, send, done) => {
|
this.node.on('input', (msg, send, _done) => {
|
||||||
/* Update to complete event based node by putting the tick function after an input event */
|
/* Update to complete event based node by putting the tick function after an input event */
|
||||||
const m = this.source;
|
const m = this.source;
|
||||||
switch(msg.topic) {
|
switch(msg.topic) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const {loadCurve,gravity,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils,coolprop} = require('generalFunctions');
|
const {loadCurve,gravity,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils,coolprop, POSITIONS} = require('generalFunctions');
|
||||||
|
|
||||||
class Machine {
|
class Machine {
|
||||||
|
|
||||||
@@ -97,9 +97,9 @@ class Machine {
|
|||||||
|
|
||||||
_init(){
|
_init(){
|
||||||
//assume standard temperature is 20degrees
|
//assume standard temperature is 20degrees
|
||||||
this.measurements.type('temperature').variant('measured').position('atEquipment').value(15).unit('C');
|
this.measurements.type('temperature').variant('measured').position(POSITIONS.AT_EQUIPMENT).value(15).unit('C');
|
||||||
//assume standard atm pressure is at sea level
|
//assume standard atm pressure is at sea level
|
||||||
this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325).unit('Pa');
|
this.measurements.type('atmPressure').variant('measured').position(POSITIONS.AT_EQUIPMENT).value(101325).unit('Pa');
|
||||||
//populate min and max
|
//populate min and max
|
||||||
if (this.predictFlow) {
|
if (this.predictFlow) {
|
||||||
const flowunit = this.config.general.unit;
|
const flowunit = this.config.general.unit;
|
||||||
@@ -112,8 +112,8 @@ class Machine {
|
|||||||
const isOperational = this._isOperationalState();
|
const isOperational = this._isOperationalState();
|
||||||
if(!isOperational){
|
if(!isOperational){
|
||||||
//overrule the last prediction this should be 0 now
|
//overrule the last prediction this should be 0 now
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(0,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0,Date.now(),this.config.general.unit);
|
||||||
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0,Date.now(),this.config.general.unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,6 @@ class Machine {
|
|||||||
|
|
||||||
_connectMeasurement(measurementChild) {
|
_connectMeasurement(measurementChild) {
|
||||||
const position = measurementChild.config.functionality.positionVsParent;
|
const position = measurementChild.config.functionality.positionVsParent;
|
||||||
const distance = measurementChild.config.functionality.distanceVsParent || 0;
|
|
||||||
const measurementType = measurementChild.config.asset.type;
|
const measurementType = measurementChild.config.asset.type;
|
||||||
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
|
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
|
||||||
const eventName = `${measurementType}.measured.${position}`;
|
const eventName = `${measurementType}.measured.${position}`;
|
||||||
@@ -194,8 +193,8 @@ class Machine {
|
|||||||
// Method to assess drift using errorMetrics
|
// Method to assess drift using errorMetrics
|
||||||
assessDrift(measurement, processMin, processMax) {
|
assessDrift(measurement, processMin, processMax) {
|
||||||
this.logger.debug(`Assessing drift for measurement: ${measurement} processMin: ${processMin} processMax: ${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 predictedMeasurement = this.measurements.type(measurement).variant("predicted").position(POSITIONS.DOWNSTREAM).getAllValues().values;
|
||||||
const measuredMeasurement = this.measurements.type(measurement).variant("measured").position("downstream").getAllValues().values;
|
const measuredMeasurement = this.measurements.type(measurement).variant("measured").position(POSITIONS.DOWNSTREAM).getAllValues().values;
|
||||||
|
|
||||||
if (!predictedMeasurement || !measuredMeasurement) return null;
|
if (!predictedMeasurement || !measuredMeasurement) return null;
|
||||||
|
|
||||||
@@ -372,23 +371,23 @@ class Machine {
|
|||||||
calcFlow(x) {
|
calcFlow(x) {
|
||||||
if(this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
if (!this._isOperationalState()) {
|
if (!this._isOperationalState()) {
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(0,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0,Date.now(),this.config.general.unit);
|
||||||
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0,Date.now(),this.config.general.unit);
|
||||||
this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`);
|
this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cFlow = this.predictFlow.y(x);
|
const cFlow = this.predictFlow.y(x);
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(cFlow,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(cFlow,Date.now(),this.config.general.unit);
|
||||||
this.measurements.type("flow").variant("predicted").position("atEquipment").value(cFlow,Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cFlow,Date.now(),this.config.general.unit);
|
||||||
//this.logger.debug(`Calculated flow: ${cFlow} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
//this.logger.debug(`Calculated flow: ${cFlow} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
||||||
return cFlow;
|
return cFlow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no curve data is available, log a warning and return 0
|
// If no curve data is available, log a warning and return 0
|
||||||
this.logger.warn(`No curve data available for flow calculation. Returning 0.`);
|
this.logger.warn(`No curve data available for flow calculation. Returning 0.`);
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(0, Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0, Date.now(),this.config.general.unit);
|
||||||
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0, Date.now(),this.config.general.unit);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0, Date.now(),this.config.general.unit);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -397,20 +396,20 @@ class Machine {
|
|||||||
calcPower(x) {
|
calcPower(x) {
|
||||||
if(this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
if (!this._isOperationalState()) {
|
if (!this._isOperationalState()) {
|
||||||
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
|
||||||
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
|
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.predictPower.currentX = x; Decrepated
|
//this.predictPower.currentX = x; Decrepated
|
||||||
const cPower = this.predictPower.y(x);
|
const cPower = this.predictPower.y(x);
|
||||||
this.measurements.type("power").variant("predicted").position('atEquipment').value(cPower);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cPower);
|
||||||
//this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
//this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
||||||
return cPower;
|
return cPower;
|
||||||
}
|
}
|
||||||
// If no curve data is available, log a warning and return 0
|
// If no curve data is available, log a warning and return 0
|
||||||
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
|
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
|
||||||
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -428,7 +427,7 @@ class Machine {
|
|||||||
|
|
||||||
// If no curve data is available, log a warning and return 0
|
// If no curve data is available, log a warning and return 0
|
||||||
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
|
this.logger.warn(`No curve data available for power calculation. Returning 0.`);
|
||||||
this.measurements.type("power").variant("predicted").position('atEquipment').value(0);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -438,14 +437,14 @@ class Machine {
|
|||||||
if(this.hasCurve) {
|
if(this.hasCurve) {
|
||||||
this.predictCtrl.currentX = x;
|
this.predictCtrl.currentX = x;
|
||||||
const cCtrl = this.predictCtrl.y(x);
|
const cCtrl = this.predictCtrl.y(x);
|
||||||
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(cCtrl);
|
this.measurements.type("ctrl").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cCtrl);
|
||||||
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
|
||||||
return cCtrl;
|
return cCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no curve data is available, log a warning and return 0
|
// If no curve data is available, log a warning and return 0
|
||||||
this.logger.warn(`No curve data available for control calculation. Returning 0.`);
|
this.logger.warn(`No curve data available for control calculation. Returning 0.`);
|
||||||
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(0);
|
this.measurements.type("ctrl").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -477,7 +476,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get downstream
|
// get downstream
|
||||||
const downstreamPressure = this.measurements.type('pressure').variant('measured').position('downstream').getCurrentValue();
|
const downstreamPressure = this.measurements.type('pressure').variant('measured').position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
|
|
||||||
// Only downstream => use it, warn that it's partial
|
// Only downstream => use it, warn that it's partial
|
||||||
if (downstreamPressure != null) {
|
if (downstreamPressure != null) {
|
||||||
@@ -531,7 +530,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
const upstreamFlow = this.measurements.type('flow').variant('measured').position('upstream').getCurrentValue();
|
const upstreamFlow = this.measurements.type('flow').variant('measured').position(POSITIONS.UPSTREAM).getCurrentValue();
|
||||||
|
|
||||||
// Only upstream => might still accept it, but warn
|
// Only upstream => might still accept it, but warn
|
||||||
if (upstreamFlow != null) {
|
if (upstreamFlow != null) {
|
||||||
@@ -540,7 +539,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
const downstreamFlow = this.measurements.type('flow').variant('measured').position('downstream').getCurrentValue();
|
const downstreamFlow = this.measurements.type('flow').variant('measured').position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
|
|
||||||
// Only downstream => might still accept it, but warn
|
// Only downstream => might still accept it, but warn
|
||||||
if (downstreamFlow != null) {
|
if (downstreamFlow != null) {
|
||||||
@@ -554,7 +553,7 @@ class Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleMeasuredPower() {
|
handleMeasuredPower() {
|
||||||
const power = this.measurements.type("power").variant("measured").position("atEquipment").getCurrentValue();
|
const power = this.measurements.type("power").variant("measured").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
// If your system calls it "upstream" or just a single "value", adjust accordingly
|
// If your system calls it "upstream" or just a single "value", adjust accordingly
|
||||||
|
|
||||||
if (power != null) {
|
if (power != null) {
|
||||||
@@ -600,8 +599,8 @@ class Machine {
|
|||||||
|
|
||||||
// Update predicted flow if you have prediction capability
|
// Update predicted flow if you have prediction capability
|
||||||
if (this.predictFlow) {
|
if (this.predictFlow) {
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(this.predictFlow.outputY || 0);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(this.predictFlow.outputY || 0);
|
||||||
this.measurements.type("flow").variant("predicted").position("atEquipment").value(this.predictFlow.outputY || 0);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(this.predictFlow.outputY || 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,35 +731,35 @@ class Machine {
|
|||||||
|
|
||||||
const pressureDiff = this.measurements.type('pressure').variant('measured').difference('Pa');
|
const pressureDiff = this.measurements.type('pressure').variant('measured').difference('Pa');
|
||||||
const g = gravity.getStandardGravity();
|
const g = gravity.getStandardGravity();
|
||||||
const temp = this.measurements.type('temperature').variant('measured').position('atEquipment').getCurrentValue('K');
|
const temp = this.measurements.type('temperature').variant('measured').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('K');
|
||||||
const atmPressure = this.measurements.type('atmPressure').variant('measured').position('atEquipment').getCurrentValue('Pa');
|
const atmPressure = this.measurements.type('atmPressure').variant('measured').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('Pa');
|
||||||
|
|
||||||
console.log(`--------------------calc efficiency : Pressure diff:${pressureDiff},${temp}, ${g} `);
|
console.log(`--------------------calc efficiency : Pressure diff:${pressureDiff},${temp}, ${g} `);
|
||||||
const rho = coolprop.PropsSI('D', 'T', temp, 'P', atmPressure, 'WasteWater');
|
const rho = coolprop.PropsSI('D', 'T', temp, 'P', atmPressure, 'WasteWater');
|
||||||
|
|
||||||
|
|
||||||
this.logger.debug(`temp: ${temp} atmPressure : ${atmPressure} rho : ${rho} pressureDiff: ${pressureDiff?.value || 0}`);
|
this.logger.debug(`temp: ${temp} atmPressure : ${atmPressure} rho : ${rho} pressureDiff: ${pressureDiff?.value || 0}`);
|
||||||
const flowM3s = this.measurements.type('flow').variant('predicted').position('atEquipment').getCurrentValue('m3/s');
|
const flowM3s = this.measurements.type('flow').variant('predicted').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('m3/s');
|
||||||
const powerWatt = this.measurements.type('power').variant('predicted').position('atEquipment').getCurrentValue('W');
|
const powerWatt = this.measurements.type('power').variant('predicted').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('W');
|
||||||
this.logger.debug(`Flow : ${flowM3s} power: ${powerWatt}`);
|
this.logger.debug(`Flow : ${flowM3s} power: ${powerWatt}`);
|
||||||
|
|
||||||
if (power != 0 && flow != 0) {
|
if (power != 0 && flow != 0) {
|
||||||
const specificFlow = flow / power;
|
const specificFlow = flow / power;
|
||||||
const specificEnergyConsumption = power / flow;
|
const specificEnergyConsumption = power / flow;
|
||||||
|
|
||||||
this.measurements.type("efficiency").variant(variant).position('atEquipment').value(specificFlow);
|
this.measurements.type("efficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(specificFlow);
|
||||||
this.measurements.type("specificEnergyConsumption").variant(variant).position('atEquipment').value(specificEnergyConsumption);
|
this.measurements.type("specificEnergyConsumption").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(specificEnergyConsumption);
|
||||||
|
|
||||||
if(pressureDiff?.value != null && flowM3s != null && powerWatt != null){
|
if(pressureDiff?.value != null && flowM3s != null && powerWatt != null){
|
||||||
const meterPerBar = pressureDiff.value / rho * g;
|
const meterPerBar = pressureDiff.value / rho * g;
|
||||||
const nHydraulicEfficiency = rho * g * flowM3s * (pressureDiff.value * meterPerBar ) / powerWatt;
|
const nHydraulicEfficiency = rho * g * flowM3s * (pressureDiff.value * meterPerBar ) / powerWatt;
|
||||||
this.measurements.type("nHydraulicEfficiency").variant(variant).position('atEquipment').value(nHydraulicEfficiency);
|
this.measurements.type("nHydraulicEfficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(nHydraulicEfficiency);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//change this to nhydrefficiency ?
|
//change this to nhydrefficiency ?
|
||||||
return this.measurements.type("efficiency").variant(variant).position('atEquipment').getCurrentValue();
|
return this.measurements.type("efficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -860,7 +859,7 @@ const PT1 = new Child(config={
|
|||||||
},
|
},
|
||||||
functionality:{
|
functionality:{
|
||||||
softwareType:"measurement",
|
softwareType:"measurement",
|
||||||
positionVsParent:"upstream",
|
positionVsParent: POSITIONS.UPSTREAM,
|
||||||
},
|
},
|
||||||
asset:{
|
asset:{
|
||||||
supplier:"Vega",
|
supplier:"Vega",
|
||||||
@@ -882,7 +881,7 @@ const PT2 = new Child(config={
|
|||||||
},
|
},
|
||||||
functionality:{
|
functionality:{
|
||||||
softwareType:"measurement",
|
softwareType:"measurement",
|
||||||
positionVsParent:"upstream",
|
positionVsParent: POSITIONS.UPSTREAM,
|
||||||
},
|
},
|
||||||
asset:{
|
asset:{
|
||||||
supplier:"Vega",
|
supplier:"Vega",
|
||||||
@@ -936,8 +935,8 @@ const machine = new Machine(machineConfig, stateConfig);
|
|||||||
|
|
||||||
//machine.logger.info(JSON.stringify(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]));
|
//machine.logger.info(JSON.stringify(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]));
|
||||||
machine.logger.info(`Registering child...`);
|
machine.logger.info(`Registering child...`);
|
||||||
machine.childRegistrationUtils.registerChild(PT1, "upstream");
|
machine.childRegistrationUtils.registerChild(PT1, POSITIONS.UPSTREAM);
|
||||||
machine.childRegistrationUtils.registerChild(PT2, "downstream");
|
machine.childRegistrationUtils.registerChild(PT2, POSITIONS.DOWNSTREAM);
|
||||||
|
|
||||||
//feed curve to the machine class
|
//feed curve to the machine class
|
||||||
//machine.updateCurve(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]);
|
//machine.updateCurve(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]);
|
||||||
@@ -950,8 +949,8 @@ machine.getOutput();
|
|||||||
//manual test
|
//manual test
|
||||||
//machine.handleInput("parent", "execSequence", "startup");
|
//machine.handleInput("parent", "execSequence", "startup");
|
||||||
|
|
||||||
machine.measurements.type("pressure").variant("measured").position('upstream').value(-200);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(-200);
|
||||||
machine.measurements.type("pressure").variant("measured").position('downstream').value(1000);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(1000);
|
||||||
|
|
||||||
testingSequences();
|
testingSequences();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user