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>
53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
/**
|
|
* Resolves the working pressure for prediction and pushes it onto
|
|
* predictFlow/predictPower/predictCtrl.fDimension. After every push the
|
|
* CoG, efficiency, and distance-from-BEP are recomputed so downstream
|
|
* state stays consistent — exactly what the pre-refactor
|
|
* getMeasuredPressure() did.
|
|
*/
|
|
|
|
const eff = require('../prediction/efficiencyMath');
|
|
|
|
function getMeasuredPressure(host) {
|
|
if (!host.hasCurve || !host.predictFlow || !host.predictPower || !host.predictCtrl) {
|
|
host.logger.error('No valid curve available to calculate prediction using last known pressure');
|
|
return 0;
|
|
}
|
|
const up = host._getPreferredPressureValue('upstream');
|
|
const dn = host._getPreferredPressureValue('downstream');
|
|
|
|
const applyDiff = (diff) => {
|
|
host.predictFlow.fDimension = diff;
|
|
host.predictPower.fDimension = diff;
|
|
host.predictCtrl.fDimension = diff;
|
|
const { cog, minEfficiency } = eff.calcCog(host);
|
|
const efficiency = eff.calcEfficiency(host, host.predictPower.outputY, host.predictFlow.outputY, 'predicted');
|
|
eff.calcDistanceBEP(host, efficiency, cog, minEfficiency);
|
|
};
|
|
|
|
if (up != null && dn != null) {
|
|
const diff = dn - up;
|
|
host.logger.debug(`Pressure differential: ${diff}`);
|
|
applyDiff(diff);
|
|
return diff;
|
|
}
|
|
if (dn != null) {
|
|
host.logger.warn(`Using downstream pressure only for prediction: ${dn}. Prediction accuracy is degraded; inject upstream pressure too.`);
|
|
applyDiff(dn);
|
|
return dn;
|
|
}
|
|
if (up != null) {
|
|
host.logger.warn(`Using upstream pressure only for prediction: ${up}. Prediction accuracy is degraded; inject downstream pressure too.`);
|
|
applyDiff(up);
|
|
return up;
|
|
}
|
|
host.logger.error('No valid pressure measurements available to calculate prediction using last known pressure');
|
|
applyDiff(0);
|
|
const fu = host.unitPolicy.canonical.flow;
|
|
host.measurements.type('flow').variant('predicted').position('max').value(host.predictFlow.currentFxyYMax, Date.now(), fu);
|
|
host.measurements.type('flow').variant('predicted').position('min').value(host.predictFlow.currentFxyYMin, Date.now(), fu);
|
|
return 0;
|
|
}
|
|
|
|
module.exports = { getMeasuredPressure };
|