EMRY-011: EMA + Welford streaming processors #56

Merged
vxfemboy merged 2 commits from emry-011-ema-welford into main 2026-06-25 02:26:31 +00:00
vxfemboy commented 2026-06-25 02:13:50 +00:00 (Migrated from github.com)

Closes EMRY-011 (#9). Branched off main.

What

crates/emry-engine/src/stats.rs — two Processor impls over a configured MetricId:

  • Ema — alpha-weighted EMA, seeded on first value; alpha validated to (0,1].
  • Welford — single-pass online sample mean/std (Knuth/Welford two-delta form); emits {base}_mean and {base}_std.

Non-finite inputs are rejected (skipped, state untouched) so a NaN step never corrupts the running stat; alerting is deferred to the anomaly processor (EMRY-013). Reads from both Event::Metric and Event::MetricsBatch.

Verification

  • ./scripts/pre-commit-rust.sh green: clippy -D warnings, 13 engine tests, stats.rs 99% lines, total 95.59%
  • Reference series match hand-computed values: EMA [1,2,3,4]3.125; Welford [2,4,4,4,5,5,7,9]→ mean 5, sample var 32/7
  • NaN/Inf rejection verified to leave state intact in both

Review

No issues above threshold. Strengthened the Welford test to also assert the emitted _std value per the spec's reference-value requirement.

Closes EMRY-011 (#9). Branched off `main`. ## What `crates/emry-engine/src/stats.rs` — two `Processor` impls over a configured `MetricId`: - **`Ema`** — alpha-weighted EMA, seeded on first value; `alpha` validated to `(0,1]`. - **`Welford`** — single-pass online sample mean/std (Knuth/Welford two-delta form); emits `{base}_mean` and `{base}_std`. Non-finite inputs are **rejected** (skipped, state untouched) so a NaN step never corrupts the running stat; alerting is deferred to the anomaly processor (EMRY-013). Reads from both `Event::Metric` and `Event::MetricsBatch`. ## Verification - `./scripts/pre-commit-rust.sh` green: clippy `-D warnings`, 13 engine tests, stats.rs 99% lines, total 95.59% - Reference series match hand-computed values: EMA `[1,2,3,4]`→`3.125`; Welford `[2,4,4,4,5,5,7,9]`→ mean `5`, sample var `32/7` - NaN/Inf rejection verified to leave state intact in both ## Review No issues above threshold. Strengthened the Welford test to also assert the emitted `_std` value per the spec's reference-value requirement.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
femboy/emry!56
No description provided.