Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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