# Generating a rating between 1 to 5 accounting for number of users who have rated

I need a rating system for my app, what happens is that a user can rate a thread 1 to 5. The calculation I was going to use was shown below.

$$\begin{array}{llll} \text{ID}&\text{UID}&\text{TID}&\text{Rating}\\ \hline 1&1&37&5\\ 2&4&37&5\\ 3&8&37&5\\ 4&22&37&5\\ 5&2&37&5\\ \end{array}$$

This is a sample table, as you can see the way I did it was:

$$r_1\qquad\quad r_2\qquad\quad r_3\qquad\quad r_4\qquad\quad r_5\quad\\ \frac{(0\times1)+(0\times2)+(0\times3)+(0\times4)+(0\times5)}5=5$$

There is no user (UID) with a rating of $1$ ($r_1$) so you set $r_1 = (0 \times 1)$ but there are users (UID) with a rating of $5$ ($r_5$) so you set $r_5 = (5 \times 5)$ and the rest $r_2, r_3, r_4$ are set to $0$ as there are no ratings for those.

I get a rating of 5 stars.

But my problem is if 100 different users all rate the thread 5 you will get a rating of 5 using the formula given, also if 5 different users rated another thread 5 you would get a rating of 5 also. But I don't want these results as both ratings for each thread will hit the top. I know I could select in SQL to order the threads by number of users who have rated the thread so the 100 different users will go top this works, but the threads that had 5 users who rated 5 will be second.

Is there another way to rate theses threads taking into account how many users have rated each thread?

• 1. Choose a number of users that you want to rate each thread. I'll pick 10 for this illustration. 2. Calculate the average rating as you have done in your question. Call that number R. 3. Count the number of ratings. Call that A. 4. Calculate $RA/10$. 5. If $RA/10 \leq 5$, then $RA/10$ is the final score. If $RA/10 >5$, then 5 is the final score. Jun 27, 2015 at 14:09