Skip to content

Instantly share code, notes, and snippets.

@darrenterhune
Created October 3, 2011 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenterhune/1260482 to your computer and use it in GitHub Desktop.
Save darrenterhune/1260482 to your computer and use it in GitHub Desktop.
ranking algorithm in mysql
# I hate this... it's fugly:
order("CEIL((artworks.votes + POW(subscriptions.amount, 2)) / POW(((DATEDIFF(CURDATE(), artworks.created_at)) + 1), 1.5))")
# Would love to be able to do something similar to this (although I like typing *POW!*):
order(((artworks.votes + subscriptions.amount)**2) / (((Time.parse(DateTime.now.to_s) - Time.parse(created_at.to_s) + 1) / 86400).round + 1)^1.5)
# Code could have some boo boos init... this is just as an example fyi
# Just for the record, the data set is large so I can't use ruby sort_by, select, collect, map etc... the ordering needs to be on the mysql level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment