fix(attendance): stop double-normalizing confidenceScore in recordAttendance#3866
Open
Srejoye wants to merge 1 commit into
Open
fix(attendance): stop double-normalizing confidenceScore in recordAttendance#3866Srejoye wants to merge 1 commit into
Srejoye wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
POST /api/attendance/recordnormalizesconfidenceScoreto a 0–1 range in the route, then passes that already-normalized value intoAttendanceService.recordAttendance(), which independently divides by 100 again. A raw score of 85 ends up persisted as0.0085instead of0.85in bothattendance_records(Firestore) andattendance(MongoDB), breaking any downstream logic comparing against a 0–1 threshold.The offline sync path (
normalizeConfidenceScoreinapp/api/attendance/sync/route.js) does not have this bug, creating inconsistentconfidenceScoresemantics between online and offline-synced records in the same collections.Fix
Establish a single normalization boundary at the route layer:
parsedConfidence / 100) and now passes the result asnormalizedConfidenceScore— an explicit name documenting the expected scale.AttendanceService.recordAttendance()no longer re-divides; it consumesnormalizedConfidenceScoredirectly as the already-correct 0–1 value.Tests
Added
lib/services/__tests__/attendanceService.confidence.test.js:confidenceScorein both the Firestore transaction write and the MongoDBupdateOnewrite.0.85is persisted (not0.0085) for an already-normalized input.Existing
app/api/attendance/record/route.test.jsassertions (confidenceScore: 0.75,0.8) now pass against the real (unmocked) service.Closes #3801