pub struct SlidingWindowAggregator { /* private fields */ }Expand description
A sliding window analytics aggregator for real-time media metrics.
Events are ingested in order via SlidingWindowAggregator::ingest. The
aggregator maintains a rolling window of window_duration_ms worth of
time buckets, each bucket_ms wide. Old buckets outside the window are
automatically evicted.
Implementations§
Source§impl SlidingWindowAggregator
impl SlidingWindowAggregator
Sourcepub fn new(
window_duration_ms: i64,
bucket_ms: i64,
) -> Result<Self, AnalyticsError>
pub fn new( window_duration_ms: i64, bucket_ms: i64, ) -> Result<Self, AnalyticsError>
Create a new aggregator.
Returns an error if window_duration_ms < bucket_ms or either is zero.
Sourcepub fn ingest(&mut self, event: RealtimeEvent)
pub fn ingest(&mut self, event: RealtimeEvent)
Ingest a real-time event.
Events should be delivered roughly in time order; out-of-order events within the current bucket are merged correctly, but events older than the window start are silently dropped.
Sourcepub fn buckets(&self) -> &VecDeque<BucketMetrics>
pub fn buckets(&self) -> &VecDeque<BucketMetrics>
Return a snapshot of all active buckets (oldest first).
Sourcepub fn concurrent_viewers(&self) -> u32
pub fn concurrent_viewers(&self) -> u32
Current instantaneous concurrent viewer count.
Sourcepub fn window_bitrate_stats(&self) -> (f64, u64, u64)
pub fn window_bitrate_stats(&self) -> (f64, u64, u64)
Aggregate bitrate statistics across all active buckets.
Returns (avg_bps, min_bps, max_bps). Returns (0.0, 0, 0) if no
bitrate samples exist in the window.
Sourcepub fn window_buffer_events(&self) -> u32
pub fn window_buffer_events(&self) -> u32
Total buffer events in the current window.
Sourcepub fn window_peak_concurrent(&self) -> u32
pub fn window_peak_concurrent(&self) -> u32
Peak concurrent viewers across all active buckets.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SlidingWindowAggregator
impl RefUnwindSafe for SlidingWindowAggregator
impl Send for SlidingWindowAggregator
impl Sync for SlidingWindowAggregator
impl Unpin for SlidingWindowAggregator
impl UnsafeUnpin for SlidingWindowAggregator
impl UnwindSafe for SlidingWindowAggregator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more