Files
fizzy/test/models/bubble/scorable_test.rb
T
Kevin McConnell 16a80ff3a6 More dynamic activity scores
This introduces a more dynamic system of activity scoring, to improve
the way bubbles "bubble up" due to their activity. There are a few
different parts we can tune here, and it's likely we'll need to make
adjustments once we get a feel for how this works in practice.

The basic idea here is:

- We assign points for certain types of event that happen on a bubble. A
  boost gets 1 point, a comment gets 10 points, and so on.
- These points decay over time, at a rate of 50% per day. So old
  activity is worth much less than new activity. Bubbles should rise up
  quickly when acted upon, bit will float back down if left idle.
- Some comments can score higher than others: the first comment from
  each person on a bubble is worth more (20) because it signals that
  more people are getting involved; and comments that follow a comment
  by a different author are also worth more (15) because that signals
  there's ongoing conversation between people, not just a series of
  notes being left by one individual.

In terms of implementation, we persist the score on the bubble
whenever it changes, but we handle the decay on the client side. That
allows us to cache the bubble representation without having to
continually change it while its activity decays.

We also keep a separate `activity_score_order` attribute on the model.
This can be used to sort the bubbles in order of "most active", without
having to think about the decay.
2025-03-05 17:16:31 +00:00

57 lines
1.6 KiB
Ruby

require "test_helper"
class Bubble::ScorableTest < ActiveSupport::TestCase
test "a bubble has a score that increases with activity" do
bubble = bubbles(:logo)
score = bubble.activity_score
assert_operator score, :>, 0
with_current_user :kevin do
bubble.capture Comment.create(body: "This is exciting!")
end
assert_operator bubble.activity_score, :>, score
end
test "commenting on a bubble boosts its score more than boosting it" do
bubble = bubbles(:logo)
bubble.rescore
comment_change = capture_change -> { bubble.activity_score } do
with_current_user :kevin do
bubble.capture Comment.create(body: "This is exciting!")
end
end
boost_change = capture_change -> { bubble.activity_score } do
with_current_user :kevin do
bubble.boost!
end
end
assert_operator comment_change, :>, boost_change
end
test "recent activity counts more than older activity in the ordering" do
with_current_user :kevin do
travel_to 5.days.ago
bubble_old = buckets(:writebook).bubbles.create! status: :published, title: "old"
bubble_mid = buckets(:writebook).bubbles.create! status: :published, title: "mid"
bubble_new = buckets(:writebook).bubbles.create! status: :published, title: "new"
bubble_old.boost!
bubble_old.boost!
travel_back
travel_to 2.days.ago
bubble_mid.boost!
travel_back
bubble_new.boost!
assert_equal [ bubble_new, bubble_mid, bubble_old ], Bubble.where(id: [ bubble_old, bubble_mid, bubble_new ]).ordered_by_activity
end
end
end