fixed pressure updates from machines. Everything seems to be working again.

This commit is contained in:
znetsixe
2025-09-23 15:50:40 +02:00
parent ac9d1b4fdd
commit a55c6bdbea
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%)...");
mg.setScaling("normalized");
//first set pressure:
pt1.inputValue = 1400;
//fetch ranges
const maxflow = mg.dynamicTotals.flow.max;
console.log(`max group flow capacity: ${maxflow.toFixed(2)} m3/h`);
@@ -280,20 +277,47 @@ async function testNormalizedScaling(mg, pt1) {
console.log(`min group flow capacity: ${minFlow.toFixed(2)} m3/h`);
const testPoints = [0, 10, 25, 50, 75, 90, 100];
const testPressurePoints = [800, 1200, 1600, 2000];
for (const demand of testPoints) {
for (const pressure of testPressurePoints) {
try {
console.log(`\n--- normalized demand: ${demand}% ---`);
await mg.handleInput("parent", demand);
logMachineStates(mg, `normalized ${demand}%`);
} catch (err) {
console.error(`❌ error at ${demand}%:`, err.message);
console.log(`\n--- testing at ${pressure} mbar ---`);
pt1.calculateInput(pressure);
logMachineStates(mg, `${pressure} mbar, before demand tests`);
for (const demand of testPoints) {
try {
console.log(`\n--- normalized demand: ${demand}% ---`);
await mg.handleInput("parent", 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) {
console.error(`❌ error at ${demand}%:`, err.message);
}
}
} catch (err) {
console.error(`❌ error setting pressure to ${pressure}:`, err.message);
}
}
}
async function testAbsoluteScaling(mg, pt1) {
console.log("\n🧪 testing absolute scaling...");