Method: WRate#rate

Defined in:
lib/w_rate.rb

#rate(sum_rating, votes_count, votes_range = [1, 5], switch_number) ⇒ Object

Your code goes here…



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/w_rate.rb', line 5

def 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