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
impl RangeQuery
Sourcepub fn sum(self) -> Option<u32>
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));Sourcepub fn average(self) -> Option<f64>
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());Sourcepub fn average_nonzero(self) -> Option<f64>
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.
Sourcepub fn count_nonzero(self) -> Option<usize>
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.
Sourcepub fn last_seen(self) -> Option<usize>
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.
Sourcepub fn first_seen(self) -> Option<usize>
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.
Sourcepub fn into_buckets(self) -> Vec<u32>
pub fn into_buckets(self) -> Vec<u32>
Returns a vector of bucket counts for the range.