pub struct CtrTracker { /* private fields */ }Expand description
Tracks CTR metrics for an arbitrary number of items.
Each item is identified by a &str key. Items are created on first
impression or click — there is no need to pre-register them.
Implementations§
Source§impl CtrTracker
impl CtrTracker
Sourcepub fn record_impression(&mut self, item_id: &str)
pub fn record_impression(&mut self, item_id: &str)
Records one impression for item_id.
If the item is not yet tracked it is created with zero counts first.
Sourcepub fn record_impressions(&mut self, item_id: &str, count: u64)
pub fn record_impressions(&mut self, item_id: &str, count: u64)
Records count impressions for item_id in a single call.
Useful for bulk-ingesting impression counts from a reporting pipeline.
Sourcepub fn record_click(&mut self, item_id: &str)
pub fn record_click(&mut self, item_id: &str)
Records one click for item_id.
If the item is not yet tracked it is created with zero counts first. Clicks without a preceding impression are allowed (e.g. deep links).
Sourcepub fn record_clicks(&mut self, item_id: &str, count: u64)
pub fn record_clicks(&mut self, item_id: &str, count: u64)
Records count clicks for item_id in a single call.
Sourcepub fn stats(&self, item_id: &str) -> Option<&CtrStats>
pub fn stats(&self, item_id: &str) -> Option<&CtrStats>
Returns the CtrStats for item_id, or None if it has never been
seen.
Sourcepub fn ctr(&self, item_id: &str) -> Result<f64, AnalyticsError>
pub fn ctr(&self, item_id: &str) -> Result<f64, AnalyticsError>
Returns the raw CTR for item_id.
§Errors
Returns AnalyticsError::InvalidInput when item_id is not tracked.
Sourcepub fn ranked(&self) -> Vec<CtrVariant>
pub fn ranked(&self) -> Vec<CtrVariant>
Returns items ranked by CTR descending.
Items with no impressions are placed at the bottom (CTR = 0). Items with equal CTR are ordered by total impressions descending (more data first).
Sourcepub fn winner(&self, min_impressions: u64) -> Result<CtrVariant, AnalyticsError>
pub fn winner(&self, min_impressions: u64) -> Result<CtrVariant, AnalyticsError>
Returns the item with the highest CTR among those with at least
min_impressions impressions.
§Errors
Returns AnalyticsError::InsufficientData when no item meets the
min_impressions threshold.
Sourcepub fn item_count(&self) -> usize
pub fn item_count(&self) -> usize
Returns the total number of items currently being tracked.
Trait Implementations§
Source§impl Clone for CtrTracker
impl Clone for CtrTracker
Source§fn clone(&self) -> CtrTracker
fn clone(&self) -> CtrTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CtrTracker
impl Debug for CtrTracker
Source§impl Default for CtrTracker
impl Default for CtrTracker
Source§fn default() -> CtrTracker
fn default() -> CtrTracker
Auto Trait Implementations§
impl Freeze for CtrTracker
impl RefUnwindSafe for CtrTracker
impl Send for CtrTracker
impl Sync for CtrTracker
impl Unpin for CtrTracker
impl UnsafeUnpin for CtrTracker
impl UnwindSafe for CtrTracker
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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