数学任务,将10星评级转换为向上和向下

时间:2014-11-07 02:41:06

标签: php wordpress math

我想将我的文章评级脚本从10星评级(gdsr)改为up和downvotes(如youtube)。

但我不想放弃目前的评级,所以我的想法是将当前(10星gdStarRating)转换为上下投票。

我的问题是数学公式...我不明白。

例如

10 members has voted, the rating is 9
= 9 upvotes and 1 downvote

另一个例子

18 member has voted, the rating is 9.6
=  ?? upvotes and ?? downvotes

15 member has voted, the rating is 8.8
=  ?? upvotes and ?? downvotes

什么是正确的(PHP)数学公式?

1 个答案:

答案 0 :(得分:2)

将评分比率乘以总票数,以获得与您当前投票/ 10比率最接近的上/下比率

即。

18 member has voted, the rating is 9.6
=  ?? upvotes and ?? downvotes

等级9.6转换为96%的赞成票,18 * 96%= 17.23 => 17票1票下来投票

15 member has voted, the rating is 8.8
=  ?? upvotes and ?? downvotes

8.8的评级转换为88%的赞成票,15 * 88%= 13.2 => 13票2票下来

PHP示例

$totalvotes = 18;
$rating = 9.6;
$upvotes = round($totalvotes * ($rating/10));
$downvotes = $totalvotes - $upvotes;