B1.3: isStable real threshold (config-driven, replaces tautology)
The legacy stdDev < stdDev*2 was always true. New behaviour: stdDev <= config.calibration.stabilityThreshold OR stdDev === 0. Default threshold 0.01 in scaling-units. Schema field + editor UI added. 4 BUG-PRESERVED tests rewritten + 4 new edge tests. 101/101 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const { stats } = require('generalFunctions');
|
||||
|
||||
const MARGIN_FACTOR = 2;
|
||||
const DEFAULT_STABILITY_THRESHOLD = 0.01;
|
||||
|
||||
/**
|
||||
* Calibration helper extracted from measurement/specificClass.js.
|
||||
@@ -23,8 +23,9 @@ class Calibrator {
|
||||
|
||||
/**
|
||||
* Decide whether the rolling window is stable enough to trust.
|
||||
* Mirrors the original threshold check; with `stdDev=0` (constant input)
|
||||
* the comparison short-circuits to true.
|
||||
* Compares the window's stdDev against config.calibration.stabilityThreshold
|
||||
* (absolute, in scaling-units). A constant buffer (stdDev=0) is always
|
||||
* stable regardless of threshold.
|
||||
*/
|
||||
isStable() {
|
||||
const values = this._storedValues();
|
||||
@@ -32,8 +33,12 @@ class Calibrator {
|
||||
return { isStable: false, stdDev: 0 };
|
||||
}
|
||||
const stdDev = stats.stdDev(values);
|
||||
const stableThreshold = stdDev * MARGIN_FACTOR;
|
||||
return { isStable: stdDev < stableThreshold || stdDev === 0, stdDev };
|
||||
const cfg = this._config();
|
||||
const raw = cfg && cfg.calibration && cfg.calibration.stabilityThreshold;
|
||||
const threshold = Number.isFinite(Number(raw)) && Number(raw) >= 0
|
||||
? Number(raw)
|
||||
: DEFAULT_STABILITY_THRESHOLD;
|
||||
return { isStable: stdDev === 0 || stdDev <= threshold, stdDev };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ class nodeClass extends BaseNodeAdapter {
|
||||
},
|
||||
smoothing: { smoothWindow: uiConfig.count, smoothMethod: uiConfig.smooth_method },
|
||||
simulation: { enabled: uiConfig.simulator },
|
||||
calibration: { stabilityThreshold: uiConfig.stabilityThreshold },
|
||||
mode: { current: mode },
|
||||
channels,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user