Skip to content

fix(dashboard): compute 8.0 derived/ratio measures (Completion Rate KPI) - #120

Merged
os-zhuang merged 1 commit into
mainfrom
fix/dashboard-completion-rate
Jun 11, 2026
Merged

fix(dashboard): compute 8.0 derived/ratio measures (Completion Rate KPI)#120
os-zhuang merged 1 commit into
mainfrom
fix/dashboard-completion-rate

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

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 / sum computed over other named measures — has no single source field. resolveDatasetWidget therefore fell through to aggregate: "count", and useWidgetQuery returned records.length.

Fix

  • Resolve a derived measure into its component measure specs (resolveDerivedMeasure) and compute it client-side from the fetched rows, applying each component's own filter via a new matchesMongoFilter helper in query-builder.
  • A ratio is scaled to 0–100 and defaults to a 0% format, so a bare 0–1 quotient reads as "25%", not "0".
  • Non-derived measures are unchanged.

Tests

__tests__/hooks/useDashboardData.test.ts gains 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

… 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>
@os-zhuang
os-zhuang merged commit d9da62e into main Jun 11, 2026
@os-zhuang
os-zhuang deleted the fix/dashboard-completion-rate branch June 11, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant