Skip to content

Instantly share code, notes, and snippets.

@xwmx
Forked from xdite/topic.rb
Created June 27, 2011 00:18
Show Gist options
  • Save xwmx/1048120 to your computer and use it in GitHub Desktop.
Save xwmx/1048120 to your computer and use it in GitHub Desktop.
before_update :update_ranking
def self.calculate_ranking(score, created_at)
order = Math.log10(([score.abs,1].max))
if score > 0
sign = 1
elsif score < 0
sign = -1
else
sign = 0
end
seconds = created_at - DateTime.new(1970,1,1)
long_num = order + sign * seconds / 45000
(long_num * 10**7).round.to_f / (10**7)
end
def update_ranking
self.ranking = Topic.calculate_ranking(self.pushes_count, self.created_at)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment