| Author |
Topic |
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-22 : 12:45:31
|
Hii have a table like this:id articleID, userID, rating1 1 1 22 1 2 13 1 3 24 2 1 25 3 2 1 How do I calculate the rating for an article?Is it: 'total rating'/'Number of users' ? Also, how would I get the Top 2 articles from the above table?Thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-22 : 12:55:50
|
| TOP 2 regarding what? Total highest rating?select top 2 q.articleidfrom (select articleid from yourtable group by articleid order by sum(rating)) qYou should rely on Bayesian formula here for somewhat reliable result.Peter LarssonHelsingborg, Sweden |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-22 : 12:58:06
|
| SELECT articleID, avg(rating) ratingFROM tableGROUP BY articleIDLike this if you want fractionsSELECT articleID, avg(cast(rating as decimal(5, 2))) ratingFROM tableGROUP BY articleIDLike this for top 2SELECT TOP 2 articleID, avg(rating) ratingFROM tableGROUP BY articleIDORDER BY rating desc |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-22 : 12:59:38
|
| ORDER BY AVG(Rating) DESCright?Peter LarssonHelsingborg, Sweden |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-22 : 13:14:24
|
quote: Originally posted by Peso ORDER BY AVG(Rating) DESCright?Peter LarssonHelsingborg, Sweden
Yes, although mine is OK because I named the aggregated column rating too. I guess I should have saidSELECT TOP 2 articleID, avg(rating) AvgRatingFROM tableGROUP BY articleIDORDER BY AvgRating desc |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-22 : 17:28:24
|
| Thanks a lot. Even though, I did not explain fully (because I was in a hurry to leave the desk), you guys understood me correctly. |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-23 : 07:11:40
|
quote: Originally posted by snSQLYes, although mine is OK because I named the aggregated column rating too. I guess I should have saidSELECT TOP 2 articleID, avg(rating) AvgRatingFROM tableGROUP BY articleIDORDER BY AvgRating desc
Actually, I need some information again.The above statement can give a very varied result. E.g the average rating of some articles may be 44, and others may be 10, 8, 5.In my system I need to display five stars to indicate the ratings of an article. But if the rating can be 44, 10, 3... How do I know whether to display four stars or three stars...I think I need Bayesian formula to calculate such rating. I did google it, but could not find any information on how to use the Bayesian formula to calculate the ratings.Would be grateful if you help in this regards as well.Regards |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-23 : 07:16:14
|
| [code]The formula for calculating the Top 250 Rated Titles gives a true Bayesian estimate:weighted rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × Cwhere:R = average for the movie (mean) = (Rating) v = number of votes for the movie = (votes)m = minimum votes required to be listed in the Top 250C = the mean vote across the whole report[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-23 : 07:24:14
|
| This formula is not easy to truly understand.Try with this analogy:For a ranking of 1 (which is the highest ranking), the article is awarded 12 pts.For a ranking of 2 (which is the second highest), the article is awarded 10 pts.For a ranking of 3, the article is awarded 8 pts.For a ranking of 4, the article is awarded 7 pts.For a ranking of 5, the article is awarded 6 pts.For a ranking of 6, the article is awarded 5 pts.For a ranking of 7, the article is awarded 4 pts.For a ranking of 8, the article is awarded 3 pts.For a ranking of 9, the article is awarded 2 pts.For a ranking of 10, the article is awarded 1 pts.Now sum up all points for every article and sort them by the sum of pts, descending.Peter LarssonHelsingborg, Sweden |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2006-11-23 : 08:39:50
|
Aha...the "Eurovision" method of scoring!!!!! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-23 : 08:45:23
|
| You noticed! Great!Then I think I explained it simple enough...With the Bayesian estimated, the weighted ranking can never be larger than highest possible score.Peter LarssonHelsingborg, Sweden |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-23 : 09:56:32
|
Hi Peso,I have just tried to implement your fomula. But I am getting a 0 value. Would be greatful if you could have a look at the code:Create PROCEDURE [dbo].[CalculateRatingTest2]@submissionID int,@rating int outputAS-- AvgRating = average for the entry (mean) = (Rating) -- votes = number of votes for the entry = (votes)-- minimum = minimum votes required to be listed -- wholeAvgRating = the mean vote across the whole reportdeclare @avgRating intdeclare @votes intdeclare @minimum intdeclare @wholeAvgRating intSET NOCOUNT ON;BEGIN-- average rating of this entryselect @avgRating = avg(cast(intRating as decimal(5, 2)))from Ratings where submissionID= @submissionID-- number of votes for this itemselect @votes = count(*) from Ratings where submissionID= @submissionIDset @minimum = 1-- average rating of all entriesselect @wholeAvgRating = avg(cast(intRating as decimal(5, 2)))from Ratingsset @rating = (@votes / (@votes+@minimum)) * @avgRating + (@minimum / (@votes+@minimum)) * @wholeAvgRating END Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-23 : 10:00:59
|
| You have declared your Rating as INT. Declare as NUMERIC(9, 4) instead. This applies to all your variables.Peter LarssonHelsingborg, Sweden |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-23 : 10:24:25
|
| Thanks again,Now it seems to be working.I have been working with SQL for sometime, but I am still never sure where to use int, money, numeric....>> minimum votes required to be listed in the Top 250Can I set this value to 1 so all the votes are counted?Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-23 : 11:15:16
|
| Of course. You decide the parameters for your ranking.Peter LarssonHelsingborg, Sweden |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-11-24 : 04:28:57
|
I hope this is last ever question on rating. Does the following formula give the values between 1 - 10 or 1 - 100:weighted rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-24 : 04:31:09
|
| The weighted ranking (wr) will be between 0 and the maximum value for vote that you allow.Peter LarssonHelsingborg, Sweden |
 |
|
|
|