Skip to content

feat: add badges module with offline evaluation engine - #594

Open
vaibhav45sktech wants to merge 1 commit into
PSMRI:feature/gamificationfrom
vaibhav45sktech:main
Open

feat: add badges module with offline evaluation engine#594
vaibhav45sktech wants to merge 1 commit into
PSMRI:feature/gamificationfrom
vaibhav45sktech:main

Conversation

@vaibhav45sktech

Copy link
Copy Markdown
Collaborator

📋 Description

This PR implements the Badges module per the badge system LLD. ASHAs earn recognition badges for consistency, breadth, and case-completion quality, evaluated fully on-device over the existing encrypted Room database. The module is strictly read-only over health data, pays out nothing financially, and no beneficiary-level data ever leaves the device.

Changes

  • Add 5 new Room tables (BADGE_EARNED, BADGE_STATE, BADGE_SYNC_LOG, BADGE_STREAK_FREEZE, BADGE_CONFIG) via additive MIGRATION_63_64; no health-table changes.
  • Add offline badge engine (badges/domain): rules-as-data catalog of 9 badges, recompute-only evaluator, and a streak engine with grace tokens and server-pushed freeze windows for streak fairness.
  • Wake evaluation on record saves via Room InvalidationTracker (no per-repository wiring), on successful syncs, and nightly via WorkManager.
  • Add badge shelf screen and a live never-zero progress widget on the home screen, with 4-tier badge artwork per badge; hidden cleanly by a remote kill switch.
  • Add BadgeSyncWorker for /flw-api/badges/* config/freeze/earned sync on the existing authenticated client; degrades silently to compiled defaults while backend endpoints are unavailable.
  • Log successful sync weeks (BADGE_SYNC_LOG) at pull completion and at the end of a fully successful push cycle.
  • Add unit tests covering the streak engine (grace, freeze windows, streak breaks).

✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

  • Tested on sakshamUatDebug (emulator, API 36): DB migration 63→64 applies cleanly, badge shelf and home widget render with tiered artwork, evaluation recomputes within ~3s of form saves, and StreakEngineTest (9 cases) passes.
  • Server endpoints (GET/POST /flw-api/badges/*) are not yet deployed; the module runs on compiled defaults until then (config pulls are skipped silently).
  • Critical Referral badge is implemented but disabled by default pending structured referral data, per the LLD's deferral; it can be enabled via server config.

* badge tables BADGE_EARNED, BADGE_STATE, BADGE_SYNC_LOG, BADGE_STREAK_FREEZE, BADGE_CONFIG with migration 63 to 64
* badge evaluator with streak engine, grace tokens and freeze windows over existing health tables
* badge shelf screen and live progress widget on home with tiered badge artwork
* badge config and earned sync workers on flw-api/badges endpoints with offline defaults
* unit tests for streak engine
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: de821d2f-8bbd-4cf4-aea2-3850c344402f


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

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