Skip to main content

Threshold

Struct Threshold 

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

A metric limit that has been checked against the metric’s Scale: the metric id is known, the limit is finite, and a ratio-scale limit is non-negative.

Built with Threshold::check. Fields are private so every Threshold in existence has passed that validation; read them back through id, info and limit.

Equality compares the metric id and the limit (f64 ==).

Implementations§

Source§

impl Threshold

Source

pub fn check(id: &str, limit: f64) -> Result<Checked, LimitError>

Validate limit for the metric id.

§Errors

A Scale::Interval limit outside the domain, or on the domain edge at the metric’s bad end, is accepted with a LimitWarning in Checked::warning.

Source

pub fn id(&self) -> &'static str

The metric id this threshold gates.

Source

pub fn info(&self) -> &'static MetricInfo

The catalog entry of the gated metric.

Source

pub fn limit(&self) -> f64

The configured limit.

Source

pub fn warning(&self) -> Option<LimitWarning>

The advisory this limit raises, if any: an interval-scale limit outside its domain, or on the domain edge at the metric’s bad end where a strict comparison cannot fire. The same advisory check returns in Checked::warning, asked of a threshold already in hand — a soft-tier limit soft_limit derived, say.

Source

pub fn breaches(&self, v: f64) -> bool

Whether v breaches the limit: strictly greater for a higher-is-worse metric, strictly less for a lower-is-worse one. A value equal to the limit does not breach, and NaN never does.

Source

pub fn excess(&self, v: f64) -> f64

The signed distance of v past the limit in the bad direction: positive for a breach, zero on the limit, negative inside it.

Source

pub fn severity(&self, v: f64) -> f64

How badly v breaches the limit, as a multiple where 1.0 is “on the limit”. Comparable across metrics, so a ranking of offenders can sort on it directly.

  • Scale::Ratio ceiling with a positive limit: exactly v / limit (bitwise; the ratio users already read as “2× over”). A ratio-scale floor, which the catalog has none of today, inverts it to limit / v.
  • Scale::Ratio with a zero limit (or a floor breached by a zero value): f64::INFINITY. Every such breach saturates; tie-break on excess, as cmp_severity does.
  • Scale::Interval: 1 + excess / unit, one step per unit of badness past the limit. Finite for any finite v, whatever its sign or the limit’s.

Defined for a breaching value. Callers rank only breaches; for a value that does not breach the result is unspecified.

Source

pub fn cmp_severity(&self, a: f64, b: f64) -> Ordering

Order two breaching values of this metric: Ordering::Greater means a is the worse breach. Compares severity and breaks a tie (including two saturated zero-limit severities) on excess.

Source

pub fn cmp_breach(&self, a: f64, other: &Self, b: f64) -> Ordering

Order the breach a of this threshold against the breach b of other, which may gate a different metric or limit: Ordering::Greater means a is the worse breach. The same key as cmp_severity — severity, then excess — so a ranking across metrics and a ranking within one agree.

Source

pub fn is_soft_ratio(ratio: f64) -> bool

Whether ratio is a soft-tier band soft_limit accepts: finite and in (0, 1]. 1.0 is the identity; a ratio above it would make the soft tier looser than the hard gate, and 0, a negative or NaN is a usage error.

Source

pub fn soft_limit(&self, ratio: f64) -> Result<Self, LimitError>

The stricter soft-tier threshold for a band ratio in (0, 1].

  • Scale::Ratio: limit · ratio for a ceiling, limit / ratio for a floor.
  • Scale::Interval: the limit moved (1 - ratio) · unit into the healthy side — up for a floor, down for a ceiling — and clamped at the domain’s healthy edge (max for a floor, min for a ceiling), though never past the hard limit itself, so a soft tier is never looser than its hard tier even for an out-of-domain limit. Multiplying a floor of -50 would loosen it, which is why an interval metric cannot share the ratio arithmetic.

ratio == 1 returns the hard threshold unchanged. No rounding is applied; presentation rounding is the caller’s concern.

§Errors

LimitError::BadRatio when ratio is not finite or lies outside (0, 1].

Source

pub fn change(&self, recorded: f64, v: f64) -> Change

How v has moved from its baseline recorded value, positive when worse. A Scale::Ratio metric reports a percentage of the record (or Change::FromZero for a zero record); a Scale::Interval metric reports points, since a percentage of an arbitrary zero is meaningless. A NaN v is Change::NaN.

Source

pub fn drift(&self, recorded: f64, v: f64) -> f64

A non-negative magnitude of the move from recorded to v. The ratio form lies in [0, 1]; the interval form counts units and is unbounded, so a ranking across the two scales favours a large mi.* move.

  • Scale::Ratio: |recorded - v| / max(|recorded|, |v|), in [0, 1], and 0 when both are zero.
  • Scale::Interval: |recorded - v| / unit, so a hundredth of a point near an arbitrary zero stays a hundredth of a step.

Trait Implementations§

Source§

impl Clone for Threshold

Source§

fn clone(&self) -> Self

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 Threshold

Source§

impl Debug for Threshold

Source§

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

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

impl PartialEq for Threshold

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.