Skip to content

Instantly share code, notes, and snippets.

@goncalossilva
Created July 30, 2011 18:58
Show Gist options
  • Select an option

  • Save goncalossilva/1115856 to your computer and use it in GitHub Desktop.

Select an option

Save goncalossilva/1115856 to your computer and use it in GitHub Desktop.
Codebits talk proposals rank
require 'rubygems'
require 'json'
require 'net/http'
require 'statistics2'
# from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
def ci_lower_bound(pos, n, power)
return 0 if n == 0
z = Statistics2.pnormaldist(1-power/2)
phat = 1.0*pos/n
(phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end
url = "http://services.sapo.pt/Codebits/calltalks"
response = Net::HTTP.get_response(URI.parse(url))
results = JSON.parse(response.body)
results.each do |result|
result["score"] = ci_lower_bound(result["up"].to_i, result["up"].to_i+result["down"].to_i, 0.05)
result["up"].to_f/result["down"].to_f
end
results.sort! { |a,b| b["score"] <=> a["score"] }
results.each_with_index do |result, index|
puts "##{index+1}"
puts "Title: #{result["title"]}"
puts "Votes: #{result["up"]} - #{result["down"]}"
puts "Score: #{result["score"]}"
puts
end
@nunopolonia

Copy link
Copy Markdown

@goncalossilva you can give weights to the upvotes according to the downvotes.

If 0 < n downvotes < 25 then n upvotes * 1 end

if 25 < n downvotes < 50 then n upvotes * 0.9 end

Then it's a question of fine tuning this weights

@goncalossilva

Copy link
Copy Markdown
Author

Yeah, I think I'll do something like that... I was waiting for someone to provide me with an already reliable ranking system :)

@nunopolonia

Copy link
Copy Markdown

Apparently what you want is the lower bound of Wilson score confidence interval for a Bernoulli parameter :D

There you go my friend http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

@goncalossilva

Copy link
Copy Markdown
Author

Now that's what I'm talking about! I've seen that before... I think it had something to do with @paulozoom's MSc thesis. Oh well, time for some coding. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment