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§
Trait Implementations§
Source§impl Clone for MovingSpread
impl Clone for MovingSpread
Source§fn clone(&self) -> MovingSpread
fn clone(&self) -> MovingSpread
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for MovingSpread
impl Debug for MovingSpread
Source§impl Display for MovingSpread
impl Display for MovingSpread
Source§impl Metric<f64> for MovingSpread
impl Metric<f64> for MovingSpread
Source§type Output = f64
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>
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 moreSource§fn observe(&mut self, x: Input) -> f64
fn observe(&mut self, x: Input) -> 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
impl StatefulMetric<f64> for MovingSpread
fn observe_opt(&mut self, x: Input) -> Option<Self::Output>
Auto Trait Implementations§
impl Freeze for MovingSpread
impl RefUnwindSafe for MovingSpread
impl Send for MovingSpread
impl Sync for MovingSpread
impl Unpin for MovingSpread
impl UnwindSafe for MovingSpread
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