Skip to content

fix: cap forum post engagement time depreciation with min instead of max - #1037

Open
TowyTowy wants to merge 1 commit into
glanceapp:devfrom
TowyTowy:fix/forum-post-time-depreciation-dev
Open

fix: cap forum post engagement time depreciation with min instead of max#1037
TowyTowy wants to merge 1 commit into
glanceapp:devfrom
TowyTowy:fix/forum-post-time-depreciation-dev

Conversation

@TowyTowy

Copy link
Copy Markdown

The time-based depreciation in calculateEngagement (used by the Reddit and Hacker News widgets) uses math.Max(elapsed - depreciatePostsOlderThanHours, maxDepreciationAfterHours). Because math.Max(x, maxDepreciationAfterHours) is always ≥ maxDepreciationAfterHours, the depreciation factor is always ≥ 1. This means:

  • Every post older than the 7h threshold is immediately hit with the full maxDepreciation (0.9) instead of decaying gradually — there's a cliff at 7h rather than a ramp toward maxDepreciationAfterHours.
  • Posts older than depreciatePostsOlderThanHours + maxDepreciationAfterHours (31h) get a factor > 1, producing negative engagement scores.

Switching to math.Min caps the ramp numerator at maxDepreciationAfterHours, so the factor rises from 0 to 1 over the intended window and stops there — restoring gradual decay and flooring engagement at 1 - 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 / gofmt clean.

Prepared with AI assistance (Claude) and reviewed/verified by me.

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>
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