pub struct DriftDetector { /* private fields */ }Expand description
Drift detector using Z-score analysis.
Detects performance regressions using sliding window baseline comparison. Based on statistical process control principles.
§Example
use jugar_web::loadtest::DriftDetector;
let mut detector = DriftDetector::new(10, 2.0);
// Calibrate with baseline samples
detector.calibrate(&[1.0, 1.1, 0.9, 1.0, 1.05, 0.95, 1.0, 1.0, 0.98, 1.02]);
// Normal observation
let result = detector.observe(1.0);
assert!(result.is_normal());
// Anomalous observation (way outside normal range)
let result = detector.observe(10.0);
assert!(result.is_anomaly());Implementations§
Source§impl DriftDetector
impl DriftDetector
Sourcepub fn new(window_size: usize, z_threshold: f64) -> Self
pub fn new(window_size: usize, z_threshold: f64) -> Self
Create a new drift detector.
§Arguments
window_size- Number of samples in the sliding windowz_threshold- Z-score threshold for anomaly detection (typical: 2.0-3.0)
Sourcepub fn with_drift_threshold(self, percent: f64) -> Self
pub fn with_drift_threshold(self, percent: f64) -> Self
Set the drift threshold percentage.
Sourcepub fn calibrate(&mut self, samples: &[f64])
pub fn calibrate(&mut self, samples: &[f64])
Calibrate the detector with baseline samples.
This establishes the “normal” baseline for comparison.
Sourcepub fn is_calibrated(&self) -> bool
pub fn is_calibrated(&self) -> bool
Check if the detector has been calibrated.
Sourcepub fn observe(&mut self, frame_time_ms: f64) -> AnomalyResult
pub fn observe(&mut self, frame_time_ms: f64) -> AnomalyResult
Add a sample and check for anomaly.
Sourcepub fn detect_drift(&self) -> Option<DriftReport>
pub fn detect_drift(&self) -> Option<DriftReport>
Detect sustained drift (window mean significantly different from baseline).
Sourcepub fn window_stats(&self) -> Option<(f64, f64)>
pub fn window_stats(&self) -> Option<(f64, f64)>
Get current window statistics.
Sourcepub fn full_reset(&mut self)
pub fn full_reset(&mut self)
Full reset (clear window and calibration).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DriftDetector
impl RefUnwindSafe for DriftDetector
impl Send for DriftDetector
impl Sync for DriftDetector
impl Unpin for DriftDetector
impl UnwindSafe for DriftDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more