简体   繁体   English

如何使用Fivestar计算用户在其所有节点上的平均评分?

[英]How to calculate the user's average rating on all his/her nodes with Fivestar?

On my website, users can rate each other's nodes via a Fivestar field called Stars in a comment. 在我的网站上,用户可以通过在评论中名为Stars的Fivestar字段对彼此的节点进行评分。 I'd now like to calculate the overall average score of a user. 我现在要计算用户的总体平均得分。 That means, I'd like to display the user's average score for all his/her nodes. 这意味着,我想显示用户在他/她所有节点上的平均得分。

For example. 例如。 Let's say a user created 2 nodes: Node 1 and Node 2 . 假设一个用户创建了2个节点: Node 1Node 2 Some people rated his content: 有人评价他的内容:

  • Scores of Node 1 : 4/5, 5/5, 3/5 节点1的分数:4 / 5、5 / 5、3 / 5
  • Scores of Node 2 : 4/5, 4/5 节点2的分数:4 / 5、4 / 5

The overall average would then be (4+5+3+4+4)/5=4. 这样,总体平均值将为(4 + 5 + 3 + 4 + 4)/ 5 = 4。

Preferably, this result should also be displayed as stars. 优选地,该结果也应该显示为星星。

How can I do that? 我怎样才能做到这一点?


Edit: Working with the Computed Field module seems to be a general idea to solve this matter. 编辑:使用计算字段模块似乎是解决此问题的一般想法。 It looks fine to me and I think it's best to store the users' average score in a user field, in order to make it easily accessable. 在我看来,这很好,我认为最好将用户的平均得分存储在用户字段中,以使其易于访问。 (Working with a view is also fine.) I'm planning to display the average score on their profile page, but perhaps I'm going to use it elsewhere on the website in the future too. (使用视图也可以。)我计划在他们的个人资料页面上显示平均得分,但也许将来我也会在网站上的其他地方使用它。

Can you please help me with (a scetch) of the code I'm supposed to use? 您能(帮助)我应该使用的代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM