Two governance items from the 2026-05-14 quality review:
- test/_output-manifest.md enumerates every Port 0/1/2 key MGC emits, its
source, type, range, and which tests cover it in populated/degraded states
(per .claude/rules/output-coverage.md).
- src/control/strategies.js extracts computeEqualFlowDistribution as a pure
function so the equal-flow algorithm is testable without an MGC fixture.
test/basic/equalFlowDistribution.basic.test.js (6 tests) covers all three
demand branches and pins the legacy quirk where the default branch counts
active machines but iterates priority-ordered first-N (documented in the
test so the future cleanup is a deliberate change).
Plus rolled-up session work that landed alongside:
- set.demand is now unit-self-describing ({value, unit:'m3/h'|'l/s'|'%'|...}
or bare number = %); setScaling/scaling.current removed from MGC, commands,
editor (mgc.html), specificClass.
- _optimalControl + equalFlowControl now compute eta = (Q*dP)/P_shaft rather
than Q/P, keeping the metric in the same scale as each child's cog.
- groupEfficiency.calcRelativeDistanceFromPeak returns undefined (was 1) when
pumps are homogeneous (|max-min| < 1e-9). Dashboard treats undefined as
'-' instead of showing a misleading 100% / 0% reading.
- examples/02-Dashboard.json: auto-init inject so the dashboard populates at
deploy, NCog formatter normalizes the SUM emitted by MGC by
machineCountActive, Q-H fanout trims the flat-Q tail so the H axis isn't
stretched to 40m by curve-envelope clamp points, num/pct treat null AND
undefined as no-data (closes the +null === 0 trap).
- new test/integration/dashboard-fanout.integration.test.js (17 tests),
bep-distance-demand-sweep.integration.test.js (3 tests),
group-bep-cascade.integration.test.js -- total suite now 108/108 green.
- .gitignore: wiki/test.gif (143 MB screen recording, kept locally only).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
3.7 KiB
JavaScript
91 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const { interpolation } = require('generalFunctions');
|
|
const GroupEfficiency = require('../../src/efficiency/groupEfficiency.js');
|
|
|
|
function makeMachines(cogs) {
|
|
const out = {};
|
|
cogs.forEach((cog, i) => { out[`m${i}`] = { cog }; });
|
|
return out;
|
|
}
|
|
|
|
function makeGE(extra = {}) {
|
|
return new GroupEfficiency({
|
|
interpolation: new interpolation(),
|
|
logger: { warn() {}, error() {}, debug() {}, info() {} },
|
|
...extra,
|
|
});
|
|
}
|
|
|
|
test('calcGroupEfficiency aggregates across 3 machines', () => {
|
|
const ge = makeGE();
|
|
const machines = makeMachines([0.9, 0.8, 0.7]);
|
|
const { maxEfficiency, lowestEfficiency } = ge.calcGroupEfficiency(machines);
|
|
assert.equal(lowestEfficiency, 0.7);
|
|
// maxEfficiency in the original code is actually the MEAN cog.
|
|
assert.ok(Math.abs(maxEfficiency - 0.8) < 1e-12);
|
|
});
|
|
|
|
test('calcDistanceFromPeak returns |a - b|', () => {
|
|
const ge = makeGE();
|
|
assert.ok(Math.abs(ge.calcDistanceFromPeak(0.85, 0.92) - 0.07) < 1e-12);
|
|
assert.ok(Math.abs(ge.calcDistanceFromPeak(0.92, 0.85) - 0.07) < 1e-12);
|
|
});
|
|
|
|
test('calcRelativeDistanceFromPeak maps current onto [0..1]', () => {
|
|
const ge = makeGE();
|
|
// current=0.85, max=0.92, min=0.7 → maps 0.85 in [0.92..0.7] onto [0..1].
|
|
// interpolate_lin_single_point treats first range as input domain:
|
|
// 0.85 → ((0.85 - 0.92) / (0.7 - 0.92)) * (1 - 0) + 0 = 0.07/0.22 ≈ 0.3181818...
|
|
const v = ge.calcRelativeDistanceFromPeak(0.85, 0.92, 0.7);
|
|
const expected = (0.85 - 0.92) / (0.7 - 0.92);
|
|
assert.ok(Math.abs(v - expected) < 1e-9, `got ${v} expected ${expected}`);
|
|
});
|
|
|
|
test('calcDistanceBEP returns both abs + rel', () => {
|
|
const ge = makeGE();
|
|
const { absDistFromPeak, relDistFromPeak } = ge.calcDistanceBEP(0.85, 0.92, 0.7);
|
|
assert.ok(Math.abs(absDistFromPeak - 0.07) < 1e-12);
|
|
const expectedRel = (0.85 - 0.92) / (0.7 - 0.92);
|
|
assert.ok(Math.abs(relDistFromPeak - expectedRel) < 1e-9);
|
|
});
|
|
|
|
test('calcRelativeDistanceFromPeak returns undefined when max === min (degenerate)', () => {
|
|
// For homogeneous pump groups (all cogs equal), the [max..min] band
|
|
// collapses and the metric is mathematically undefined. Return undefined
|
|
// so the dashboard displays "—" instead of a misleading 0% / 100%.
|
|
const ge = makeGE();
|
|
assert.equal(ge.calcRelativeDistanceFromPeak(0.85, 0.8, 0.8), undefined);
|
|
});
|
|
|
|
test('calcRelativeDistanceFromPeak returns undefined when max ≈ min within epsilon', () => {
|
|
// Float noise from identical pumps: max-min might be 1e-12 rather than 0.
|
|
// Must still report undefined — the interpolation extrapolates wildly here.
|
|
const ge = makeGE();
|
|
assert.equal(ge.calcRelativeDistanceFromPeak(0.85, 0.211264, 0.211263999), undefined);
|
|
});
|
|
|
|
test('calcRelativeDistanceFromPeak returns undefined when current is null', () => {
|
|
const ge = makeGE();
|
|
assert.equal(ge.calcRelativeDistanceFromPeak(null, 0.92, 0.7), undefined);
|
|
});
|
|
|
|
test('calcDistanceBEP propagates undefined relDist for degenerate input', () => {
|
|
// Regression: if currentEff is finite, absDist is still computed (it's
|
|
// just |current - peak|), but relDist must be undefined for degenerate.
|
|
const ge = makeGE();
|
|
const { absDistFromPeak, relDistFromPeak } = ge.calcDistanceBEP(0.206, 0.211, 0.211);
|
|
assert.ok(Math.abs(absDistFromPeak - 0.005) < 1e-9);
|
|
assert.equal(relDistFromPeak, undefined);
|
|
});
|
|
|
|
test('calcGroupEfficiency handles a single machine', () => {
|
|
const ge = makeGE();
|
|
const { maxEfficiency, lowestEfficiency } = ge.calcGroupEfficiency(makeMachines([0.77]));
|
|
assert.equal(maxEfficiency, 0.77);
|
|
assert.equal(lowestEfficiency, 0.77);
|
|
});
|