Skip to main content

PersistentAnomalyzer

Struct PersistentAnomalyzer 

Source
pub struct PersistentAnomalyzer { /* private fields */ }
Expand description

A thin wrapper that pairs an Anomalyzer with a PersistenceManager.

Every push is durably written to the WAL before the probability is returned, and a snapshot is compacted automatically every snapshot_interval pushes (default 1 000).

§Example

use anomalyzer_ts::{AnomalyzerConf, PersistentAnomalyzer};

let conf = AnomalyzerConf {
    active_size: 1,
    n_seasons: 4,
    methods: vec!["magnitude".into(), "highrank".into()],
    ..Default::default()
};

// First run — no prior state, starts fresh.
// Subsequent runs — history is restored from disk automatically.
let mut detector = PersistentAnomalyzer::open("/var/lib/myapp/anomaly", conf)?;

let prob = detector.push(15.0)?;
println!("prob = {prob:.3}");

detector.flush()?; // compact on clean shutdown

Implementations§

Source§

impl PersistentAnomalyzer

Source

pub fn open(dir: impl AsRef<Path>, conf: AnomalyzerConf) -> Result<Self>

Open the persistence directory, recover history, and return a ready detector. Creates the directory if it does not exist.

Source

pub fn push(&mut self, value: f64) -> Result<f64>

Push a new value, persist it durably, and return the anomaly probability.

Source

pub fn eval(&self) -> f64

Re-evaluate the current windows without pushing a new value.

Source

pub fn flush(&mut self) -> Result<()>

Force a snapshot + WAL truncation immediately. Call on clean shutdown to minimise replay time at next startup.

Source

pub fn wal_size_bytes(&self) -> Result<u64>

Bytes currently accumulated in the WAL.

Source

pub fn pending_wal_entries(&self) -> usize

WAL entries pending since the last snapshot.

Source

pub fn set_snapshot_interval(&mut self, n: usize)

Adjust how often an automatic snapshot is taken (default: 1 000 pushes).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V