Trendn Blog
How the Trendn ranking algorithm works

A lot of questions come in asking about the ranking of content and transparency of what factors are used in the algorithm. In this post, I’ll try to explain how the Trendn ranking algorithm works and how you can use it in your own application. It is a very simple ranking algorithm and works very well to rank what is trending.

The ranking algorithm looks like this

Score = P / (T+2)^G

Where,
P = points of an item (I will discuss this number next)
T = time since submission (in hours)
G = Gravity, defaults to 1.8

Now to explain..

P = Points of an item: This essentially is the sum of all the social engagement factors. For example, we use the Facebook API to get the amount of likes, shares and comments. Many other factors are used:
Twitter - Tweet Count
Digg - Digg Count, Comment Count
Reddit - Votes, Comment Count
Bookmarks - Delicious, Google Reader
Hacker News - Points, Comments

T = Time since submission: The score decreases as T increases, meaning that older items will get lower and lower scores.

G = Gravity: The score decreases much faster for older items if gravity is increased

Now, to implementation in both Python and PHP.

Python:

def calculate_score(votes, item_hour_age, gravity=1.8):
      return (votes - 1) / pow((item_hour_age+2), gravity)

PHP:

function calculate_score($votes, $item_hour_age, $gravity=1.8) {
    return ($votes - 1) / pow(($item_hour_age+2), $gravity);

}