[metrics] Recalculate average after removing the last value - #301
Open
dajiaohuang wants to merge 1 commit into
Open
[metrics] Recalculate average after removing the last value#301dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #300.
Removing the last numeric value during an incremental average update divides by zero. If the same transaction subsequently adds another row, the intermediate nonfinite result survives until Metrics exposes it as undefined, despite the final table having numeric data.
Return undefined from the removal shortcut when its prior length is one. This uses the existing full-recalculation fallback on the final values, without changing public APIs or other aggregators.
The regression removes the sole row, adds two rows in one transaction, checks the final average and single listener notification, and verifies a later update.
Validation
f09e5a3b74) and passes with this patch.npm run compileForTestpasses.git diff --checkpass for the patch. CSpell passes for the production file; repository configuration excludes test files.test/unit/core/other: 753 pass, 2 middleware synchronization tests fail (transformed data/value returning to the originator). Both fail identically after removing this patch and rebuilding main.npm run preCommitcould not complete on Windows: the spell stage fails withspawn npx ENOENT. Focused tests do not establish whole-repository 100% coverage.Tested on Windows with Node.js v24.14.1. No dependencies or generated files changed.