I have an array of dictionaries. Each dictionary holds data about an individual audio track. My app uses a star rating system so users can rate track 1-5 stars. Each dictionary has its own rating data per track, as follows:
avgRating(ex: 4.6)rating_5_count(integer representing how many 5-star ratings a track received)rating_4_countrating_3_countrating_2_countrating_1_count
I’m trying to create a Top Charts table in my app. I’m creating a new array with objects sorted by avgRating. I understand how to sort the objects using NSSortDescriptors, but here is where I’m running into trouble…
If I only use avgRating as a sort descriptor, then if a track only receives one 5-star rating, it will jump to the top of the charts and beat out a track that might have a 4.9 with hundreds of votes.
I could set a minimum vote count to prevent this in the Top Charts array, but I would rather not do this. I would then have to change the min vote count as I get more users.
This is a bit subjective, but does anyone have any other suggestions on how to effectively sort the array?
There is many ways to deal with such a situation.
One approach could be to consider the number of votes as a measure of the confidence in the rating average. Starts with an average set at 3 (per example).
Now sort your array based on
confidenceRatinginstead ofaverageRating.You can tweak the algorithm above by changing how many votes are needed so confidenceRating equals averageRating, and of course, you can change the function I used in the example. square root could work as well, or why not a linear progression. Your call.
This is just an example of course, a pretty dumb one. The standard deviation of the votes may add some intelligence in the algorithm, taking not only the number of votes into account but also the distribution of votes. 100 votes on 100 at 5 have more ‘confidence’ than 1000 votes scattered randomly between 0 and 5. Methink.