Align machineGroupControl with current architecture
This commit is contained in:
43
mgc.html
43
mgc.html
@@ -1,15 +1,12 @@
|
|||||||
<!--
|
<!--
|
||||||
brabantse delta kleuren:
|
| S88-niveau | Primair (blokkleur) | Tekstkleur |
|
||||||
#eaf4f1
|
| ---------------------- | ------------------- | ---------- |
|
||||||
#86bbdd
|
| **Area** | `#0f52a5` | wit |
|
||||||
#bad33b
|
| **Process Cell** | `#0c99d9` | wit |
|
||||||
#0c99d9
|
| **Unit** | `#50a8d9` | zwart |
|
||||||
#a9daee
|
| **Equipment (Module)** | `#86bbdd` | zwart |
|
||||||
#0f52a5
|
| **Control Module** | `#a9daee` | zwart |
|
||||||
#50a8d9
|
|
||||||
#cade63
|
|
||||||
#4f8582
|
|
||||||
#c4cce0
|
|
||||||
-->
|
-->
|
||||||
<script src="/machineGroupControl/menu.js"></script> <!-- Load the menu script for dynamic dropdowns -->
|
<script src="/machineGroupControl/menu.js"></script> <!-- Load the menu script for dynamic dropdowns -->
|
||||||
<script src="/machineGroupControl/configData.js"></script> <!-- Load the config script for node information -->
|
<script src="/machineGroupControl/configData.js"></script> <!-- Load the config script for node information -->
|
||||||
@@ -17,10 +14,12 @@
|
|||||||
<script>
|
<script>
|
||||||
RED.nodes.registerType('machineGroupControl',{
|
RED.nodes.registerType('machineGroupControl',{
|
||||||
category: "EVOLV",
|
category: "EVOLV",
|
||||||
color: "#eaf4f1",
|
color: "#50a8d9",
|
||||||
defaults: {
|
defaults: {
|
||||||
// Define default properties
|
// Define default properties
|
||||||
name: { value: "" },
|
name: { value: "" },
|
||||||
|
processOutputFormat: { value: "process" },
|
||||||
|
dbaseOutputFormat: { value: "influxdb" },
|
||||||
|
|
||||||
// Logger properties
|
// Logger properties
|
||||||
enableLog: { value: false },
|
enableLog: { value: false },
|
||||||
@@ -39,7 +38,7 @@
|
|||||||
outputs:3,
|
outputs:3,
|
||||||
inputLabels: ["Input"],
|
inputLabels: ["Input"],
|
||||||
outputLabels: ["process", "dbase", "parent"],
|
outputLabels: ["process", "dbase", "parent"],
|
||||||
icon: "font-awesome/fa-tachometer",
|
icon: "font-awesome/fa-cogs",
|
||||||
|
|
||||||
label: function () {
|
label: function () {
|
||||||
return this.positionIcon + " " + "machineGroup";
|
return this.positionIcon + " " + "machineGroup";
|
||||||
@@ -77,6 +76,24 @@
|
|||||||
|
|
||||||
<script type="text/html" data-template-name="machineGroupControl">
|
<script type="text/html" data-template-name="machineGroupControl">
|
||||||
|
|
||||||
|
<h3>Output Formats</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-processOutputFormat"><i class="fa fa-random"></i> Process Output</label>
|
||||||
|
<select id="node-input-processOutputFormat" style="width:60%;">
|
||||||
|
<option value="process">process</option>
|
||||||
|
<option value="json">json</option>
|
||||||
|
<option value="csv">csv</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-dbaseOutputFormat"><i class="fa fa-database"></i> Database Output</label>
|
||||||
|
<select id="node-input-dbaseOutputFormat" style="width:60%;">
|
||||||
|
<option value="influxdb">influxdb</option>
|
||||||
|
<option value="json">json</option>
|
||||||
|
<option value="csv">csv</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Logger fields injected here -->
|
<!-- Logger fields injected here -->
|
||||||
<div id="logger-fields-placeholder"></div>
|
<div id="logger-fields-placeholder"></div>
|
||||||
|
|
||||||
|
|||||||
@@ -38,21 +38,9 @@ class nodeClass {
|
|||||||
const cfgMgr = new configManager();
|
const cfgMgr = new configManager();
|
||||||
this.defaultConfig = cfgMgr.getConfig(this.name);
|
this.defaultConfig = cfgMgr.getConfig(this.name);
|
||||||
|
|
||||||
// Merge UI config over defaults
|
// Build config: base sections (no domain-specific config for group controller)
|
||||||
this.config = {
|
this.config = cfgMgr.buildConfig(this.name, uiConfig, node.id);
|
||||||
general: {
|
|
||||||
name: uiConfig.name,
|
|
||||||
id: node.id, // node.id is for the child registration process
|
|
||||||
unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards)
|
|
||||||
logging: {
|
|
||||||
enabled: uiConfig.enableLog,
|
|
||||||
logLevel: uiConfig.logLevel,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
functionality: {
|
|
||||||
positionVsParent: uiConfig.positionVsParent || "atEquipment", // Default to 'atEquipment' if not set
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// Utility for formatting outputs
|
// Utility for formatting outputs
|
||||||
this._output = new outputUtils();
|
this._output = new outputUtils();
|
||||||
}
|
}
|
||||||
@@ -80,7 +68,7 @@ class nodeClass {
|
|||||||
const availableMachines = Object.values(mg.machines || {}).filter((machine) => {
|
const availableMachines = Object.values(mg.machines || {}).filter((machine) => {
|
||||||
// Safety check: ensure machine and machine.state exist
|
// Safety check: ensure machine and machine.state exist
|
||||||
if (!machine || !machine.state || typeof machine.state.getCurrentState !== 'function') {
|
if (!machine || !machine.state || typeof machine.state.getCurrentState !== 'function') {
|
||||||
console.warn(`Machine missing or invalid:`, machine?.config?.general?.id || 'unknown');
|
mg.logger.warn(`Machine missing or invalid: ${machine?.config?.general?.id || 'unknown'}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,40 +186,35 @@ class nodeClass {
|
|||||||
const mg = this.source;
|
const mg = this.source;
|
||||||
const RED = this.RED;
|
const RED = this.RED;
|
||||||
switch (msg.topic) {
|
switch (msg.topic) {
|
||||||
case "registerChild":
|
case "registerChild": {
|
||||||
console.log(`Registering child in mgc: ${msg.payload}`);
|
|
||||||
const childId = msg.payload;
|
const childId = msg.payload;
|
||||||
const childObj = RED.nodes.getNode(childId);
|
const childObj = RED.nodes.getNode(childId);
|
||||||
|
|
||||||
// Debug: Check what we're getting
|
mg.logger.debug(`Registering child: ${childId}, found: ${!!childObj}, source: ${!!childObj?.source}`);
|
||||||
console.log(`Child object:`, childObj ? 'found' : 'NOT FOUND');
|
|
||||||
console.log(`Child source:`, childObj?.source ? 'exists' : 'MISSING');
|
|
||||||
if (childObj?.source) {
|
|
||||||
console.log(`Child source type:`, childObj.source.constructor.name);
|
|
||||||
console.log(`Child has state:`, !!childObj.source.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
mg.childRegistrationUtils.registerChild(
|
mg.childRegistrationUtils.registerChild(
|
||||||
childObj.source,
|
childObj.source,
|
||||||
msg.positionVsParent
|
msg.positionVsParent
|
||||||
);
|
);
|
||||||
|
|
||||||
// Debug: Check machines after registration
|
mg.logger.debug(`Total machines after registration: ${Object.keys(mg.machines || {}).length}`);
|
||||||
console.log(`Total machines after registration:`, Object.keys(mg.machines || {}).length);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "setMode":
|
case "setMode": {
|
||||||
const mode = msg.payload;
|
const mode = msg.payload;
|
||||||
mg.setMode(mode);
|
mg.setMode(mode);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "setScaling":
|
case "setScaling": {
|
||||||
const scaling = msg.payload;
|
const scaling = msg.payload;
|
||||||
mg.setScaling(scaling);
|
mg.setScaling(scaling);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "Qd":
|
case "Qd": {
|
||||||
const Qd = parseFloat(msg.payload);
|
const Qd = parseFloat(msg.payload);
|
||||||
const sourceQd = "parent";
|
const sourceQd = "parent";
|
||||||
|
|
||||||
@@ -245,9 +228,10 @@ class nodeClass {
|
|||||||
msg.payload = "done";
|
msg.payload = "done";
|
||||||
send(msg);
|
send(msg);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
mg.logger.error(`Demand handling failed: ${e.message}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Handle unknown topics if needed
|
// Handle unknown topics if needed
|
||||||
|
|||||||
@@ -1,20 +1,6 @@
|
|||||||
/**
|
|
||||||
* @summary A class to interact and manipulate machines with a non-euclidian curve
|
|
||||||
* @description A class to interact and manipulate machines with a non-euclidian curve
|
|
||||||
* @module machineGroup
|
|
||||||
* @exports machineGroup
|
|
||||||
* @version 0.1.0
|
|
||||||
* @since 0.1.0
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* - Rene De Ren
|
|
||||||
* Email:
|
|
||||||
* - r.de.ren@brabantsedelta.nl
|
|
||||||
*/
|
|
||||||
|
|
||||||
//load local dependencies
|
//load local dependencies
|
||||||
const EventEmitter = require("events");
|
const EventEmitter = require("events");
|
||||||
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils} = require('generalFunctions');
|
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils, POSITIONS} = require('generalFunctions');
|
||||||
|
|
||||||
class MachineGroup {
|
class MachineGroup {
|
||||||
constructor(machineGroupConfig = {}) {
|
constructor(machineGroupConfig = {}) {
|
||||||
@@ -89,7 +75,7 @@ class MachineGroup {
|
|||||||
Object.values(this.machines).forEach(machine => {
|
Object.values(this.machines).forEach(machine => {
|
||||||
const totals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
|
const totals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
|
||||||
//fetch min flow ever seen over all machines
|
//fetch min flow ever seen over all machines
|
||||||
Object.entries(machine.predictFlow.inputCurve).forEach(([pressure, xyCurve], index) => {
|
Object.entries(machine.predictFlow.inputCurve).forEach(([pressure, xyCurve], _index) => {
|
||||||
const minFlow = Math.min(...xyCurve.y);
|
const minFlow = Math.min(...xyCurve.y);
|
||||||
const maxFlow = Math.max(...xyCurve.y);
|
const maxFlow = Math.max(...xyCurve.y);
|
||||||
|
|
||||||
@@ -154,8 +140,8 @@ class MachineGroup {
|
|||||||
const maxFlow = machine.predictFlow.currentFxyYMax;
|
const maxFlow = machine.predictFlow.currentFxyYMax;
|
||||||
const minPower = machine.predictPower.currentFxyYMin;
|
const minPower = machine.predictPower.currentFxyYMin;
|
||||||
const maxPower = machine.predictPower.currentFxyYMax;
|
const maxPower = machine.predictPower.currentFxyYMax;
|
||||||
const actFlow = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
const actFlow = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
const actPower = machine.measurements.type("power").variant("predicted").position("atEquipment").getCurrentValue();
|
const actPower = machine.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
|
|
||||||
this.logger.debug(`Machine ${machine.config.general.id} - Min Flow: ${minFlow}, Max Flow: ${maxFlow}, Min Power: ${minPower}, Max Power: ${maxPower}, NCog: ${machine.NCog}`);
|
this.logger.debug(`Machine ${machine.config.general.id} - Min Flow: ${minFlow}, Max Flow: ${maxFlow}, Min Power: ${minPower}, Max Power: ${maxPower}, NCog: ${machine.NCog}`);
|
||||||
|
|
||||||
@@ -209,11 +195,11 @@ class MachineGroup {
|
|||||||
const { flow, power } = this.calcDynamicTotals();
|
const { flow, power } = this.calcDynamicTotals();
|
||||||
|
|
||||||
this.logger.debug(`Dynamic Totals after pressure change - Flow: Min ${flow.min}, Max ${flow.max}, Act ${flow.act} | Power: Min ${power.min}, Max ${power.max}, Act ${power.act}`);
|
this.logger.debug(`Dynamic Totals after pressure change - Flow: Min ${flow.min}, Max ${flow.max}, Act ${flow.act} | Power: Min ${power.min}, Max ${power.max}, Act ${power.act}`);
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(flow.act);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(flow.act);
|
||||||
this.measurements.type("power").variant("predicted").position("atEquipment").value(power.act);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(power.act);
|
||||||
|
|
||||||
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
||||||
const efficiency = this.measurements.type("efficiency").variant("predicted").position("atEquipment").getCurrentValue();
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,11 +235,11 @@ class MachineGroup {
|
|||||||
//add special cases
|
//add special cases
|
||||||
if( state === "operational" && ( mode == "virtualControl" || mode === "fysicalControl") ){
|
if( state === "operational" && ( mode == "virtualControl" || mode === "fysicalControl") ){
|
||||||
let flow = 0;
|
let flow = 0;
|
||||||
if(machine.measurements.type("flow").variant("measured").position("downstream").getCurrentValue()){
|
if(machine.measurements.type("flow").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue()){
|
||||||
flow = machine.measurements.type("flow").variant("measured").position("downstream").getCurrentValue();
|
flow = machine.measurements.type("flow").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
}
|
}
|
||||||
else if(machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue()){
|
else if(machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue()){
|
||||||
flow = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
flow = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this.logger.error("Dont perform calculation at all seeing that there is a machine working but we dont know the flow its producing");
|
this.logger.error("Dont perform calculation at all seeing that there is a machine working but we dont know the flow its producing");
|
||||||
@@ -403,10 +389,10 @@ class MachineGroup {
|
|||||||
try{
|
try{
|
||||||
//we need to force the pressures of all machines to be equal to the highest pressure measured in the group
|
//we need to force the pressures of all machines to be equal to the highest pressure measured in the group
|
||||||
// this is to ensure a correct evaluation of the flow and power consumption
|
// this is to ensure a correct evaluation of the flow and power consumption
|
||||||
const pressures = Object.entries(this.machines).map(([machineId, machine]) => {
|
const pressures = Object.entries(this.machines).map(([_machineId, machine]) => {
|
||||||
return {
|
return {
|
||||||
downstream: machine.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(),
|
downstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue(),
|
||||||
upstream: machine.measurements.type("pressure").variant("measured").position("upstream").getCurrentValue()
|
upstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).getCurrentValue()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -416,12 +402,12 @@ class MachineGroup {
|
|||||||
this.logger.debug(`Max downstream pressure: ${maxDownstream}, Min upstream pressure: ${minUpstream}`);
|
this.logger.debug(`Max downstream pressure: ${maxDownstream}, Min upstream pressure: ${minUpstream}`);
|
||||||
|
|
||||||
//set the pressures
|
//set the pressures
|
||||||
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
Object.entries(this.machines).forEach(([_machineId, machine]) => {
|
||||||
if(machine.state.getCurrentState() !== "operational" && machine.state.getCurrentState() !== "accelerating" && machine.state.getCurrentState() !== "decelerating"){
|
if(machine.state.getCurrentState() !== "operational" && machine.state.getCurrentState() !== "accelerating" && machine.state.getCurrentState() !== "decelerating"){
|
||||||
|
|
||||||
//Equilize pressures over all machines so we can make a proper calculation
|
//Equilize pressures over all machines so we can make a proper calculation
|
||||||
machine.measurements.type("pressure").variant("measured").position("downstream").value(maxDownstream);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(maxDownstream);
|
||||||
machine.measurements.type("pressure").variant("measured").position("upstream").value(minUpstream);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(minUpstream);
|
||||||
|
|
||||||
// after updating the measurement directly we need to force the update of the value OLIFANT this is not so clear now in the code
|
// after updating the measurement directly we need to force the update of the value OLIFANT this is not so clear now in the code
|
||||||
// we need to find a better way to do this but for now it works
|
// we need to find a better way to do this but for now it works
|
||||||
@@ -465,10 +451,10 @@ class MachineGroup {
|
|||||||
this.logger.debug(`Moving to demand: ${Qd.toFixed(2)} -> Pumps: [${debugInfo}] => Total Power: ${bestResult.bestPower.toFixed(2)}`);
|
this.logger.debug(`Moving to demand: ${Qd.toFixed(2)} -> Pumps: [${debugInfo}] => Total Power: ${bestResult.bestPower.toFixed(2)}`);
|
||||||
|
|
||||||
//store the total delivered power
|
//store the total delivered power
|
||||||
this.measurements.type("power").variant("predicted").position("atEquipment").value(bestResult.bestPower);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestPower);
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(bestResult.bestFlow);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(bestResult.bestFlow);
|
||||||
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(bestResult.bestFlow / bestResult.bestPower);
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestFlow / bestResult.bestPower);
|
||||||
this.measurements.type("Ncog").variant("predicted").position("atEquipment").value(bestResult.bestCog);
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestCog);
|
||||||
|
|
||||||
await Promise.all(Object.entries(this.machines).map(async ([machineId, machine]) => {
|
await Promise.all(Object.entries(this.machines).map(async ([machineId, machine]) => {
|
||||||
// Find the flow for this machine in the best combination
|
// Find the flow for this machine in the best combination
|
||||||
@@ -504,10 +490,10 @@ class MachineGroup {
|
|||||||
// Equalize pressure across all machines for machines that are not running. This is needed to ensure accurate flow and power predictions.
|
// Equalize pressure across all machines for machines that are not running. This is needed to ensure accurate flow and power predictions.
|
||||||
equalizePressure(){
|
equalizePressure(){
|
||||||
// Get current pressures from all machines
|
// Get current pressures from all machines
|
||||||
const pressures = Object.entries(this.machines).map(([machineId, machine]) => {
|
const pressures = Object.entries(this.machines).map(([_machineId, machine]) => {
|
||||||
return {
|
return {
|
||||||
downstream: machine.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(),
|
downstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue(),
|
||||||
upstream: machine.measurements.type("pressure").variant("measured").position("upstream").getCurrentValue()
|
upstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).getCurrentValue()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -518,8 +504,8 @@ class MachineGroup {
|
|||||||
// Set consistent pressures across machines
|
// Set consistent pressures across machines
|
||||||
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
||||||
if(!this.isMachineActive(machineId)){
|
if(!this.isMachineActive(machineId)){
|
||||||
machine.measurements.type("pressure").variant("measured").position("downstream").value(maxDownstream);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(maxDownstream);
|
||||||
machine.measurements.type("pressure").variant("measured").position("upstream").value(minUpstream);
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(minUpstream);
|
||||||
// Update the measured pressure value
|
// Update the measured pressure value
|
||||||
const pressure = machine.getMeasuredPressure();
|
const pressure = machine.getMeasuredPressure();
|
||||||
this.logger.debug(`Setting pressure for machine ${machineId} to ${pressure}`);
|
this.logger.debug(`Setting pressure for machine ${machineId} to ${pressure}`);
|
||||||
@@ -563,7 +549,7 @@ class MachineGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterOutUnavailableMachines(list) {
|
filterOutUnavailableMachines(list) {
|
||||||
const newList = list.filter(({ id, machine }) => {
|
const newList = list.filter(({ machine }) => {
|
||||||
const state = machine.state.getCurrentState();
|
const state = machine.state.getCurrentState();
|
||||||
const validActionForMode = machine.isValidActionForMode("execSequence", "auto");
|
const validActionForMode = machine.isValidActionForMode("execSequence", "auto");
|
||||||
|
|
||||||
@@ -578,7 +564,7 @@ class MachineGroup {
|
|||||||
let lowestEfficiency = Infinity;
|
let lowestEfficiency = Infinity;
|
||||||
|
|
||||||
// Calculate the average efficiency of all machines -> peak is the average of them all
|
// Calculate the average efficiency of all machines -> peak is the average of them all
|
||||||
Object.entries(machines).forEach(([machineId, machine]) => {
|
Object.entries(machines).forEach(([_machineId, machine]) => {
|
||||||
cumEfficiency += machine.cog;
|
cumEfficiency += machine.cog;
|
||||||
if(machine.cog < lowestEfficiency){
|
if(machine.cog < lowestEfficiency){
|
||||||
lowestEfficiency = machine.cog;
|
lowestEfficiency = machine.cog;
|
||||||
@@ -593,7 +579,7 @@ class MachineGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//move machines assuming equal control in flow and a priority list
|
//move machines assuming equal control in flow and a priority list
|
||||||
async equalFlowControl(Qd, powerCap = Infinity, priorityList = null) {
|
async equalFlowControl(Qd, _powerCap = Infinity, priorityList = null) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// equalize pressure across all machines
|
// equalize pressure across all machines
|
||||||
@@ -648,7 +634,7 @@ class MachineGroup {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case (Qd > activeTotals.flow.max):
|
case (Qd > activeTotals.flow.max): {
|
||||||
// Case 2: Demand is above the maximum available flow.
|
// Case 2: Demand is above the maximum available flow.
|
||||||
// Start the non-active machine with the highest priority and distribute Qd over all available machines.
|
// Start the non-active machine with the highest priority and distribute Qd over all available machines.
|
||||||
let i = 1;
|
let i = 1;
|
||||||
@@ -668,9 +654,10 @@ class MachineGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
// Default case: Demand is within the active range.
|
// Default case: Demand is within the active range.
|
||||||
const countActiveMachines = machinesInPriorityOrder.filter(({ id }) => this.isMachineActive(id)).length;
|
const countActiveMachines = machinesInPriorityOrder.filter(({ id }) => this.isMachineActive(id)).length;
|
||||||
|
|
||||||
@@ -684,6 +671,7 @@ class MachineGroup {
|
|||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log information about flow distribution
|
// Log information about flow distribution
|
||||||
@@ -695,10 +683,10 @@ class MachineGroup {
|
|||||||
this.logger.debug(`Priority control for demand: ${totalFlow.toFixed(2)} -> Active pumps: [${debugInfo}] => Total Power: ${totalPower.toFixed(2)}`);
|
this.logger.debug(`Priority control for demand: ${totalFlow.toFixed(2)} -> Active pumps: [${debugInfo}] => Total Power: ${totalPower.toFixed(2)}`);
|
||||||
|
|
||||||
// Store measurements
|
// Store measurements
|
||||||
this.measurements.type("power").variant("predicted").position("atEquipment").value(totalPower);
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalPower);
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(totalFlow);
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(totalFlow);
|
||||||
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(totalFlow / totalPower);
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalFlow / totalPower);
|
||||||
this.measurements.type("Ncog").variant("predicted").position("atEquipment").value(totalCog);
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalCog);
|
||||||
|
|
||||||
this.logger.debug(`Flow distribution: ${JSON.stringify(flowDistribution)}`);
|
this.logger.debug(`Flow distribution: ${JSON.stringify(flowDistribution)}`);
|
||||||
// Apply the flow distribution to machines
|
// Apply the flow distribution to machines
|
||||||
@@ -736,7 +724,7 @@ class MachineGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//capp input to 100
|
//capp input to 100
|
||||||
input > 100 ? input = 100 : input = input;
|
if (input > 100) { input = 100; }
|
||||||
|
|
||||||
const numOfMachines = Object.keys(this.machines).length;
|
const numOfMachines = Object.keys(this.machines).length;
|
||||||
const procentTotal = numOfMachines * input;
|
const procentTotal = numOfMachines * input;
|
||||||
@@ -750,7 +738,7 @@ class MachineGroup {
|
|||||||
if(machinesNeeded > machinesActive){
|
if(machinesNeeded > machinesActive){
|
||||||
|
|
||||||
//start extra machine and put all active machines at min control
|
//start extra machine and put all active machines at min control
|
||||||
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
||||||
if(index < machinesNeeded){
|
if(index < machinesNeeded){
|
||||||
ctrlDistribution.push({machineId : id, ctrl : 0});
|
ctrlDistribution.push({machineId : id, ctrl : 0});
|
||||||
}
|
}
|
||||||
@@ -759,7 +747,7 @@ class MachineGroup {
|
|||||||
|
|
||||||
if(machinesNeeded < machinesActive){
|
if(machinesNeeded < machinesActive){
|
||||||
|
|
||||||
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
||||||
if(this.isMachineActive(id)){
|
if(this.isMachineActive(id)){
|
||||||
if(index < machinesNeeded){
|
if(index < machinesNeeded){
|
||||||
ctrlDistribution.push({machineId : id, ctrl : 100});
|
ctrlDistribution.push({machineId : id, ctrl : 100});
|
||||||
@@ -776,7 +764,7 @@ class MachineGroup {
|
|||||||
// distribute input equally among active machines (0 - 100%)
|
// distribute input equally among active machines (0 - 100%)
|
||||||
const ctrlPerMachine = procentTotal / machinesActive;
|
const ctrlPerMachine = procentTotal / machinesActive;
|
||||||
|
|
||||||
machinesInPriorityOrder.forEach(({ id, machine }) => {
|
machinesInPriorityOrder.forEach(({ id }) => {
|
||||||
if (this.isMachineActive(id)) {
|
if (this.isMachineActive(id)) {
|
||||||
// ensure ctrl is capped between 0 and 100%
|
// ensure ctrl is capped between 0 and 100%
|
||||||
const ctrlValue = Math.max(0, Math.min(ctrlPerMachine, 100));
|
const ctrlValue = Math.max(0, Math.min(ctrlPerMachine, 100));
|
||||||
@@ -808,10 +796,10 @@ class MachineGroup {
|
|||||||
const totalFlow = [];
|
const totalFlow = [];
|
||||||
|
|
||||||
// fetch and store measurements
|
// fetch and store measurements
|
||||||
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
Object.entries(this.machines).forEach(([_machineId, machine]) => {
|
||||||
|
|
||||||
const powerValue = machine.measurements.type("power").variant("predicted").position("atEquipment").getCurrentValue();
|
const powerValue = machine.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
const flowValue = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
const flowValue = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
|
|
||||||
if (powerValue !== null) {
|
if (powerValue !== null) {
|
||||||
totalPower.push(powerValue);
|
totalPower.push(powerValue);
|
||||||
@@ -821,11 +809,11 @@ class MachineGroup {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.measurements.type("power").variant("predicted").position("atEquipment").value(totalPower.reduce((a, b) => a + b, 0));
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalPower.reduce((a, b) => a + b, 0));
|
||||||
this.measurements.type("flow").variant("predicted").position("downstream").value(totalFlow.reduce((a, b) => a + b, 0));
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(totalFlow.reduce((a, b) => a + b, 0));
|
||||||
|
|
||||||
if(totalPower.reduce((a, b) => a + b, 0) > 0){
|
if(totalPower.reduce((a, b) => a + b, 0) > 0){
|
||||||
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(totalFlow.reduce((a, b) => a + b, 0) / totalPower.reduce((a, b) => a + b, 0));
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalFlow.reduce((a, b) => a + b, 0) / totalPower.reduce((a, b) => a + b, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -855,12 +843,12 @@ class MachineGroup {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (demandQ < absoluteTotals.flow.min) {
|
if (demandQ < this.absoluteTotals.flow.min) {
|
||||||
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${absoluteTotals.flow.min}. Capping to minimum flow.`);
|
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${this.absoluteTotals.flow.min}. Capping to minimum flow.`);
|
||||||
demandQout = this.absoluteTotals.flow.min;
|
demandQout = this.absoluteTotals.flow.min;
|
||||||
} else if (demandQout > absoluteTotals.flow.max) {
|
} else if (demandQout > this.absoluteTotals.flow.max) {
|
||||||
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${absoluteTotals.flow.max}. Capping to maximum flow.`);
|
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${this.absoluteTotals.flow.max}. Capping to maximum flow.`);
|
||||||
demandQout = absoluteTotals.flow.max;
|
demandQout = this.absoluteTotals.flow.max;
|
||||||
}else if(demandQout <= 0){
|
}else if(demandQout <= 0){
|
||||||
this.logger.debug(`Turning machines off`);
|
this.logger.debug(`Turning machines off`);
|
||||||
demandQout = 0;
|
demandQout = 0;
|
||||||
@@ -918,7 +906,7 @@ class MachineGroup {
|
|||||||
|
|
||||||
//recalc distance from BEP
|
//recalc distance from BEP
|
||||||
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
||||||
const efficiency = this.measurements.type("efficiency").variant("predicted").position("downstream").getCurrentValue();
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -942,9 +930,9 @@ class MachineGroup {
|
|||||||
this.measurements.getTypes().forEach(type => {
|
this.measurements.getTypes().forEach(type => {
|
||||||
this.measurements.getVariants(type).forEach(variant => {
|
this.measurements.getVariants(type).forEach(variant => {
|
||||||
|
|
||||||
const downstreamVal = this.measurements.type(type).variant(variant).position("downstream").getCurrentValue();
|
const downstreamVal = this.measurements.type(type).variant(variant).position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
||||||
const atEquipmentVal = this.measurements.type(type).variant(variant).position("atEquipment").getCurrentValue();
|
const atEquipmentVal = this.measurements.type(type).variant(variant).position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
||||||
const upstreamVal = this.measurements.type(type).variant(variant).position("upstream").getCurrentValue();
|
const upstreamVal = this.measurements.type(type).variant(variant).position(POSITIONS.UPSTREAM).getCurrentValue();
|
||||||
|
|
||||||
if (downstreamVal != null) {
|
if (downstreamVal != null) {
|
||||||
output[`downstream_${variant}_${type}`] = downstreamVal;
|
output[`downstream_${variant}_${type}`] = downstreamVal;
|
||||||
@@ -1101,11 +1089,11 @@ async function makeMachines(){
|
|||||||
for(let i = 1; i <= numofMachines; i++){
|
for(let i = 1; i <= numofMachines; i++){
|
||||||
const machine = new Machine(machineConfigs[i],stateConfigs[i]);
|
const machine = new Machine(machineConfigs[i],stateConfigs[i]);
|
||||||
//mg.machines[i] = machine;
|
//mg.machines[i] = machine;
|
||||||
mg.childRegistrationUtils.registerChild(machine, "downstream");
|
mg.childRegistrationUtils.registerChild(machine, POSITIONS.DOWNSTREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(mg.machines).forEach(machineId => {
|
Object.keys(mg.machines).forEach(machineId => {
|
||||||
mg.machines[machineId].childRegistrationUtils.registerChild(pt1, "downstream");
|
mg.machines[machineId].childRegistrationUtils.registerChild(pt1, POSITIONS.DOWNSTREAM);
|
||||||
});
|
});
|
||||||
|
|
||||||
mg.setMode("prioritycontrol");
|
mg.setMode("prioritycontrol");
|
||||||
|
|||||||
Reference in New Issue
Block a user