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 shutdownImplementations§
Source§impl PersistentAnomalyzer
impl PersistentAnomalyzer
Sourcepub fn open(dir: impl AsRef<Path>, conf: AnomalyzerConf) -> Result<Self>
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.
Sourcepub fn push(&mut self, value: f64) -> Result<f64>
pub fn push(&mut self, value: f64) -> Result<f64>
Push a new value, persist it durably, and return the anomaly probability.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Force a snapshot + WAL truncation immediately. Call on clean shutdown to minimise replay time at next startup.
Sourcepub fn wal_size_bytes(&self) -> Result<u64>
pub fn wal_size_bytes(&self) -> Result<u64>
Bytes currently accumulated in the WAL.
Sourcepub fn pending_wal_entries(&self) -> usize
pub fn pending_wal_entries(&self) -> usize
WAL entries pending since the last snapshot.
Sourcepub fn set_snapshot_interval(&mut self, n: usize)
pub fn set_snapshot_interval(&mut self, n: usize)
Adjust how often an automatic snapshot is taken (default: 1 000 pushes).
Auto Trait Implementations§
impl Freeze for PersistentAnomalyzer
impl RefUnwindSafe for PersistentAnomalyzer
impl Send for PersistentAnomalyzer
impl Sync for PersistentAnomalyzer
impl Unpin for PersistentAnomalyzer
impl UnsafeUnpin for PersistentAnomalyzer
impl UnwindSafe for PersistentAnomalyzer
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