Created
October 3, 2011 22:57
-
-
Save darrenterhune/1260482 to your computer and use it in GitHub Desktop.
ranking algorithm in mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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