fix: cap forum post engagement time depreciation with min instead of max - #1037
Open
TowyTowy wants to merge 1 commit into
Open
fix: cap forum post engagement time depreciation with min instead of max#1037TowyTowy wants to merge 1 commit into
TowyTowy wants to merge 1 commit into
Conversation
calculateEngagement applies a time-based depreciation to reddit and hacker-news posts older than depreciatePostsOlderThanHours. The ramp used math.Max(elapsed-threshold, maxDepreciationAfterHours), which is always >= maxDepreciationAfterHours, so the depreciation factor was always >= 1. As a result every post past the 7h threshold was immediately hit with the full maxDepreciation (0.9), defeating the gradual decay, and posts older than threshold+maxDepreciationAfterHours got a factor > 1, producing negative engagement scores. Use math.Min so the factor ramps from 0 to 1 over maxDepreciationAfterHours and is capped there, restoring the intended gradual decay and flooring engagement at 1-maxDepreciation. Co-Authored-By: Claude <noreply@anthropic.com>
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.
The time-based depreciation in
calculateEngagement(used by the Reddit and Hacker News widgets) usesmath.Max(elapsed - depreciatePostsOlderThanHours, maxDepreciationAfterHours). Becausemath.Max(x, maxDepreciationAfterHours)is always ≥maxDepreciationAfterHours, the depreciation factor is always ≥ 1. This means:maxDepreciation(0.9) instead of decaying gradually — there's a cliff at 7h rather than a ramp towardmaxDepreciationAfterHours.depreciatePostsOlderThanHours + maxDepreciationAfterHours(31h) get a factor > 1, producing negative engagement scores.Switching to
math.Mincaps the ramp numerator atmaxDepreciationAfterHours, so the factor rises from 0 to 1 over the intended window and stops there — restoring gradual decay and flooring engagement at1 - maxDepreciation(0.1).Added
TestCalculateEngagementTimeDepreciation, which fails on the current code (8h post → 0.1, 50h post → −0.61) and passes after the fix.go vet/gofmtclean.Prepared with AI assistance (Claude) and reviewed/verified by me.