Trending: Difference between revisions

From neuromatch
(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 ==

Latest revision as of 00:56, 15 January 2024

Up to: Features

Trending posts and hashtags to help with content discoverability!

Usage

Go to the 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 mastodon/app/models/trends: https://github.com/NeuromatchAcademy/mastodon/tree/main/app/models/trends

Eg. for Statuses the trending scores are calculated here:

def calculate_scores(statuses, at_time)
  items = statuses.map do |status|
    expected  = 1.0
    observed  = (status.reblogs_count + status.favourites_count).to_f

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

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

    [decaying_score, status]
  end

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

Config

In the Administration > Server Settings > Discovery menu...

Available options:

  • Enable Trends
  • Use trends as the landing page
  • Allow trends without prior review
  • Allow posts with content warnings to trend