fix: clamp period deltas at 0 in processTimeframe to prevent negative…#252
Open
Tamcodes4 wants to merge 1 commit into
Open
fix: clamp period deltas at 0 in processTimeframe to prevent negative…#252Tamcodes4 wants to merge 1 commit into
Tamcodes4 wants to merge 1 commit into
Conversation
Contributor
|
Thank you for submitting a pull request. Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully. Formatting and Branching
|
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.
Description
This PR fixes an issue where the daily, weekly, and monthly leaderboards could display negative solved counts and negative scores when a user's cumulative totals temporarily decreased (for example, due to an inconsistent API response).
processTimeframe()inscripts/sync-leaderboard.jspreviously calculated period deltas using direct subtraction, which could produce negative values. This change clamps the solved counts to a minimum of0usingMath.max(0, ...)before recalculating the derivedscoreandtotalSolvedvalues.Linked Issue
Fixes #238
Changes Made
Replaced direct subtraction with
Math.max(0, current - previous)for:easySolvedmediumSolvedhardSolvedLeft the existing
scoreandtotalSolvedcalculations unchanged so they automatically derive from the clamped values.Preserved the existing calculation flow while preventing invalid negative values from propagating to the leaderboard.
Type of Change
Testing
Manual Verification
Verified the logic using a scenario where a user's previous cumulative snapshot exceeded the current snapshot. Confirmed that:
easySolved,mediumSolved, andhardSolvedare clamped to0instead of becoming negative.scoreis recalculated from the clamped values and never becomes negative.totalSolvedis derived from the corrected solved counts and remains non-negative.No automated tests were added since this repository does not currently include a test suite for the leaderboard sync scripts.
Checklist
npx prettier --write .before submittingfeature/*branch, not themainbranchScreenshots / Screen Recording
N/A – Backend data-processing change only. No UI or visual changes.