TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 373
  • Total: 374
  • @rjen

Rating average

Started by FragaCampos, September 02, 2009, 03:09:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FragaCampos

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

IchBin

#1
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.

FragaCampos

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  ;)


JPDeni

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.

IchBin

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.

FragaCampos

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?


JPDeni

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


FragaCampos

Ok, thank you very much  :up:
Topic solved.

This website is proudly hosted on Crocweb Cloud Website Hosting.