The anonymous visitors and registered users on my website can rate nodes through a comment with a Fivestar field. I display the average rating on the node's page. While testing this mechanism, I found out that the average isn't calculated correctly when multiple anonymous users vote with a comment. I suspect that only the last vote of a certain uid is taken into account: since all anonymous users have a uid equal to 0 - even if their name in the comment is different - they are considered as the same person.
In order to solve this problem, I did some research to how Fivestar calculates averages. All comments and corresponding votes of anonymous users are stored seperately in the database, so I can certainly use all the available information. I think that I also located the function in fivestar.module
(lines 45-59) that calculates the average:
function fivestar_microdata_suggestions() {
$mappings = array();
// Add the review mapping for Schema.org
$mappings['fields']['fivestar']['schema.org'] = array(
'#itemprop' => array('aggregateRating'),
'#is_item' => TRUE,
'#itemtype' => array('http://schema.org/AggregateRating'),
'average_rating' => array(
'#itemprop' => array('ratingValue'),
),
'rating_count' => array(
'#itemprop' => array('ratingCount'),
),
);
return $mappings;
}
My situation is as follows: I use the average rating of a node in Rules and Views too, so I'm looking for an easy solution. Surely, I expect that I can calculate the correct average with Views or Computed Field, but implementing the usage of this average elsewhere could require quite a lot of adaptations.
Therefore, I would first like to ask you whether you have faced this problem as well. If so, how did you solve it? Is it possible to somehow "overwrite" the way Fivestar calculates averages programatically? I'm not familiar with how one uses schema.org or what information that website provides...