Compare commits

..

1 Commits

Author SHA1 Message Date
znetsixe
a55c6bdbea fixed pressure updates from machines. Everything seems to be working again. 2025-09-23 15:50:40 +02:00
2 changed files with 50 additions and 19 deletions

View File

@@ -270,9 +270,6 @@ async function testNormalizedScaling(mg, pt1) {
console.log("\n🧪 testing normalized scaling (0-100%)..."); console.log("\n🧪 testing normalized scaling (0-100%)...");
mg.setScaling("normalized"); mg.setScaling("normalized");
//first set pressure:
pt1.inputValue = 1400;
//fetch ranges //fetch ranges
const maxflow = mg.dynamicTotals.flow.max; const maxflow = mg.dynamicTotals.flow.max;
console.log(`max group flow capacity: ${maxflow.toFixed(2)} m3/h`); console.log(`max group flow capacity: ${maxflow.toFixed(2)} m3/h`);
@@ -280,6 +277,14 @@ async function testNormalizedScaling(mg, pt1) {
console.log(`min group flow capacity: ${minFlow.toFixed(2)} m3/h`); console.log(`min group flow capacity: ${minFlow.toFixed(2)} m3/h`);
const testPoints = [0, 10, 25, 50, 75, 90, 100]; const testPoints = [0, 10, 25, 50, 75, 90, 100];
const testPressurePoints = [800, 1200, 1600, 2000];
for (const pressure of testPressurePoints) {
try {
console.log(`\n--- testing at ${pressure} mbar ---`);
pt1.calculateInput(pressure);
logMachineStates(mg, `${pressure} mbar, before demand tests`);
for (const demand of testPoints) { for (const demand of testPoints) {
try { try {
@@ -289,10 +294,29 @@ async function testNormalizedScaling(mg, pt1) {
logMachineStates(mg, `normalized ${demand}%`); logMachineStates(mg, `normalized ${demand}%`);
//check if total flow is within expected range
const totalFlow = mg.measurements?.type("flow")?.variant("predicted")?.position("downstream")?.getCurrentValue() || 0;
const expectedFlow = minFlow + (demand / 100) * (maxflow - minFlow);
const percentTolerance = 0.1 ; // % tolerance of expected flow
const tolerance = (expectedFlow * percentTolerance) / 100;
if (totalFlow < expectedFlow - tolerance || totalFlow > expectedFlow + tolerance) {
console.warn(`⚠️ Total flow (${totalFlow.toFixed(2)} m3/h) is outside expected range (${(expectedFlow - tolerance).toFixed(2)} - ${(expectedFlow + tolerance).toFixed(2)} m3/h)`);
}
else {
console.log( `Difference between expected and actual flow: ${(totalFlow - expectedFlow).toFixed(2)} m3/h`);
console.log(`✅ Total flow (${totalFlow.toFixed(2)} m3/h) is within expected range (${(expectedFlow - tolerance).toFixed(2)} - ${(expectedFlow + tolerance).toFixed(2)} m3/h)`);
}
} catch (err) { } catch (err) {
console.error(`❌ error at ${demand}%:`, err.message); console.error(`❌ error at ${demand}%:`, err.message);
} }
} }
} catch (err) {
console.error(`❌ error setting pressure to ${pressure}:`, err.message);
}
}
} }
async function testAbsoluteScaling(mg, pt1) { async function testAbsoluteScaling(mg, pt1) {

View File

@@ -63,17 +63,21 @@ class MachineGroup {
if(softwareType == "machine"){ if(softwareType == "machine"){
// Check if the machine is already registered // Check if the machine is already registered
this.machines[child.config.general.id] === undefined ? this.machines[child.config.general.id] = child : this.logger.warn(`Machine ${child.config.general.id} is already registered.`); this.machines[child.config.general.id] === undefined ? this.machines[child.config.general.id] = child : this.logger.warn(`Machine ${child.config.general.id} is already registered.`);
//listen for machine pressure changes
this.logger.debug(`Listening for pressure changes from machine ${child.config.general.id}`);
child.measurements.emitter.on("pressure.measured.differential", (eventData) => {
this.logger.debug(`Pressure update from ${child.config.general.id}: ${eventData.value} ${eventData.unit}`);
this.handleChildChange(); this.handleChildChange();
/* });
// Listen for changes in the child machine
child.emitter.on('stateChange', () => this.handleChildChange());
child.emitter.on('pressureChange', () => this.handlePressureChange());
child.emitter.on('ncogChange', () => this.handleChildChange());
*/
} }
} }
calcAbsoluteTotals() { calcAbsoluteTotals() {
const absoluteTotals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } }; const absoluteTotals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
@@ -112,7 +116,10 @@ class MachineGroup {
const dynamicTotals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 }, NCog : 0 }; const dynamicTotals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 }, NCog : 0 };
this.logger.debug(`\n --------- Calculating dynamic totals for ${Object.keys(this.machines).length} machines. @ current pressure settings : ----------`);
Object.values(this.machines).forEach(machine => { Object.values(this.machines).forEach(machine => {
this.logger.debug(`Processing machine with id: ${machine.config.general.id}`);
this.logger.debug(`Current pressure settings: ${JSON.stringify(machine.predictFlow.currentF)}`);
//fetch min flow ever seen over all machines //fetch min flow ever seen over all machines
const minFlow = machine.predictFlow.currentFxyYMin; const minFlow = machine.predictFlow.currentFxyYMin;
const maxFlow = machine.predictFlow.currentFxyYMax; const maxFlow = machine.predictFlow.currentFxyYMax;