pub struct YinYangTracker { /* private fields */ }Expand description
Yin-Yang balance tracker.
Maintains a rolling window of dispatch classifications (Yang/Yin) and computes the balance ratio. When the ratio drifts outside the ideal range (0.3–0.7), it flags the imbalance.
§Example
use wm_substrate::anomaly::{YinYangTracker, BalanceState};
let mut tracker = YinYangTracker::default();
tracker.record("memory.create"); // Yang
tracker.record("memory.read"); // Yin
let balance = tracker.balance();
assert_eq!(balance.state, BalanceState::Balanced);Implementations§
Source§impl YinYangTracker
impl YinYangTracker
Sourcepub fn record(&mut self, tool_name: &str)
pub fn record(&mut self, tool_name: &str)
Record a tool dispatch by name (auto-classified as Yang or Yin).
Sourcepub fn record_nature(&mut self, nature: DispatchNature)
pub fn record_nature(&mut self, nature: DispatchNature)
Record a dispatch with a pre-determined nature.
Sourcepub fn yang_ratio(&self) -> f32
pub fn yang_ratio(&self) -> f32
Current Yang ratio (0.0 = all Yin, 1.0 = all Yang).
Sourcepub fn state(&self) -> BalanceState
pub fn state(&self) -> BalanceState
Current balance state.
Sourcepub fn balance(&self) -> YinYangBalance
pub fn balance(&self) -> YinYangBalance
Get a balance snapshot.
Sourcepub fn window_len(&self) -> usize
pub fn window_len(&self) -> usize
Number of dispatches in the current window.
Sourcepub const fn total_dispatches(&self) -> u64
pub const fn total_dispatches(&self) -> u64
Total dispatches (Yang + Yin) since creation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for YinYangTracker
impl RefUnwindSafe for YinYangTracker
impl Send for YinYangTracker
impl Sync for YinYangTracker
impl Unpin for YinYangTracker
impl UnsafeUnpin for YinYangTracker
impl UnwindSafe for YinYangTracker
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