I am trying to add a randomized number to my Wilson Score select statement.
My Post model has columns 'upvotes_count' and 'downvotes_count' that get incremented and decremented according to how many upvotes and downvotes they have (duh..).
Post.select("((upvotes_count + 1 + 1.9208) / (upvotes_count + downvotes_count + 2) - " +
"1.96 * SQRT(((upvotes_count + 1) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " +
"(upvotes_count + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + downvotes_count + 2)) " +
"AS ci_lower_bound, posts.*")
.order("ci_lower_bound DESC")
Note: In theory, Wilson Score doesn't allow for cases where both upvotes_count and downvotes_count equal 0, so I cheat and add upvote and downvote to each post record. I know this is mathematical "blasphemy" so please don't hurt me math gods. Otherwise, I wouldn't get post records with zero upvotes and zero downvotes...and that sucks.
What would be ideal is to have a select statement that would add a different random number (Poisson preferably) to upvotes_count of each post to give an artificial bump to it's Wilson score so it would occasionally appear higher on the list.
Question: How do I add a different random number to upvotes_count for each post selected in my select statement?
Something like this...but obviously it doesn't work...
Post.select("((upvotes_count + 1 + random + 1.9208) / (upvotes_count + downvotes_count + 2) - " +
"1.96 * SQRT(((upvotes_count + 1 + random) * (downvotes_count + 1)) / (upvotes_count + downvotes_count + 2) + 0.9604) / " +
"(upvotes_count + random + downvotes_count + 2)) / (1 + 3.8416 / (upvotes_count + random + downvotes_count + 2)) " +
"AS ci_lower_bound, posts.*")
Aucun commentaire:
Enregistrer un commentaire