File size: 1,309 Bytes
fa9c65f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /**
* Temporal-anomaly severity thresholds — single source of truth shared by the
* server baseline pipeline (server/worldmonitor/infrastructure/v1/_shared.ts)
* and the client mapper (src/services/temporal-baseline.ts), so the two sides
* cannot drift on what "high" or "critical" means for a z-score.
*
* Dependency-free: importable from Vite client code, Vercel Edge bundles,
* server handlers, and tsx tests alike.
*/
export const Z_THRESHOLD_LOW = 1.5;
export const Z_THRESHOLD_MEDIUM = 2.0;
export const Z_THRESHOLD_HIGH = 3.0;
export type BaselineSeverity = 'normal' | 'medium' | 'high' | 'critical';
export function getBaselineSeverity(zScore: number): BaselineSeverity {
if (zScore >= Z_THRESHOLD_HIGH) return 'critical';
if (zScore >= Z_THRESHOLD_MEDIUM) return 'high';
if (zScore >= Z_THRESHOLD_LOW) return 'medium';
return 'normal';
}
/**
* Client anomaly severity: identical thresholds, but server-emitted anomalies
* are already above the reporting floor, so anything below "high" collapses
* to "medium" (there is no "normal" band on rendered anomalies).
*/
export function getAnomalySeverity(zScore: number): 'medium' | 'high' | 'critical' {
if (zScore >= Z_THRESHOLD_HIGH) return 'critical';
if (zScore >= Z_THRESHOLD_MEDIUM) return 'high';
return 'medium';
}
|