Skip to content

Add Conquest Rate metric to the Home dashboard #307

@brianlan

Description

@brianlan

Summary

Add a Conquest Rate metric beside Problem Coverage on the Home dashboard. Conquest Rate should show the percentage of non-deleted problems whose latest known correct/incorrect result is correct.

Background / Context

Issue #305 added the protected Home dashboard with Problem Coverage and a daily activity grid. The Home dashboard now needs a second large-number metric with similar visual treatment: Conquest Rate.

Confirmed product decisions:

  • Problem Coverage remains # tried problems / # total non-deleted problems.
  • Conquest Rate means # mastered non-deleted problems / # total non-deleted problems.
  • A mastered problem is one whose latest known correct/incorrect result is correct.
  • Pending-review results are ignored for conquest. They still count for coverage and activity, but do not change mastery until resolved.
  • The Conquest Rate card should visually sit beside Problem Coverage and have comparable prominence.

Relevant codebase context from issue #305:

  • Home API endpoint: GET /api/v1/home/summary.
  • Backend Home route area: backend/app/presentation/home.py.
  • Frontend Home page: frontend/src/pages/HomePage.tsx.
  • Existing Home tests: backend/tests/api/test_home.py and frontend/src/pages/HomePage.test.tsx.

Problem

The Home dashboard currently shows only coverage. Coverage answers whether a problem has been tried, but it does not show how much of the problem set has been conquered/mastered.

Goal / Expected Behavior

The Home dashboard should show two sibling large-number stat cards:

  • Problem Coverage: tried problems over total problems.
  • Conquest Rate: mastered problems over total problems.

For zero total problems, Conquest Rate should show 0% with a short zero-state note rather than hiding the metric.

Scope

This issue should cover:

  • Extend the Home summary API response with conquest data.
  • Compute mastered problems from the latest known correct/incorrect result per problem.
  • Ignore pending-review results when deciding mastery.
  • Render a Conquest Rate stat card beside Problem Coverage.
  • Add backend and frontend tests for the new metric.

Out of Scope

This issue should not cover:

  • Changing the existing Problem Coverage formula.
  • Changing grading, practice, or exam workflows.
  • Adding drill-down views or problem lists behind the metric.
  • Changing the activity grid layout or month labels.
  • Fixing the dark-theme bottom background issue.

Chosen Implementation Approach

Extend GET /api/v1/home/summary with a conquest object, for example:

  • conquest.totalProblems
  • conquest.masteredProblems
  • conquest.percentage

Use all non-deleted problems owned by the current user as the denominator.

For each non-deleted problem, determine the latest known correct/incorrect event across:

  • Practice attempts, using practice_attempts.createdAt and gradingStatus.
  • Submitted exam items, using exam.submittedAt for the event time and each item’s grading.status / correctness fields.
  • Self-reported exam items after submission, using the resolved item grading state when available.

Ignore pending-review events for conquest. If a problem has only pending-review activity and no prior correct/incorrect result, it is not mastered.

Implementation Plan

The implementor should:

  1. Update the Home summary response model/types to include conquest.
  2. Collect relevant practice attempts for the current user and non-deleted problem IDs.
  3. Collect submitted exams for the current user and inspect their items for correct/incorrect outcomes.
  4. For each problem, keep only the latest correct/incorrect event by timestamp.
  5. Count a problem as mastered when that latest known correct/incorrect event is correct.
  6. Return the conquest totals and rounded percentage alongside existing coverage and activity data.
  7. Update the Home page to render Problem Coverage and Conquest Rate as sibling stat cards.
  8. Preserve existing coverage and activity behavior.

Relevant Files / Areas

Likely relevant areas:

  • backend/app/presentation/home.py
  • backend/tests/api/test_home.py
  • frontend/src/pages/HomePage.tsx
  • frontend/src/pages/HomePage.test.tsx

Suggested verification commands:

cd backend && uv run pytest backend/tests/api/test_home.py
cd frontend && npm test -- --run HomePage

Tests Required

The implementor must add or update automated tests covering:

  • API returns conquest fields with zero problems.
  • Latest correct practice attempt makes a problem mastered.
  • Latest incorrect practice attempt makes it not mastered.
  • Latest submitted exam correct/incorrect item participates in conquest.
  • Pending-review-only activity does not mark a problem mastered.
  • Pending-review latest event does not override the latest known correct/incorrect result.
  • Deleted problems and other users’ data are excluded.
  • Frontend renders the Conquest Rate card beside Problem Coverage.
  • Frontend renders zero-state and normal supporting text for conquest.

At minimum, tests should verify:

  • The happy path with both coverage and conquest values.
  • The pending-review edge case.
  • User data isolation.
  • That existing Problem Coverage rendering still works.

Manual Verification / Self-Check

Before claiming this issue is done, the implementor must:

  1. Run the relevant backend Home API tests.
  2. Run the relevant frontend Home page tests.
  3. Load the Home page with no problems and verify both metrics show 0% with appropriate notes.
  4. Create or seed correct and incorrect activity and verify Conquest Rate changes as expected.
  5. Include exact commands and pass/fail results in the PR description.

Suggested verification commands:

cd backend && uv run pytest backend/tests/api/test_home.py
cd frontend && npm test -- --run HomePage

Reviewer Acceptance Checklist

The reviewer should verify that:

  • Conquest Rate is defined as mastered non-deleted problems over total non-deleted problems.
  • Pending-review results are ignored for mastery but not coverage/activity.
  • Latest known correct/incorrect result wins per problem.
  • API data is scoped to the current user.
  • Deleted problems are excluded.
  • The Home UI shows Problem Coverage and Conquest Rate with similar prominence.
  • Required backend and frontend tests were added or updated.
  • Existing coverage and activity behavior did not regress.
  • The PR includes self-verification commands and results.

Dependencies

Depends on the Home dashboard from #305 being present in the target branch.

Follow-Up Work

Possible future work, not included here:

  • Drill-down list of mastered/unmastered problems.
  • Subject/tag-specific conquest metrics.

Definition of Done

This issue is done when:

  • GET /api/v1/home/summary returns conquest data.
  • The Home dashboard displays Conquest Rate beside Problem Coverage.
  • Pending-review handling follows the confirmed behavior.
  • Required automated tests pass.
  • Manual verification is documented in the PR.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions