RangeQuery

Struct RangeQuery 

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

Builder for querying a specific time range.

Provides aggregation methods like sum(), average(), and iteration over buckets.

Implementations§

Source§

impl RangeQuery

Source

pub fn take(self, n: usize) -> Self

Limit the range to at most N buckets.

Source

pub fn sum(self) -> Option<u32>

Sum all events in the range.

Returns None if the event doesn’t exist or the time unit isn’t tracked.

§Examples
use tiny_counter::EventStore;

let store = EventStore::new();
store.record_count("clicks", 10);

let total = store.query("clicks").last_days(7).sum();
assert_eq!(total, Some(10));
Source

pub fn average(self) -> Option<f64>

Calculate the average count per bucket.

Returns None if the event doesn’t exist, the time unit isn’t tracked, or there’s no data in the range.

§Examples
use tiny_counter::EventStore;

let store = EventStore::new();
store.record_count("api_calls", 100);

let avg = store.query("api_calls").last_days(7).average();
assert!(avg.is_some());
Source

pub fn average_nonzero(self) -> Option<f64>

Calculate the average excluding zero buckets.

Returns None if the event doesn’t exist, the time unit isn’t tracked, or there are no non-zero buckets.

Source

pub fn count_nonzero(self) -> Option<usize>

Sum the number of non-zero buckets.

Returns None if the event doesn’t exist or the time unit isn’t tracked.

Source

pub fn last_seen(self) -> Option<usize>

Returns the bucket index of the last seen event.

Returns None if the event doesn’t exist, the time unit isn’t tracked, or the event has never been recorded.

Source

pub fn first_seen(self) -> Option<usize>

Returns the bucket index of the first seen event.

Returns None if the event doesn’t exist, the time unit isn’t tracked, or the event has never been recorded.

Source

pub fn into_buckets(self) -> Vec<u32>

Returns a vector of bucket counts for the range.

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