TinyPortal

Development => Support => Topic started by: FragaCampos on September 02, 2009, 03:09:28 AM

Title: Rating average
Post by: FragaCampos on September 02, 2009, 03:09:28 AM
Hi TP people :)

Today I was checking my articles' ratings and i notice that there's something wrong with average rating... for example:
In one of the articles i have 3 ratings (5,4,5) and the average is 4?  :o
Is this right?

Link to my site: http://www.docspt.com
SMF version: SMF ver. 1.1.10
TP version: TP ver. 1.0 beta 4
Theme name and version: NewDef
Title: Re: Rating average
Post by: IchBin on September 02, 2009, 05:36:59 AM
TinyPortal isn't going to give you a 4.5 rating. It only gives whole numbers, which IMO is better to round down to the nearest number and not up. Here is where the code does that in the TPortal.php file.

$rating_average=floor($total/$rating_votes);

So if you take the $total(14) divided by $rating_votes(3) it equals 4.6...

Then you "floor" that number to a whole number which is 4. Make sense? Would you rather it say you got a perfect 5 when someon has not voted as a 5? If so, just change floor to ceil in that code.
Title: Re: Rating average
Post by: FragaCampos on September 02, 2009, 03:31:46 PM
Thanks for the answer IchBinâ„¢ and the solution.

Still, i can't avoid saying this: an average of integers is rounded to the nearest integer. At least that's how it works here in Portugal (and that's how i learned in school  ::)))
So in your example an average of 4,66 is 5, not 4. At least as as i see it  ;)

Title: Re: Rating average
Post by: JPDeni on September 02, 2009, 04:40:42 PM
Quotean average of integers is rounded to the nearest integer.
Right. And there are several different functions in php which round numbers. The way that it's done in TP is to use the "floor" function, which rounds to the next lower integer. There is also the "ceil" function which rounds to the next higher integer. And then there's the "round" function which rounds to the closest integer, whether it's higher or lower. You can use whichever one you prefer.
Title: Re: Rating average
Post by: IchBin on September 02, 2009, 04:59:06 PM
Quote from: FragaCampos on September 02, 2009, 03:31:46 PM
Thanks for the answer IchBinâ„¢ and the solution.

Still, i can't avoid saying this: an average of integers is rounded to the nearest integer. At least that's how it works here in Portugal (and that's how i learned in school  ::)))
So in your example an average of 4,66 is 5, not 4. At least as as i see it  ;)



So if you have 4 people vote on an article 4,4,5,5. The average of this rating is 4.5. So round it up to 5 (as you prefer). So, you now have an article that shows its rating is 5. But half of these people know they voted 4. Does that seem like a good average for those that didn't think the article was perfect? I understand how rounding up goes, and how we were all taught. But using rounding up in a ratings system does not make sense to me.
Title: Re: Rating average
Post by: FragaCampos on September 02, 2009, 05:21:43 PM
Thanks JPDeni. I'll use the the round function which i believe it's more "just".

IchBinâ„¢, i really understand your point of view, but the argument you present is valid both ways. Your refer to an extreme situation (the middle one of 4.5), but when the average is 4.7 or 4.6, i don't see how fair is it to those who voted 5 to see an average of 4.
Honestly, I really don't give much importance to article ratings, since in my portal they are just a "call to view", but i like to see things working in a "just" way  (as i see it) :)

Btw, JPDeni, how does that round function works in case of the 4.5 scenario?

Title: Re: Rating average
Post by: JPDeni on September 02, 2009, 05:23:14 PM
QuoteBtw, JPDeni, how does that round function works in case of the 4.5 scenario?

It rounds up, according to the page about the function -- http://www.php.net/round



echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4

Title: Re: Rating average
Post by: FragaCampos on September 02, 2009, 11:14:45 PM
Ok, thank you very much  :up:
Topic solved.