This commit is contained in:
Woutverheijen
2025-10-23 12:20:46 +02:00
parent c081acae4e
commit 60d7dcb1ac

View File

@@ -198,6 +198,32 @@ _callMeasurementHandler(measurementType, value, position, context) {
return reversedCurve;
}
getHealthIndex() {
if (!this.driftHistory || this.driftHistory.length === 0) {
this.logger.debug("HealthIndex: No drift history yet.");
return 1; // 1.0 = fully healthy
}
const avg = (arr) => {
if (!arr || arr.length === 0) return 0;
return arr.reduce((sum, d) => sum + (d.nrmse || 0), 0) / arr.length;
};
const flowDrift = this.driftHistory.filter(d => d.measurement === "flow");
const powerDrift = this.driftHistory.filter(d => d.measurement === "power");
const avgDrift = (avg(flowDrift) + avg(powerDrift)) / 2;
// relDistFromPeak is already stored internally (0 = best, 1 = worst)
const efficiencyScore = 1 - (this.relDistFromPeak || 0);
const healthIndex = (0.6 * efficiencyScore + 0.4 * (1 - avgDrift));
this.logger.debug(`💚 Health Index Calculated: ${healthIndex.toFixed(3)} (eff=${efficiencyScore.toFixed(3)}, drift=${avgDrift.toFixed(3)})`);
return healthIndex.toFixed(3);
}
// -------- Config -------- //
updateConfig(newConfig) {
this.config = this.configUtils.updateConfig(this.config, newConfig);