Skip to content

feat: grade-relative FLN certification distance algorithm - #218

Open
jgupta05072003-code wants to merge 1 commit into
mainfrom
feat/certification-distance-algorithm
Open

feat: grade-relative FLN certification distance algorithm#218
jgupta05072003-code wants to merge 1 commit into
mainfrom
feat/certification-distance-algorithm

Conversation

@jgupta05072003-code

Copy link
Copy Markdown
Collaborator

Summary

This is the algorithm Pavani flagged as the top pilot-readiness blocker in the 2026-08-17 sync: student current level → distance to FLN certification. Per clarification, "distance" means how many more levels a student needs to cover, after their diagnostic placement, to be certified for their specific grade — not a flat number.

Turns out the whole codebase (9 call sites, backend + frontend) was checking certification as a flat currentLevel >= 5, regardless of class. That's wrong under the 93-level framework: each grade owns a different level range (Class 2 → levels 43-61, Class 3 → 62-75, Class 4 → 76-93, per FLN_LEVELS_LIST). A Class 4 student at level 60 was being counted as certified for crossing a bar that has nothing to do with their grade's actual ceiling.

Changes

  • backend/src/certification.ts (new) — source of truth. getDistanceToCertification(classGroup, currentLevel) returns levels remaining (0 = certified, null = unrecognized grade). CLASS_CERTIFICATION_LEVEL map: Class 2→61, Class 3→75, Class 4→93 (only these three are enrolled today per seed.ts).
  • GET /api/students now returns certificationDistance per student.
  • GET /api/stats and GET /api/analytics(/superadmin) certification counts/rates switched from the flat Mongo $gte: 5 match to a grade-aware $or.
  • Frontend: mirrored as CLASS_CERTIFICATION_LEVEL/isCertified() next to FLN_LEVELS_LIST (the actual source of the class→level-range mapping) in RoleDashboards.tsx; all 7 other currentLevel >= 5 call sites across RoleDashboards.tsx/PanelViews.tsx updated to use it.

Test plan

  • tsc --noEmit clean on both workspaces
  • Verified the Mongo aggregation against a scratch collection: 4 students across Class 2/Class 4, correctly counted 2 certified (the two at their own grade's ceiling — not the two that were merely above the old flat threshold of 5)
  • Would like a second pass from Lakshya/core team on the certification-level boundaries themselves (61/75/93) before this goes to production data, since it changes reported certification rates platform-wide

Certification was checked everywhere (backend + frontend, 9 call sites) as
a flat currentLevel >= 5 threshold, regardless of grade. That's wrong: the
93-level framework assigns different level ranges per class (Class 2 ends
at level 61, Class 3 at 75, Class 4 at 93 - see FLN_LEVELS_LIST), so a
Class 4 student at level 60 was being counted as "certified" for having
crossed a flat bar meant for nothing in particular.

backend/src/certification.ts is the source of truth: getDistanceToCertification
returns how many levels remain until a student's grade-appropriate ceiling
(0 = certified, null = classGroup not a recognized enrolled grade). Mirrored
on the frontend as CLASS_CERTIFICATION_LEVEL/isCertified next to
FLN_LEVELS_LIST since that's where the class->level-range mapping actually
lives.

Wired in:
- GET /api/students now returns certificationDistance per student
- GET /api/stats and GET /api/analytics(/superadmin) certification
  counts/rates now use the grade-relative check instead of the flat one
- All 7 frontend call sites in RoleDashboards.tsx/PanelViews.tsx doing
  their own currentLevel >= 5 math updated to isCertified()

Verified: tsc --noEmit clean on both workspaces; aggregation logic checked
against a scratch MongoDB collection (4 students across Class 2/4, correctly
counted 2 certified - the two at their grade's ceiling, not the two merely
above the old flat threshold of 5).
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