Expand description
ChartAggregate<T> — a bucket/rollup projection over a crate::ChartModel.
Wraps a ChartModel<T> and exposes each series
reduced into fixed-size buckets of bucket_size source points, each
bucket collapsed to one crate::ChartDatum via a ChartAggregateFn
(Mean / Sum / Min / Max / First / Last / Custom) — the
“downsample a long series for display” pattern (a year of daily
sensor readings shown as weekly means, a tick feed shown as 1-minute
bars). Bucket b covers source indices [b*bucket_size, min((b+1)*bucket_size, n)); a trailing partial bucket is included. A
bucket’s category is its first member’s category.
Unlike crate::ChartWindow (which reads straight through to the
source), ChartAggregate materializes its buckets — a bucket’s
category is a clone of a source point’s category, so constructing or
rebuilding a ChartAggregate<T> requires T: Clone. Once built,
read-only queries (point_count, with_point, …) need only T: 'static.
§Reactivity
A tail append that doesn’t change the bucket count updates the
now-not-yet-full last bucket in place (PointUpdated); a tail append
that starts a new bucket finalizes the previous last bucket
(PointUpdated) and appends the new one(s) (PointsInserted).
Symmetrically, a tail removal that doesn’t eliminate the last bucket
recomputes it in place (PointUpdated, since it lost some of its
points); one that eliminates one or more trailing buckets recomputes the
new last bucket the same way and then drops the buckets beyond it
(PointsRemoved). A mid-series insert or removal (front or interior)
falls back to a full per-series rebuild reported as
SeriesDataReplaced. A PointUpdated recomputes just its own bucket.
use teksilo_data::{ChartModel, ChartAggregate, ChartAggregateFn};
let model: ChartModel<i32> = ChartModel::new();
let s = model.add_series("daily");
for i in 0..70 {
model.push_point(s, i, i as f32);
}
let weekly = ChartAggregate::new(model, 7, ChartAggregateFn::Mean);
assert_eq!(weekly.point_count(s), 10); // 70 / 7Structs§
- Chart
Aggregate - A bucket/rollup projection over a
ChartModel<T>.
Enums§
- Chart
Aggregate Fn - A reduction applied to the numeric values within one bucket.