Files
egutierrez 750b7abcd5 chore: auto-commit (97 archivos)
- .claude/CLAUDE.md
- .claude/agents/fn-recopilador/SKILL.md
- .claude/rules/INDEX.md
- .claude/rules/cpp_apps.md
- bash/functions/infra/build_cpp_windows.sh
- cpp/CMakeLists.txt
- cpp/PATTERNS.md
- cpp/framework/app_base.cpp
- cpp/framework/app_base.h
- dev/issues/README.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 18:11:24 +02:00

30 lines
931 B
Go

package datascience
import "sort"
// MetricsDrift calculates the relative drift of a current measurement against
// a historical baseline computed at the given percentile.
//
// historical is a window of past measurements (e.g. duration_ms, bytes).
// percentile selects the baseline: 0.5 = median, 0.95 = p95.
// drift = (current - baseline) / baseline, e.g. 0.47 means +47% above baseline.
//
// Returns drift=0, baseline=0 when historical is empty or baseline is zero.
func MetricsDrift(historical []int64, current int64, percentile float64) (drift float64, baseline int64) {
if len(historical) == 0 {
return 0, 0
}
sorted := make([]int64, len(historical))
copy(sorted, historical)
sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] })
baseline = Percentile(sorted, percentile)
if baseline == 0 {
return 0, 0
}
drift = float64(current-baseline) / float64(baseline)
return drift, baseline
}