Struct MovingSpread

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

Calculates the spread, the (max-min) in a moving window.

§Example:

let mut spread = metrics::MovingSpread::new(3);
assert_eq!(spread.observe(1.4).is_nan(), true);
assert_eq!(spread.observe(1.2).is_nan(), true);
assert_approx_eq!(spread.observe(1.3), 0.2);
assert_approx_eq!(spread.observe(-0.5), 1.8);

Implementations§

Source§

impl MovingSpread

Source

pub fn new(window_size: usize) -> Self

Trait Implementations§

Source§

impl Clone for MovingSpread

Source§

fn clone(&self) -> MovingSpread

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MovingSpread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MovingSpread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Metric<f64> for MovingSpread

Source§

type Output = f64

The type of elements recorded by the metric. For a delta of last vs current, this might be an n-dimentional vector. It typically needs to be an Owned type, rather than a reference. Read more
Source§

fn observe_opt(&mut self, x: f64) -> Option<Self::Output>

Similar to observe except None is returned instead of f64::NAN to indicate not enough data collected. Useful if you like Read more
Source§

fn observe(&mut self, x: Input) -> f64
where Self::Output: Into<f64>,

Records the value, and return the calculated metric. If there are not enough samples to calculate the metric, f64::NAN is returned, which will always compare false. So a tolerance check observe(x) < 0.0001 will fail until enough samples have been collected. If you don’t like NANs, then Metric::observe_opt is your friend.
Source§

impl StatefulMetric<f64> for MovingSpread

Source§

fn store(&mut self, x: f64)

Stores the value, and likely discards older values.
Source§

fn value_opt(&self) -> Option<f64>

The calculated value. Read more
Source§

fn observe_opt(&mut self, x: Input) -> Option<Self::Output>

Source§

fn value(&self) -> f64
where Self::Output: Into<f64>,

The calculated value. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.