pub fn sliding_window_count(
        previous: Option<u64>,
        current: Option<u64>,
        now: Duration,
        size: Duration,
    ) -> u64 {
        let current_window = (now.as_secs() / size.as_secs()) * size.as_secs();
        let next_window = current_window + size.as_secs();
        let weight = (Duration::from_secs(next_window).as_millis() - now.as_millis()) as f64
            / size.as_millis() as f64;
        current.unwrap_or(0) + (previous.unwrap_or(0) as f64 * weight).round() as u64
    }
/// Calculates weighted count based on previous and current time windows.
Calculates weighted count based on previous and current time windows.
Calculates weighted count based on previous and current time windows .
pub fn sliding_window_count(
        previous: Option<u64>,
        current: Option<u64>,
        now: Duration,
        size: Duration,
    ) -> u64 {
        let current_window = (now.as_secs() / size.as_secs()) * size.as_secs();
        let next_window = current_window + size.as_secs();
        let weight = (Duration::from_secs(next_window).as_millis() - now.as_millis()) as f64
            / size.as_millis() as f64;
        current.unwrap_or(0) + (previous.unwrap_or(0) as f64 * weight).round() as u64
    }
pub fn sliding_window_count ( previous : Option < u64 > , current : Option < u64 > , now : Duration , size : Duration , ) -> u64 { let current_window = ( now . as_secs ( ) / size . as_secs ( ) ) * size . as_secs ( ) ; let next_window = current_window + size . as_secs ( ) ; let weight = ( Duration :: from_secs ( next_window ) . as_millis ( ) - now . as_millis ( ) ) as f64 / size . as_millis ( ) as f64 ; current . unwrap_or ( 0 ) + ( previous . unwrap_or ( 0 ) as f64 * weight ) . round ( ) as u64 }
Calculates weighted count based on previous and current time windows.
Calculates weighted count based on previous and current time windows .
previous
Option<u64>
current
Option<u64>
now
Duration
size
Duration
previous
Option<u64>
current
Option<u64>
now
Duration
size
Duration