Skip to content

fix(attendance): stop double-normalizing confidenceScore in recordAttendance#3866

Open
Srejoye wants to merge 1 commit into
Premshaw23:masterfrom
Srejoye:fix/attendance-confidence-double-normalization
Open

fix(attendance): stop double-normalizing confidenceScore in recordAttendance#3866
Srejoye wants to merge 1 commit into
Premshaw23:masterfrom
Srejoye:fix/attendance-confidence-double-normalization

Conversation

@Srejoye

@Srejoye Srejoye commented Jun 26, 2026

Copy link
Copy Markdown

Problem

POST /api/attendance/record normalizes confidenceScore to a 0–1 range in the route, then passes that already-normalized value into AttendanceService.recordAttendance(), which independently divides by 100 again. A raw score of 85 ends up persisted as 0.0085 instead of 0.85 in both attendance_records (Firestore) and attendance (MongoDB), breaking any downstream logic comparing against a 0–1 threshold.

The offline sync path (normalizeConfidenceScore in app/api/attendance/sync/route.js) does not have this bug, creating inconsistent confidenceScore semantics between online and offline-synced records in the same collections.

Fix

Establish a single normalization boundary at the route layer:

  • Route continues to normalize once (parsedConfidence / 100) and now passes the result as normalizedConfidenceScore — an explicit name documenting the expected scale.
  • AttendanceService.recordAttendance() no longer re-divides; it consumes normalizedConfidenceScore directly as the already-correct 0–1 value.

Tests

Added lib/services/__tests__/attendanceService.confidence.test.js:

  • Parametrized cases for raw scores 60, 85, 100 → asserts persisted confidenceScore in both the Firestore transaction write and the MongoDB updateOne write.
  • An explicit regression test asserting 0.85 is persisted (not 0.0085) for an already-normalized input.

Existing app/api/attendance/record/route.test.js assertions (confidenceScore: 0.75, 0.8) now pass against the real (unmocked) service.

Closes #3801

…endance

Route already normalizes confidenceScore to 0-1 before calling AttendanceService.recordAttendance(), but the service independently divided it by 100 again, persisting values like 0.0085 instead of 0.85 to both Firestore and MongoDB.

Establish a single normalization boundary at the route layer: rename the field passed to the service to normalizedConfidenceScore so the contract is explicit, and remove the redundant /100 in the service.

Add parametrized regression tests covering boundary values (60, 85, 100) and an explicit guard against the double-divide.
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.

[Bug] : Confidence score is divided by 100 twice, corrupting attendance confidence values

1 participant