Trending: Difference between revisions

(Created page with "Up to: Part Of::Features Trending posts and hashtags to help with content discoverability! == Usage == Go to the [https://neuromatch.social/explore Explore] tab! From there you are given four menus, * Posts * Hashtags * People * News (popular links) == Implementation == Trends are defined in a family of models in <code>mastodon/app/models/trends</code>: https://github.com/NeuromatchAcademy/mastodon/tree/main/app/models/trends Eg. for <code>Statuses</code> th...")
 
 
Line 21: Line 21:


<syntaxhighlight lang="ruby">
<syntaxhighlight lang="ruby">
  def calculate_scores(statuses, at_time)
def calculate_scores(statuses, at_time)
    items = statuses.map do |status|
  items = statuses.map do |status|
      expected  = 1.0
    expected  = 1.0
      observed  = (status.reblogs_count + status.favourites_count).to_f
    observed  = (status.reblogs_count + status.favourites_count).to_f


      score = if expected > observed || observed < options[:threshold]
    score = if expected > observed || observed < options[:threshold]
                0
      0
              else
    else
                ((observed - expected)**2) / expected
      ((observed - expected)**2) / expected
              end
    end


      decaying_score = if score.zero? || !eligible?(status)
    decaying_score = if score.zero? || !eligible?(status)
                        0
      0
                      else
    else
                        score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
      score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
                      end
    end


      [decaying_score, status]
    [decaying_score, status]
    end
  end
</syntaxhighlight>
</syntaxhighlight>


AKA the score is a sum of reblogs and favorites with some exponential time decay.  
AKA the score is a sum of reblogs and favorites with some exponential time decay.


== Config ==
== Config ==