B3.3 follow-up: drop _unitView mirror; use UnitPolicy property bags directly
UnitPolicy now exposes canonical/output/curve as both methods AND frozen property bags, so this.unitPolicy = this.constructor.unitPolicy works directly. Removes the 14-line _unitView assembly in configure(). specificClass.js 336→318. 77/77 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,24 +36,6 @@ class MachineGroup extends BaseDomain {
|
||||
// tests still write directly (matches the pumpingStation pattern).
|
||||
this.machines = {};
|
||||
|
||||
// groupOps/totals/optimizer modules expect the legacy object-style
|
||||
// policy (ctx.unitPolicy.canonical.flow). UnitPolicy on BaseDomain
|
||||
// exposes canonical()/output() methods, so build a compatible view.
|
||||
this._unitView = Object.freeze({
|
||||
canonical: Object.freeze({
|
||||
flow: this.unitPolicy.canonical('flow'),
|
||||
pressure: this.unitPolicy.canonical('pressure'),
|
||||
power: this.unitPolicy.canonical('power'),
|
||||
temperature: this.unitPolicy.canonical('temperature'),
|
||||
}),
|
||||
output: Object.freeze({
|
||||
flow: this.unitPolicy.output('flow'),
|
||||
pressure: this.unitPolicy.output('pressure'),
|
||||
power: this.unitPolicy.output('power'),
|
||||
temperature: this.unitPolicy.output('temperature'),
|
||||
}),
|
||||
});
|
||||
|
||||
this.scaling = this.config.scaling.current;
|
||||
this.mode = this.config.mode.current;
|
||||
this.absDistFromPeak = 0;
|
||||
@@ -71,12 +53,12 @@ class MachineGroup extends BaseDomain {
|
||||
this.operatingPoint = new GroupOperatingPoint({
|
||||
measurements: this.measurements,
|
||||
machines: this.machines,
|
||||
unitPolicy: this._unitView,
|
||||
unitPolicy: this.unitPolicy,
|
||||
logger: this.logger,
|
||||
});
|
||||
this.totals = new TotalsCalculator({
|
||||
machines: this.machines,
|
||||
unitPolicy: this._unitView,
|
||||
unitPolicy: this.unitPolicy,
|
||||
logger: this.logger,
|
||||
operatingPoint: this.operatingPoint,
|
||||
isMachineActive: (id) => this.isMachineActive(id),
|
||||
@@ -165,8 +147,8 @@ class MachineGroup extends BaseDomain {
|
||||
handlePressureChange() {
|
||||
this.operatingPoint.equalize();
|
||||
const totals = this.calcDynamicTotals();
|
||||
const fUnit = this._unitView.canonical.flow;
|
||||
const pUnit = this._unitView.canonical.power;
|
||||
const fUnit = this.unitPolicy.canonical.flow;
|
||||
const pUnit = this.unitPolicy.canonical.power;
|
||||
this.operatingPoint.writeOwn('flow', 'predicted', POSITIONS.AT_EQUIPMENT, totals.flow.act, fUnit);
|
||||
// Mirror live aggregate onto DOWNSTREAM — PS subscribes here for the
|
||||
// outflow signal. See preserve-tests/ps-mgc-flow-contract regression.
|
||||
@@ -227,8 +209,8 @@ class MachineGroup extends BaseDomain {
|
||||
}
|
||||
|
||||
// INTENT lands on AT_EQUIPMENT only; DOWNSTREAM is the live aggregate.
|
||||
this.operatingPoint.writeOwn('power', 'predicted', POSITIONS.AT_EQUIPMENT, bestResult.bestPower, this._unitView.canonical.power);
|
||||
this.operatingPoint.writeOwn('flow', 'predicted', POSITIONS.AT_EQUIPMENT, bestResult.bestFlow, this._unitView.canonical.flow);
|
||||
this.operatingPoint.writeOwn('power', 'predicted', POSITIONS.AT_EQUIPMENT, bestResult.bestPower, this.unitPolicy.canonical.power);
|
||||
this.operatingPoint.writeOwn('flow', 'predicted', POSITIONS.AT_EQUIPMENT, 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);
|
||||
|
||||
@@ -314,8 +296,8 @@ class MachineGroup extends BaseDomain {
|
||||
finally { this._shutdownInFlight.delete(id); }
|
||||
}
|
||||
}));
|
||||
const fUnit = this._unitView.canonical.flow;
|
||||
const pUnit = this._unitView.canonical.power;
|
||||
const fUnit = this.unitPolicy.canonical.flow;
|
||||
const pUnit = this.unitPolicy.canonical.power;
|
||||
this.operatingPoint.writeOwn('flow', 'predicted', POSITIONS.DOWNSTREAM, 0, fUnit);
|
||||
this.operatingPoint.writeOwn('flow', 'predicted', POSITIONS.AT_EQUIPMENT, 0, fUnit);
|
||||
this.operatingPoint.writeOwn('power', 'predicted', POSITIONS.AT_EQUIPMENT, 0, pUnit);
|
||||
@@ -323,8 +305,8 @@ class MachineGroup extends BaseDomain {
|
||||
}
|
||||
|
||||
_canonicalToOutputFlow(value) {
|
||||
const from = this._unitView.canonical.flow;
|
||||
const to = this._unitView.output.flow;
|
||||
const from = this.unitPolicy.canonical.flow;
|
||||
const to = this.unitPolicy.output.flow;
|
||||
if (!from || !to || from === to) return value;
|
||||
return convert(value).from(from).to(to);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user