Skip to main content

GroupStats

Struct GroupStats 

Source
#[non_exhaustive]
pub struct GroupStats { pub count: u64, pub sum: f64, pub min: Option<IndexValue>, pub max: Option<IndexValue>, }
Expand description

One group’s live statistics.

use kevy_index::{GroupStats, IndexValue};
let mut total = GroupStats::default();
let mut part = GroupStats::default();
(part.count, part.sum, part.min, part.max) = (2, 10.0, Some(IndexValue::I64(3)), Some(IndexValue::I64(7)));
total.merge(&part);
assert_eq!(total.avg(), Some(5.0));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§count: u64

Rows in the group.

s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").count, 2);
s.apply(b"o:2", AggRow::Removed);
assert_eq!(s.group(b"eu").count, 1);
§sum: f64

Sum of the aggregated field (f64 accumulation — the i64 overflow guard; precision bounds documented).

s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").sum, 42.0);
§min: Option<IndexValue>

Exact minimum (None only when count == 0).

s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").min, Some(IndexValue::I64(12)));
// exact under deletion: the next-smallest value takes over
s.apply(b"o:2", AggRow::Removed);
assert_eq!(s.group(b"eu").min, Some(IndexValue::I64(30)));
assert_eq!(s.group(b"us").min, None, "an unknown group has no rows");
§max: Option<IndexValue>

Exact maximum.

s.apply(b"o:1", row(b"eu", 30));
s.apply(b"o:2", row(b"eu", 12));
assert_eq!(s.group(b"eu").max, Some(IndexValue::I64(30)));
s.apply(b"o:1", row(b"eu", 5));
assert_eq!(s.group(b"eu").max, Some(IndexValue::I64(12)));

Implementations§

Source§

impl GroupStats

Source

pub fn avg(&self) -> Option<f64>

Derived average.

assert_eq!(kevy_index::GroupStats::default().avg(), None);
Source

pub fn rank_score(&self, by: AggBy) -> f64

This group’s standing under by, oriented so a larger score ranks higher for every metric — the order sort_groups puts groups in (a smaller minimum ranks higher; a group without one ranks last).

use kevy_index::{AggBy, GroupStats, IndexValue};
let mut g = GroupStats::default();
(g.count, g.min) = (3, Some(IndexValue::I64(2)));
assert_eq!((g.rank_score(AggBy::Count), g.rank_score(AggBy::Min)), (3.0, -2.0));
assert_eq!(g.rank_score(AggBy::Max), f64::NEG_INFINITY);
Source

pub fn merge(&mut self, part: &GroupStats)

Fold one shard’s partial for the same group into this one (reduce side): counts and sums add, min and max take the extremes.

use kevy_index::{GroupStats, IndexValue};
let mut a = GroupStats::default();
a.count = 1;
a.min = Some(IndexValue::I64(5));
let mut b = GroupStats::default();
b.count = 1;
b.min = Some(IndexValue::I64(2));
a.merge(&b);
assert_eq!((a.count, a.min), (2, Some(IndexValue::I64(2))));

Trait Implementations§

Source§

impl Clone for GroupStats

Source§

fn clone(&self) -> GroupStats

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 Debug for GroupStats

Source§

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

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

impl Default for GroupStats

Source§

fn default() -> GroupStats

Returns the “default value” for a type. Read more
Source§

impl PartialEq for GroupStats

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GroupStats

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