pub struct FeedbackAggregator { /* private fields */ }Expand description
Accumulates FeedbackEvents across sessions and summarizes them by
corpus_id.
Serializable as a flat JSON array of events — same pattern as
MetaTrainingRecord::save_list.
Append is O(1) amortized; Self::summarize is O(N) per call, which
is fine for the scale feedback naturally reaches (hundreds to
thousands of events per corpus).
#[serde(transparent)] keeps the derive-based serializer
(serde_json::to_string(&agg)) and the hand-rolled
Self::save / Self::load path on the same JSON shape — a flat
array of events. Without it, the derive would emit {"events": [...]}
which load rejects.
Implementations§
Source§impl FeedbackAggregator
impl FeedbackAggregator
pub fn new() -> Self
Sourcepub fn with_window(max_events: usize) -> Self
pub fn with_window(max_events: usize) -> Self
Construct with a bounded event window. Once the log reaches
max_events, every new record call drops the oldest event so
memory stays capped — appropriate for long-running services
that only need recent feedback for per-corpus summaries.
Without this cap the event log grows indefinitely; on a 1 event/sec firehose that reaches 100 MB of JSON within a week.
Sourcepub fn set_max_events(&mut self, max_events: Option<usize>)
pub fn set_max_events(&mut self, max_events: Option<usize>)
Attach (or drop) the event-count cap after construction.
pub fn is_empty(&self) -> bool
Sourcepub fn record(&mut self, event: FeedbackEvent)
pub fn record(&mut self, event: FeedbackEvent)
Append one event. When a Self::with_window cap is set and
the log is already at capacity, the oldest event is evicted
first — a FIFO ring over the underlying Vec.
Sourcepub fn events(&self) -> &[FeedbackEvent]
pub fn events(&self) -> &[FeedbackEvent]
Read-only borrow of the raw event log.
Sourcepub fn corpus_ids(&self) -> Vec<String>
pub fn corpus_ids(&self) -> Vec<String>
Distinct corpus_ids that have any feedback attached.
Sourcepub fn summarize(&self, corpus_id: &str) -> Option<FeedbackSummary>
pub fn summarize(&self, corpus_id: &str) -> Option<FeedbackSummary>
Summarize feedback for a specific corpus. Returns None if the
corpus has no events yet.
Sourcepub fn summarize_all(&self) -> Vec<FeedbackSummary>
pub fn summarize_all(&self) -> Vec<FeedbackSummary>
Summarize every corpus that has events. Sorted by corpus_id.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> Result<()>
pub fn save(&self, path: impl AsRef<Path>) -> Result<()>
Save this aggregator (event list) to a JSON file. Creates parent directories as needed.
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self>
pub fn load(path: impl AsRef<Path>) -> Result<Self>
Load an aggregator from a JSON event-log file. Returns an empty aggregator if the file does not exist.
Accepts both a JSON array (legacy, what save writes for
backward compat) and JSON Lines (new format written by
FeedbackEvent::append_to_default_store and sibling append
paths). Detection is first-character based.
Sourcepub fn default_store_path() -> Result<PathBuf>
pub fn default_store_path() -> Result<PathBuf>
Default on-disk feedback log: ~/.sphereql/feedback_events.json.
Parallel convention to
MetaTrainingRecord::default_store_path.
Sourcepub fn load_default_store() -> Result<Self>
pub fn load_default_store() -> Result<Self>
Load the default on-disk feedback store. Empty aggregator if the store does not exist yet.
Trait Implementations§
Source§impl Clone for FeedbackAggregator
impl Clone for FeedbackAggregator
Source§fn clone(&self) -> FeedbackAggregator
fn clone(&self) -> FeedbackAggregator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FeedbackAggregator
impl Debug for FeedbackAggregator
Source§impl Default for FeedbackAggregator
impl Default for FeedbackAggregator
Source§fn default() -> FeedbackAggregator
fn default() -> FeedbackAggregator
Source§impl<'de> Deserialize<'de> for FeedbackAggregator
impl<'de> Deserialize<'de> for FeedbackAggregator
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for FeedbackAggregator
impl RefUnwindSafe for FeedbackAggregator
impl Send for FeedbackAggregator
impl Sync for FeedbackAggregator
impl Unpin for FeedbackAggregator
impl UnsafeUnpin for FeedbackAggregator
impl UnwindSafe for FeedbackAggregator
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