Skip to main content

Depletion

Struct Depletion 

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

Predicts how soon a falling level will reach a threshold.

This is the primitive behind “warn before a tank runs dry”. Feed it successive level readings and it estimates how many more samples remain before the level reaches a low mark, so an alert can fire with time to act on it. The technique one layer down is a linear extrapolation of the most recent rate of fall, so it reacts to noise and pairs well with a Smoother on the input.

§Examples

use pamoja_kit::Depletion;

let mut tank = Depletion::new(0.0);
assert_eq!(tank.update(10.0), None); // first reading: no rate is known yet
assert_eq!(tank.update(8.0), Some(4)); // falling 2 per sample, 4 until empty

Implementations§

Source§

impl Depletion

Source

pub fn new(threshold: f32) -> Self

Creates a predictor that warns as the level approaches threshold.

§Arguments
  • threshold - the low level to predict reaching, such as an empty tank.
§Returns

A predictor awaiting its first two readings.

Source

pub fn update(&mut self, level: f32) -> Option<u32>

Records a reading and estimates the samples until the threshold is reached.

§Arguments
  • level - the latest measured level.
§Returns

Some(0) if the level is already at or below the threshold; Some(n) for the estimated number of samples until it is reached at the current rate of fall; or None if the level is steady or rising, or if this is the first reading and no rate is known yet.

Trait Implementations§

Source§

impl Clone for Depletion

Source§

fn clone(&self) -> Depletion

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Depletion

Source§

impl Debug for Depletion

Source§

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

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

impl PartialEq for Depletion

Source§

fn eq(&self, other: &Depletion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Depletion

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, 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.