fix(dashboard): compute 8.0 derived/ratio measures (Completion Rate KPI) - #120
Merged
Conversation
… isn't a row count A dataset measure that is *derived* (a ratio/difference/product/sum over other named measures) had no single source field, so `resolveDatasetWidget` fell back to `aggregate: "count"` and the KPI rendered the row count — "Completion Rate" showed "8" instead of a percentage. Resolve a derived measure into its component specs and compute it client-side from the fetched rows (`matchesMongoFilter` applies each component's own filter). A `ratio` is scaled to 0–100 and defaults to a `0%` format so a bare 0–1 quotient reads as "25%", not "0". Closes the follow-up flagged while building the 2-col KPI grid. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Completion Rate KPI showed a row count
Follow-up flagged while building the 2-col KPI grid (#117). On the Task Overview dashboard, the Completion Rate tile rendered "8" (the total task count) instead of a percentage.
Root cause
An 8.0 dataset measure that is derived — a
ratio/difference/product/sumcomputed over other named measures — has no single source field.resolveDatasetWidgettherefore fell through toaggregate: "count", anduseWidgetQueryreturnedrecords.length.Fix
resolveDerivedMeasure) and compute it client-side from the fetched rows, applying each component's ownfiltervia a newmatchesMongoFilterhelper inquery-builder.ratiois scaled to 0–100 and defaults to a0%format, so a bare 0–1 quotient reads as "25%", not "0".Tests
__tests__/hooks/useDashboardData.test.tsgains coverage for derived-measure resolution + client-side computation (ratio→percent, filtered components). Full suite: 1305 passing, tsc + lint clean.Verified
Browser dashboard: Completion Rate now reads 0% (0 completed of 8) instead of "8".
🤖 Generated with Claude Code