OPUS CODE Articles rating score Calculation
 Lower bound of
Wilson score confidence interval for a Bernoulli parameter
provides a way to sort a product based on positive and negative ratings.  The idea here is to treat the existing set of user ratings as a statistical sampling of a hypothetical set of user ratings from all users and then use this score. In other words, what user community would think about upvoting a product with 95% confidence given that we have an existing rating for this product with a sample (subset from the whole community) user ratings.
 Therefore if we know what a sample population thinks i.e. user reviews for a product, you can use this to estimate the preferences of the whole community.
 If there are
X
positive votes andY
negative votes for an article. We can estimate that with 95% confidence betweenwilson_lower_bound_score
andwilson_upper_bound_score
% of users will upvote this product using the Wilson Score of Confidence interval.
 Wilson Confidence Interval considers binomial distribution for score calculation i.e. it considers only positive and negative ratings. If your product is rated on a 5 scale rating, then we can convert ratings {1–3} into negative and {4,5} to positive rating and can calculate Wilson score.
Python implementation with star rating (with +5 allowance) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
def save(self, *args, **kwargs):
if self.id and (self.thumbs_up.count() or self.thumbs_down.count()):
import math
Z = 1.96
pos, neg = self.thumbs_up.count(), self.thumbs_down.count()
n = pos + neg
phat = pos/n
self.score = ((phat + Z*Z/(2*n)  Z * math.sqrt((phat*(1phat)+Z*Z/(4*n))/n))/(1+Z*Z/n))
star = f'<li class="listinlineitem mr0"><i class="fas fastar orangetext"></i></li>'
half_star = f'<li class="listinlineitem"><i class="fas fastarhalfalt orangetext"></i></li>'
star_score = divmod(math.ceil(self.score*100)+5, 20)
star_score_display = star*star_score[0]
if star_score[1] >= 10 and star_score[0] < 5:
star_score_display += half_star
self.star_score = star_score_display
return super().save(*args, **kwargs)
