|
|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
//load local dependencies
|
|
|
|
|
const EventEmitter = require("events");
|
|
|
|
|
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils, convert} = require('generalFunctions');
|
|
|
|
|
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils, convert, POSITIONS} = require('generalFunctions');
|
|
|
|
|
|
|
|
|
|
const CANONICAL_UNITS = Object.freeze({
|
|
|
|
|
pressure: 'Pa',
|
|
|
|
|
@@ -123,7 +123,7 @@ class MachineGroup {
|
|
|
|
|
Object.values(this.machines).forEach(machine => {
|
|
|
|
|
const totals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
|
|
|
|
|
//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 maxFlow = Math.max(...xyCurve.y);
|
|
|
|
|
|
|
|
|
|
@@ -196,8 +196,8 @@ class MachineGroup {
|
|
|
|
|
const minPower = machine.predictPower.currentFxyYMin;
|
|
|
|
|
const maxPower = machine.predictPower.currentFxyYMax;
|
|
|
|
|
|
|
|
|
|
const actFlow = this._readChildMeasurement(machine, "flow", "predicted", "atequipment", this.unitPolicy.canonical.flow) || 0;
|
|
|
|
|
const actPower = this._readChildMeasurement(machine, "power", "predicted", "atequipment", this.unitPolicy.canonical.power) || 0;
|
|
|
|
|
const actFlow = this._readChildMeasurement(machine, "flow", "predicted", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.flow) || 0;
|
|
|
|
|
const actPower = this._readChildMeasurement(machine, "power", "predicted", POSITIONS.AT_EQUIPMENT, this.unitPolicy.canonical.power) || 0;
|
|
|
|
|
|
|
|
|
|
this.logger.debug(`Machine ${machine.config.general.id} - Min Flow: ${minFlow}, Max Flow: ${maxFlow}, Min Power: ${minPower}, Max Power: ${maxPower}, NCog: ${machine.NCog}`);
|
|
|
|
|
|
|
|
|
|
@@ -251,11 +251,11 @@ class MachineGroup {
|
|
|
|
|
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._writeMeasurement("flow", "predicted", "atequipment", flow.act, this.unitPolicy.canonical.flow);
|
|
|
|
|
this._writeMeasurement("power", "predicted", "atequipment", power.act, this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", POSITIONS.AT_EQUIPMENT, flow.act, this.unitPolicy.canonical.flow);
|
|
|
|
|
this._writeMeasurement("power", "predicted", POSITIONS.AT_EQUIPMENT, power.act, this.unitPolicy.canonical.power);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -291,8 +291,8 @@ class MachineGroup {
|
|
|
|
|
//add special cases
|
|
|
|
|
if( state === "operational" && ( mode == "virtualControl" || mode === "fysicalControl") ){
|
|
|
|
|
let flow = 0;
|
|
|
|
|
const measuredFlow = this._readChildMeasurement(machine, "flow", "measured", "downstream", this.unitPolicy.canonical.flow);
|
|
|
|
|
const predictedFlow = this._readChildMeasurement(machine, "flow", "predicted", "atequipment", this.unitPolicy.canonical.flow);
|
|
|
|
|
const measuredFlow = this._readChildMeasurement(machine, "flow", "measured", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.flow);
|
|
|
|
|
const predictedFlow = this._readChildMeasurement(machine, "flow", "predicted", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.flow);
|
|
|
|
|
if (Number.isFinite(measuredFlow) && measuredFlow !== 0) {
|
|
|
|
|
flow = measuredFlow;
|
|
|
|
|
}
|
|
|
|
|
@@ -647,10 +647,10 @@ class MachineGroup {
|
|
|
|
|
try{
|
|
|
|
|
//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
|
|
|
|
|
const pressures = Object.entries(this.machines).map(([machineId, machine]) => {
|
|
|
|
|
const pressures = Object.entries(this.machines).map(([_machineId, machine]) => {
|
|
|
|
|
return {
|
|
|
|
|
downstream: this._readChildMeasurement(machine, "pressure", "measured", "downstream", this.unitPolicy.canonical.pressure),
|
|
|
|
|
upstream: this._readChildMeasurement(machine, "pressure", "measured", "upstream", this.unitPolicy.canonical.pressure)
|
|
|
|
|
downstream: this._readChildMeasurement(machine, "pressure", "measured", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.pressure),
|
|
|
|
|
upstream: this._readChildMeasurement(machine, "pressure", "measured", POSITIONS.UPSTREAM, this.unitPolicy.canonical.pressure)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -660,12 +660,12 @@ class MachineGroup {
|
|
|
|
|
this.logger.debug(`Max downstream pressure: ${maxDownstream}, Min upstream pressure: ${minUpstream}`);
|
|
|
|
|
|
|
|
|
|
//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"){
|
|
|
|
|
|
|
|
|
|
//Equilize pressures over all machines so we can make a proper calculation
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", "downstream", maxDownstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", "upstream", minUpstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", POSITIONS.DOWNSTREAM, maxDownstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", POSITIONS.UPSTREAM, minUpstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
@@ -728,10 +728,10 @@ class MachineGroup {
|
|
|
|
|
this.logger.debug(`Moving to demand: ${Qd.toFixed(2)} -> Pumps: [${debugInfo}] => Total Power: ${bestResult.bestPower.toFixed(2)}`);
|
|
|
|
|
|
|
|
|
|
//store the total delivered power
|
|
|
|
|
this._writeMeasurement("power", "predicted", "atequipment", bestResult.bestPower, this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", "atequipment", bestResult.bestFlow, this.unitPolicy.canonical.flow);
|
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position("atequipment").value(bestResult.bestFlow / bestResult.bestPower);
|
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position("atequipment").value(bestResult.bestCog);
|
|
|
|
|
this._writeMeasurement("power", "predicted", POSITIONS.AT_EQUIPMENT, bestResult.bestPower, this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", POSITIONS.DOWNSTREAM, bestResult.bestFlow, this.unitPolicy.canonical.flow);
|
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestFlow / bestResult.bestPower);
|
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestCog);
|
|
|
|
|
|
|
|
|
|
await Promise.all(Object.entries(this.machines).map(async ([machineId, machine]) => {
|
|
|
|
|
// Find the flow for this machine in the best combination
|
|
|
|
|
@@ -767,10 +767,10 @@ class MachineGroup {
|
|
|
|
|
// Equalize pressure across all machines for machines that are not running. This is needed to ensure accurate flow and power predictions.
|
|
|
|
|
equalizePressure(){
|
|
|
|
|
// 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 {
|
|
|
|
|
downstream: this._readChildMeasurement(machine, "pressure", "measured", "downstream", this.unitPolicy.canonical.pressure),
|
|
|
|
|
upstream: this._readChildMeasurement(machine, "pressure", "measured", "upstream", this.unitPolicy.canonical.pressure)
|
|
|
|
|
downstream: this._readChildMeasurement(machine, "pressure", "measured", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.pressure),
|
|
|
|
|
upstream: this._readChildMeasurement(machine, "pressure", "measured", POSITIONS.UPSTREAM, this.unitPolicy.canonical.pressure)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -781,8 +781,8 @@ class MachineGroup {
|
|
|
|
|
// Set consistent pressures across machines
|
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
|
if(!this.isMachineActive(machineId)){
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", "downstream", maxDownstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", "upstream", minUpstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", POSITIONS.DOWNSTREAM, maxDownstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
this._writeChildMeasurement(machine, "pressure", "measured", POSITIONS.UPSTREAM, minUpstream, this.unitPolicy.canonical.pressure);
|
|
|
|
|
// Update the measured pressure value
|
|
|
|
|
const pressure = machine.getMeasuredPressure();
|
|
|
|
|
this.logger.debug(`Setting pressure for machine ${machineId} to ${pressure}`);
|
|
|
|
|
@@ -826,7 +826,7 @@ class MachineGroup {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterOutUnavailableMachines(list) {
|
|
|
|
|
const newList = list.filter(({ id, machine }) => {
|
|
|
|
|
const newList = list.filter(({ machine }) => {
|
|
|
|
|
const state = machine.state.getCurrentState();
|
|
|
|
|
const validActionForMode = machine.isValidActionForMode("execsequence", "auto");
|
|
|
|
|
|
|
|
|
|
@@ -841,7 +841,7 @@ class MachineGroup {
|
|
|
|
|
let lowestEfficiency = Infinity;
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
if(machine.cog < lowestEfficiency){
|
|
|
|
|
lowestEfficiency = machine.cog;
|
|
|
|
|
@@ -856,7 +856,7 @@ class MachineGroup {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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 {
|
|
|
|
|
|
|
|
|
|
// equalize pressure across all machines
|
|
|
|
|
@@ -911,7 +911,7 @@ class MachineGroup {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case (Qd > activeTotals.flow.max):
|
|
|
|
|
case (Qd > activeTotals.flow.max): {
|
|
|
|
|
// 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.
|
|
|
|
|
let i = 1;
|
|
|
|
|
@@ -931,9 +931,10 @@ class MachineGroup {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
default: {
|
|
|
|
|
// Default case: Demand is within the active range.
|
|
|
|
|
const countActiveMachines = machinesInPriorityOrder.filter(({ id }) => this.isMachineActive(id)).length;
|
|
|
|
|
|
|
|
|
|
@@ -947,6 +948,7 @@ class MachineGroup {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log information about flow distribution
|
|
|
|
|
@@ -958,10 +960,10 @@ class MachineGroup {
|
|
|
|
|
this.logger.debug(`Priority control for demand: ${totalFlow.toFixed(2)} -> Active pumps: [${debugInfo}] => Total Power: ${totalPower.toFixed(2)}`);
|
|
|
|
|
|
|
|
|
|
// Store measurements
|
|
|
|
|
this._writeMeasurement("power", "predicted", "atequipment", totalPower, this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", "atequipment", totalFlow, this.unitPolicy.canonical.flow);
|
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position("atequipment").value(totalFlow / totalPower);
|
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position("atequipment").value(totalCog);
|
|
|
|
|
this._writeMeasurement("power", "predicted", POSITIONS.AT_EQUIPMENT, totalPower, this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", POSITIONS.DOWNSTREAM, totalFlow, this.unitPolicy.canonical.flow);
|
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalFlow / totalPower);
|
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalCog);
|
|
|
|
|
|
|
|
|
|
this.logger.debug(`Flow distribution: ${JSON.stringify(flowDistribution)}`);
|
|
|
|
|
// Apply the flow distribution to machines
|
|
|
|
|
@@ -999,7 +1001,7 @@ class MachineGroup {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//capp input to 100
|
|
|
|
|
input > 100 ? input = 100 : input = input;
|
|
|
|
|
if (input > 100) { input = 100; }
|
|
|
|
|
|
|
|
|
|
const numOfMachines = Object.keys(this.machines).length;
|
|
|
|
|
const procentTotal = numOfMachines * input;
|
|
|
|
|
@@ -1013,7 +1015,7 @@ class MachineGroup {
|
|
|
|
|
if(machinesNeeded > machinesActive){
|
|
|
|
|
|
|
|
|
|
//start extra machine and put all active machines at min control
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 0});
|
|
|
|
|
}
|
|
|
|
|
@@ -1022,7 +1024,7 @@ class MachineGroup {
|
|
|
|
|
|
|
|
|
|
if(machinesNeeded < machinesActive){
|
|
|
|
|
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
|
|
|
|
if(this.isMachineActive(id)){
|
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 100});
|
|
|
|
|
@@ -1039,7 +1041,7 @@ class MachineGroup {
|
|
|
|
|
// distribute input equally among active machines (0 - 100%)
|
|
|
|
|
const ctrlPerMachine = procentTotal / machinesActive;
|
|
|
|
|
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }) => {
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id }) => {
|
|
|
|
|
if (this.isMachineActive(id)) {
|
|
|
|
|
// ensure ctrl is capped between 0 and 100%
|
|
|
|
|
const ctrlValue = Math.max(0, Math.min(ctrlPerMachine, 100));
|
|
|
|
|
@@ -1071,10 +1073,10 @@ class MachineGroup {
|
|
|
|
|
const totalFlow = [];
|
|
|
|
|
|
|
|
|
|
// fetch and store measurements
|
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
|
Object.entries(this.machines).forEach(([_machineId, machine]) => {
|
|
|
|
|
|
|
|
|
|
const powerValue = this._readChildMeasurement(machine, "power", "predicted", "atequipment", this.unitPolicy.canonical.power);
|
|
|
|
|
const flowValue = this._readChildMeasurement(machine, "flow", "predicted", "atequipment", this.unitPolicy.canonical.flow);
|
|
|
|
|
const powerValue = this._readChildMeasurement(machine, "power", "predicted", POSITIONS.AT_EQUIPMENT, this.unitPolicy.canonical.power);
|
|
|
|
|
const flowValue = this._readChildMeasurement(machine, "flow", "predicted", POSITIONS.DOWNSTREAM, this.unitPolicy.canonical.flow);
|
|
|
|
|
|
|
|
|
|
if (powerValue !== null) {
|
|
|
|
|
totalPower.push(powerValue);
|
|
|
|
|
@@ -1084,11 +1086,11 @@ class MachineGroup {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this._writeMeasurement("power", "predicted", "atequipment", totalPower.reduce((a, b) => a + b, 0), this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", "atequipment", totalFlow.reduce((a, b) => a + b, 0), this.unitPolicy.canonical.flow);
|
|
|
|
|
this._writeMeasurement("power", "predicted", POSITIONS.AT_EQUIPMENT, totalPower.reduce((a, b) => a + b, 0), this.unitPolicy.canonical.power);
|
|
|
|
|
this._writeMeasurement("flow", "predicted", POSITIONS.DOWNSTREAM, totalFlow.reduce((a, b) => a + b, 0), this.unitPolicy.canonical.flow);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1124,12 +1126,12 @@ class MachineGroup {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (demandQ < absoluteTotals.flow.min) {
|
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${absoluteTotals.flow.min}. Capping to minimum flow.`);
|
|
|
|
|
if (demandQ < this.absoluteTotals.flow.min) {
|
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${this.absoluteTotals.flow.min}. Capping to minimum flow.`);
|
|
|
|
|
demandQout = this.absoluteTotals.flow.min;
|
|
|
|
|
} else if (demandQout > absoluteTotals.flow.max) {
|
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${absoluteTotals.flow.max}. Capping to maximum flow.`);
|
|
|
|
|
demandQout = absoluteTotals.flow.max;
|
|
|
|
|
} else if (demandQout > this.absoluteTotals.flow.max) {
|
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${this.absoluteTotals.flow.max}. Capping to maximum flow.`);
|
|
|
|
|
demandQout = this.absoluteTotals.flow.max;
|
|
|
|
|
}else if(demandQout <= 0){
|
|
|
|
|
this.logger.debug(`Turning machines off`);
|
|
|
|
|
demandQout = 0;
|
|
|
|
|
@@ -1185,7 +1187,7 @@ class MachineGroup {
|
|
|
|
|
|
|
|
|
|
//recalc distance from BEP
|
|
|
|
|
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.AT_EQUIPMENT).getCurrentValue();
|
|
|
|
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1306,32 +1308,32 @@ class MachineGroup {
|
|
|
|
|
const output = {};
|
|
|
|
|
|
|
|
|
|
//build the output object
|
|
|
|
|
Object.entries(this.measurements.measurements || {}).forEach(([type, variants]) => {
|
|
|
|
|
Object.keys(variants || {}).forEach((variant) => {
|
|
|
|
|
const unit = this._outputUnitForType(type);
|
|
|
|
|
const downstreamVal = this._readMeasurement(type, variant, "downstream", unit);
|
|
|
|
|
const atEquipmentVal = this._readMeasurement(type, variant, "atequipment", unit);
|
|
|
|
|
const upstreamVal = this._readMeasurement(type, variant, "upstream", unit);
|
|
|
|
|
this.measurements.getTypes().forEach(type => {
|
|
|
|
|
this.measurements.getVariants(type).forEach(variant => {
|
|
|
|
|
const unit = this._outputUnitForType(type);
|
|
|
|
|
const downstreamVal = this._readMeasurement(type, variant, POSITIONS.DOWNSTREAM, unit);
|
|
|
|
|
const atEquipmentVal = this._readMeasurement(type, variant, POSITIONS.AT_EQUIPMENT, unit);
|
|
|
|
|
const upstreamVal = this._readMeasurement(type, variant, POSITIONS.UPSTREAM, unit);
|
|
|
|
|
|
|
|
|
|
if (downstreamVal != null) {
|
|
|
|
|
output[`downstream_${variant}_${type}`] = downstreamVal;
|
|
|
|
|
}
|
|
|
|
|
if (upstreamVal != null) {
|
|
|
|
|
output[`upstream_${variant}_${type}`] = upstreamVal;
|
|
|
|
|
}
|
|
|
|
|
if (atEquipmentVal != null) {
|
|
|
|
|
output[`atequipment${variant}_${type}`] = atEquipmentVal;
|
|
|
|
|
}
|
|
|
|
|
if (downstreamVal != null && upstreamVal != null) {
|
|
|
|
|
const diff = this.measurements
|
|
|
|
|
.type(type)
|
|
|
|
|
.variant(variant)
|
|
|
|
|
.difference({ from: 'downstream', to: 'upstream', unit });
|
|
|
|
|
if (diff?.value != null) {
|
|
|
|
|
output[`differential_${variant}_${type}`] = diff.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (downstreamVal != null) {
|
|
|
|
|
output[`downstream_${variant}_${type}`] = downstreamVal;
|
|
|
|
|
}
|
|
|
|
|
if (upstreamVal != null) {
|
|
|
|
|
output[`upstream_${variant}_${type}`] = upstreamVal;
|
|
|
|
|
}
|
|
|
|
|
if (atEquipmentVal != null) {
|
|
|
|
|
output[`atEquipment_${variant}_${type}`] = atEquipmentVal;
|
|
|
|
|
}
|
|
|
|
|
if (downstreamVal != null && upstreamVal != null) {
|
|
|
|
|
const diff = this.measurements
|
|
|
|
|
.type(type)
|
|
|
|
|
.variant(variant)
|
|
|
|
|
.difference({ from: POSITIONS.DOWNSTREAM, to: POSITIONS.UPSTREAM, unit });
|
|
|
|
|
if (diff?.value != null) {
|
|
|
|
|
output[`differential_${variant}_${type}`] = diff.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//fill in the rest of the output object
|
|
|
|
|
|