Skip to content

Instantly share code, notes, and snippets.

@abdul-shajin
Last active December 18, 2015 08:29
Show Gist options
  • Save abdul-shajin/5754851 to your computer and use it in GitHub Desktop.
Save abdul-shajin/5754851 to your computer and use it in GitHub Desktop.
Rank Links according to number of parameters
Upvote number
Comments recieved for a link
Share count
user rank
Recency
Follower count of category (eg: gaming)
Visiter - Upvote ratio (later)
The equation which I used to find rank is
points*2 + log(comment_weight)*2 +log(share_count) + (log(user_weight) +log(category_weight))/5
_______________________________________________________________________________
log(age)**2
This will return a fraction value mostly between 0 to 100 and will assign to each post (links)
incude Math
class Rank
attr_accessor :link
def initialize(link)
@link = link
end
#where ranking occurs
def rank_link
((points*2) + (log(comment_weight)*2) + log(share_count) + (log(user_weight) + log(category_weight))/5 )/log(age)**2
end
private
#Return points
def points
@link.ups - @link.down
end
#Comment
def comment_weight
@link.comments.count
end
#To get epoch seconds of created at - Recency matters
def epoch_second
@link.created_at.to_i
end
def age
Time.now.to_i - epoch_second
end
def share_count
@link.shares.count
end
#Assume user have a ranking system which results weight
#More post count, Most upvoted post, Most commented post means most weighted user
def user_weight
@link.user.weight_score
end
#Each link is belongs to a category
#Category has weight according to number of users following.
def category_weight
@link.category.weight_score
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment