Skip to content

Instantly share code, notes, and snippets.

@natew
Created Oct 16, 2012
Embed
What would you like to do?
Reddit ranking algorithm in rails
# Ranking algorithm
def set_rank
find_id = matching_id || id
shared_song = Song.find(find_id) if find_id
if shared_song
favs_count = shared_song.user_broadcasts_count
time_created = shared_song.created_at
else
favs_count = 1
time_created = created_at
end
favs = [Math.log(favs_count * 10), 0].max
time = (time_created - Time.new(2012)) / 100000
self.rank = favs + time
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment