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>
72 lines
3.0 KiB
JavaScript
72 lines
3.0 KiB
JavaScript
/**
|
|
* Curve-driven prediction math kept as host-aware helpers so the
|
|
* specificClass orchestrator stays slim. Every helper mirrors a method
|
|
* from the pre-refactor Machine class one-to-one — behaviour is
|
|
* preserved verbatim including the "no curve → log + 0" fallback shape
|
|
* and the operational-state guard.
|
|
*/
|
|
|
|
function calcFlow(host, x) {
|
|
const u = host.unitPolicy.canonical.flow;
|
|
if (host.hasCurve) {
|
|
if (!host._isOperationalState()) {
|
|
host.measurements.type('flow').variant('predicted').position('downstream').value(0, Date.now(), u);
|
|
host.measurements.type('flow').variant('predicted').position('atEquipment').value(0, Date.now(), u);
|
|
host.logger.debug('Machine is not operational. Setting predicted flow to 0.');
|
|
return 0;
|
|
}
|
|
const cFlow = Math.max(0, host.predictFlow.y(x));
|
|
host.measurements.type('flow').variant('predicted').position('downstream').value(cFlow, Date.now(), u);
|
|
host.measurements.type('flow').variant('predicted').position('atEquipment').value(cFlow, Date.now(), u);
|
|
return cFlow;
|
|
}
|
|
host.logger.warn('No curve data available for flow calculation. Returning 0.');
|
|
host.measurements.type('flow').variant('predicted').position('downstream').value(0, Date.now(), u);
|
|
host.measurements.type('flow').variant('predicted').position('atEquipment').value(0, Date.now(), u);
|
|
return 0;
|
|
}
|
|
|
|
function calcPower(host, x) {
|
|
const u = host.unitPolicy.canonical.power;
|
|
if (host.hasCurve) {
|
|
if (!host._isOperationalState()) {
|
|
host.measurements.type('power').variant('predicted').position('atEquipment').value(0, Date.now(), u);
|
|
host.logger.debug('Machine is not operational. Setting predicted power to 0.');
|
|
return 0;
|
|
}
|
|
const cPower = Math.max(0, host.predictPower.y(x));
|
|
host.measurements.type('power').variant('predicted').position('atEquipment').value(cPower, Date.now(), u);
|
|
return cPower;
|
|
}
|
|
host.logger.warn('No curve data available for power calculation. Returning 0.');
|
|
host.measurements.type('power').variant('predicted').position('atEquipment').value(0, Date.now(), u);
|
|
return 0;
|
|
}
|
|
|
|
function inputFlowCalcPower(host, flow) {
|
|
if (host.hasCurve) {
|
|
host.predictCtrl.currentX = flow;
|
|
const cCtrl = host.predictCtrl.y(flow);
|
|
host.predictPower.currentX = cCtrl;
|
|
return host.predictPower.y(cCtrl);
|
|
}
|
|
host.logger.warn('No curve data available for power calculation. Returning 0.');
|
|
host.measurements.type('power').variant('predicted').position('atEquipment')
|
|
.value(0, Date.now(), host.unitPolicy.canonical.power);
|
|
return 0;
|
|
}
|
|
|
|
function calcCtrl(host, x) {
|
|
if (host.hasCurve) {
|
|
host.predictCtrl.currentX = x;
|
|
const cCtrl = host.predictCtrl.y(x);
|
|
host.measurements.type('ctrl').variant('predicted').position('atEquipment').value(cCtrl);
|
|
return cCtrl;
|
|
}
|
|
host.logger.warn('No curve data available for control calculation. Returning 0.');
|
|
host.measurements.type('ctrl').variant('predicted').position('atEquipment').value(0, Date.now());
|
|
return 0;
|
|
}
|
|
|
|
module.exports = { calcFlow, calcPower, inputFlowCalcPower, calcCtrl };
|