pub struct TimeWindow {
pub window_type: WindowType,
pub duration: Duration,
pub start_time: u64,
pub end_time: u64,
/* private fields */
}Expand description
Time-based window for event processing
Fields§
§window_type: WindowTypeWindow type
duration: DurationWindow duration
start_time: u64Window start time (milliseconds since epoch)
end_time: u64Window end time (milliseconds since epoch)
Implementations§
Source§impl TimeWindow
impl TimeWindow
Sourcepub fn new(
window_type: WindowType,
duration: Duration,
start_time: u64,
max_events: usize,
) -> Self
pub fn new( window_type: WindowType, duration: Duration, start_time: u64, max_events: usize, ) -> Self
Create a new time window
Sourcepub fn add_event(&mut self, event: StreamEvent) -> bool
pub fn add_event(&mut self, event: StreamEvent) -> bool
Add event to window if it fits
Sourcepub fn record(&mut self, event: StreamEvent)
pub fn record(&mut self, event: StreamEvent)
Records an event into a continuously sliding window: advances the
trailing boundary to the event’s own timestamp and evicts anything
older than duration, instead of rejecting events the way
add_event does once [start_time, end_time) is
stale.
add_event and WindowManager are built around a history of
many fixed, non-advancing windows (useful for looking back at past
windows later). record is for the opposite case: maintaining a
single live value — “how many X in the trailing N seconds, as of
right now” — which is what most rate/threshold rules actually need.
No-op on the boundary advance for non-Sliding window types (the
event is still recorded); tumbling/session semantics don’t have a
meaningful “trailing” window to advance.
Sourcepub fn contains_timestamp(&self, timestamp: u64) -> bool
pub fn contains_timestamp(&self, timestamp: u64) -> bool
Check if timestamp falls within this window
Sourcepub fn events(&self) -> &VecDeque<StreamEvent>
pub fn events(&self) -> &VecDeque<StreamEvent>
Get all events in window
Sourcepub fn is_expired(&self, current_time: u64) -> bool
pub fn is_expired(&self, current_time: u64) -> bool
Check if window is expired
Sourcepub fn duration_ms(&self) -> u64
pub fn duration_ms(&self) -> u64
Get window duration in milliseconds
Sourcepub fn events_by_type(&self, event_type: &str) -> Vec<&StreamEvent>
pub fn events_by_type(&self, event_type: &str) -> Vec<&StreamEvent>
Get events filtered by type
Sourcepub fn average(&self, field: &str) -> Option<f64>
pub fn average(&self, field: &str) -> Option<f64>
Calculate average of numeric field across events
Sourcepub fn latest_timestamp(&self) -> Option<u64>
pub fn latest_timestamp(&self) -> Option<u64>
Get the latest event timestamp
Sourcepub fn events_in_range(&self, start: u64, end: u64) -> Vec<&StreamEvent>
pub fn events_in_range(&self, start: u64, end: u64) -> Vec<&StreamEvent>
Get events within a sub-window