B3.3 follow-up: drop _unitView mirror; use UnitPolicy property bags directly
Same as MGC — UnitPolicy property bags replace the manual _unitView/ unitPolicyView reassignment. specificClass.js 400→377. 196/196 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,9 +56,6 @@ class Machine extends BaseDomain {
|
||||
this.config = this.configUtils.updateConfig(this.config, {
|
||||
general: { name: `${this.config.functionality?.softwareType}_${this.config.general.id}` },
|
||||
});
|
||||
this.unitPolicyView = this._freezeUnitView(this.unitPolicy);
|
||||
this._unitPolicyInstance = this.unitPolicy;
|
||||
this.unitPolicy = this.unitPolicyView;
|
||||
|
||||
this._setupCurves();
|
||||
this.groupPredictFlow = null; this.groupPredictPower = null; this.groupPredictCtrl = null; this.groupNCog = 0;
|
||||
@@ -68,33 +65,13 @@ class Machine extends BaseDomain {
|
||||
this._setupChildren();
|
||||
}
|
||||
|
||||
_freezeUnitView(p) {
|
||||
const slot = (m, k) => (typeof p[m] === 'function' ? p[m](k) : p[m]?.[k]);
|
||||
return Object.freeze({
|
||||
canonical: Object.freeze({
|
||||
pressure: slot('canonical', 'pressure'), atmPressure: slot('canonical', 'atmPressure') || 'Pa',
|
||||
flow: slot('canonical', 'flow'), power: slot('canonical', 'power'),
|
||||
temperature: slot('canonical', 'temperature'),
|
||||
}),
|
||||
output: Object.freeze({
|
||||
pressure: slot('output', 'pressure'), flow: slot('output', 'flow'),
|
||||
power: slot('output', 'power'), temperature: slot('output', 'temperature'),
|
||||
atmPressure: slot('output', 'atmPressure') || 'Pa',
|
||||
}),
|
||||
curve: Object.freeze({
|
||||
pressure: slot('curve', 'pressure'), flow: slot('curve', 'flow'),
|
||||
power: slot('curve', 'power'), control: slot('curve', 'control'),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
_setupCurves() {
|
||||
this.model = this.config.asset?.model;
|
||||
const { rawCurve, error } = loadModelCurve(this.model);
|
||||
this.rawCurve = rawCurve;
|
||||
if (error) { this.logger.error(`${error} in machineConfig. Cannot make predictions.`); this._installNullPredictors(); return; }
|
||||
try {
|
||||
this.curve = normalizeMachineCurve(rawCurve, this.unitPolicyView, this.logger);
|
||||
this.curve = normalizeMachineCurve(rawCurve, this.unitPolicy, this.logger);
|
||||
this.config = this.configUtils.updateConfig(this.config, { asset: { ...this.config.asset, machineCurve: this.curve } });
|
||||
const built = buildPredictors(this.config.asset.machineCurve);
|
||||
this.predictors = built;
|
||||
@@ -150,7 +127,7 @@ class Machine extends BaseDomain {
|
||||
this.virtualPressureChildIds = { upstream: 'dashboard-sim-upstream', downstream: 'dashboard-sim-downstream' };
|
||||
this.realPressureChildIds = { upstream: new Set(), downstream: new Set() };
|
||||
this.virtualPressureChildren = new VirtualPressureChildren({
|
||||
logger: this.logger, unitPolicy: this.unitPolicyView, parentRef: this,
|
||||
logger: this.logger, unitPolicy: this.unitPolicy, parentRef: this,
|
||||
ids: this.virtualPressureChildIds,
|
||||
}).build();
|
||||
this.pressureInit = new PressureInitialization({
|
||||
@@ -184,10 +161,10 @@ class Machine extends BaseDomain {
|
||||
}
|
||||
|
||||
_init() {
|
||||
const tu = this.unitPolicyView.output.temperature;
|
||||
const tu = this.unitPolicy.output.temperature;
|
||||
this.measurements.type('temperature').variant('measured').position('atEquipment').value(15, Date.now(), tu);
|
||||
this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325, Date.now(), 'Pa');
|
||||
const fu = this.unitPolicyView.canonical.flow;
|
||||
const fu = this.unitPolicy.canonical.flow;
|
||||
const fmin = this.predictFlow ? this.predictFlow.currentFxyYMin : 0;
|
||||
const fmax = this.predictFlow ? this.predictFlow.currentFxyYMax : 0;
|
||||
this.measurements.type('flow').variant('predicted').position('max').value(fmax, Date.now(), fu);
|
||||
@@ -259,8 +236,8 @@ class Machine extends BaseDomain {
|
||||
// ── state-machine driven recompute ─────────────────────────────────
|
||||
_updateState() {
|
||||
if (!this._isOperationalState()) {
|
||||
const fu = this.unitPolicyView.canonical.flow;
|
||||
const pu = this.unitPolicyView.canonical.power;
|
||||
const fu = this.unitPolicy.canonical.flow;
|
||||
const pu = this.unitPolicy.canonical.power;
|
||||
this.measurements.type('flow').variant('predicted').position('downstream').value(0, Date.now(), fu);
|
||||
this.measurements.type('flow').variant('predicted').position('atEquipment').value(0, Date.now(), fu);
|
||||
this.measurements.type('power').variant('predicted').position('atEquipment').value(0, Date.now(), pu);
|
||||
@@ -366,9 +343,9 @@ class Machine extends BaseDomain {
|
||||
|
||||
updateCurve(newCurve) {
|
||||
this.logger.info('Updating machine curve');
|
||||
const normalized = normalizeMachineCurve(newCurve, this.unitPolicyView, this.logger);
|
||||
const normalized = normalizeMachineCurve(newCurve, this.unitPolicy, this.logger);
|
||||
this.config = this.configUtils.updateConfig(this.config, {
|
||||
asset: { machineCurve: normalized, curveUnits: this.unitPolicyView.curve },
|
||||
asset: { machineCurve: normalized, curveUnits: this.unitPolicy.curve },
|
||||
});
|
||||
if (!this.predictFlow || !this.predictPower || !this.predictCtrl) {
|
||||
const built = buildPredictors(this.config.asset.machineCurve);
|
||||
|
||||
Reference in New Issue
Block a user