Skip to content

Instantly share code, notes, and snippets.

@natew
Created October 16, 2012 06:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natew/3897513 to your computer and use it in GitHub Desktop.
Save natew/3897513 to your computer and use it in GitHub Desktop.
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