module WRate
Constants
- VERSION
Public Class Methods
rate(sum_rating, votes_count, votes_range = [1, 5], switch_number)
click to toggle source
Your code goes hereā¦
# File lib/w_rate.rb, line 5 def self.rate(sum_rating, votes_count, votes_range = [1, 5], switch_number) z = 1.6 v_min = votes_range.min v_width = (votes_range.max - v_min).to_f phat = (sum_rating - votes_count.to_f * v_min) / v_width / votes_count.to_f if votes_count < switch_number rating=(phat+(z*z)/(2*votes_count)+z*Math.sqrt((phat*(1-phat)+(z*z)/(4*votes_count))/votes_count))/(1+(z*z)/votes_count) else rating = (phat+(z*z)/(2*votes_count)-z*Math.sqrt((phat*(1-phat)+(z*z)/(4*votes_count))/votes_count))/(1+(z*z)/votes_count) end return rating * v_width + v_min end