- π·πΊRussia a_sh
The output of PercentageFormatter and ratingFormatter is totally incorrect.
When I try to use percentage or rating output of fivestar rating it shows erroneous results.
For example, for node with 3 votes and average rating 9.7 it shows percentage rating 90%.
I did check the output of PercentageFormatter.php and it outputs data with votes count=1 (should be 3) and value as shown.The content of Field/FieldFormatter/PercentageFormatter.php in my installation is included. It works as described above. It seems tha aforementioned patch is already included in my installation.
- πΊπΈUnited States tr Cascadia
Please provide steps for reproducing the problem, including details of how you set up your Fivestar field.
For example, for node with 3 votes and average rating 9.7 it shows percentage rating 90%.
I did check the output of PercentageFormatter.php and it outputs data with votes count=1 (should be 3) and value as shown.But if there really is only one vote like it says, perhaps 90% is also correct? Are the 3 votes on different node types, or are they different vote types, etc? I guess maybe you have this configured for 10 stars not 5? If so, do you see the same problems with only 5 stars?
- π·πΊRussia a_sh
As an example.
Node id is 50. It have two vote types with two total votes.
Db content dump is:INSERT INTO `votingapi_vote` (`id`, `type`, `uuid`, `entity_type`, `entity_id`, `value`, `value_type`, `user_id`, `timestamp`, `vote_source`) VALUES
(2248, 'vote', '5ceaf1a2-5566-4991-ac7a-daaf3934402e', 'node', 50, 100, 'percent', 1, 1685946862, 'd832a7497a537224185ea5484e5abda367e403c3b28d14a126a7d39de90a1502'),
(2249, 'tastevote', '4f5048c8-2789-4f5f-bc59-5bf09d6087e0', 'node', 50, 80, 'percent', 1, 1685946862, 'd832a7497a537224185ea5484e5abda367e403c3b28d14a126a7d39de90a1502'),
(2141, 'vote', '8fbcb524-ed70-4325-b52e-3ced5df08ea4', 'node', 50, 100, 'percent', 0, 1684564841, '4743d4ef68c8d8c307eecb571f206949ba40b9b8083fb7f055b2747caf84fbd8'),
(2142, 'tastevote', '4897c131-77f8-49b7-98a2-d3b2fc29ce2e', 'node', 50, 100, 'percent', 0, 1684564841, '4743d4ef68c8d8c307eecb571f206949ba40b9b8083fb7f055b2747caf84fbd8');INSERT INTO `votingapi_result` (`id`, `type`, `entity_type`, `entity_id`, `value`, `value_type`, `function`, `timestamp`) VALUES
(8629, 'vote', 'node', 50, 100, 'percent', 'vote_average', 1685946862),
(8630, 'vote', 'node', 50, 2, 'percent', 'vote_count', 1685946862),
(8631, 'vote', 'node', 50, 200, 'percent', 'vote_sum', 1685946862),
(8632, 'tastevote', 'node', 50, 90, 'percent', 'vote_average', 1685946862),
(8633, 'tastevote', 'node', 50, 2, 'percent', 'vote_count', 1685946862),
(8634, 'tastevote', 'node', 50, 180, 'percent', 'vote_sum', 1685946862);For tastevote:
Stars formatter shows rating 9 of 10 (2 votes), that is correct.
Percentage formatter shows rating 80% - that is incorrect. It is always equal with value of the last vote - I just checked this. If I add vote 4 stars it becomes 40%.Changing number of stars from 10 to 5 do not affect the correctness of Percentage formatter - it is still incorrect.
- π·πΊRussia a_sh
The dump of StarsFormatter.php $elements output
array(1) { [0]=> array(29) { ["#attributes"]=> array(3) { ["class"]=> array(1) @ [0]=> string(15) "fivestar-form-2" ["id"]=> string(7) "vote--2" ["data-drupal-selector"]=> string(15) "fivestar-form-2" } ["vote"]=> array(35) { ["#type"]=> string(8) "fivestar" ["#stars"]=> int(10) ["#allow_clear"]=> bool(false) ["#allow_revote"]=> bool(true) ["#allow_ownvote"]=> bool(true) ["#vote_type"]=> string(4) "vote" ["#widget"]=> array(4) @ ["name"]=> string(6) "oxygen" ["text_format"]=> string(7) "average" ["display_format"]=> string(7) "average" ["fivestar_widget"]=> string(6) "oxygen" ["#default_value"]=> string(2) "60" ["#values"]=> array(3) @ ["vote_sum"]=> string(3) "930" ["vote_count"]=> string(2) "12" ["vote_average"]=> string(4) "77.5" ["#settings"]=> array(4) @ ["name"]=> string(6) "oxygen" ["text_format"]=> string(7) "average" ["display_format"]=> string(7) "average" ["fivestar_widget"]=> string(6) "oxygen" ["#show_static_result"]=> bool(false) ["#attributes"]=> array(2) { ["class"]=> array(1) @ [0]=> string(4) "vote" ["data-drupal-selector"]=> string(9) "edit-vote" } ["#input"]=> boo array ( 0 => array ( '#theme' => 'fivestar_formatter_percentage', '#instance_settings' => array ( 'stars' => 10, 'allow_clear' => false, 'allow_revote' => true, 'allow_ownvote' => true, 'rated_while' => 'viewing', 'enable_voting_target' => false, 'target_bridge_field' => '', 'target_fivestar_field' => '', 'vote_type' => 'tastevote', ), '#item' => array ( 'user' => 1, 'average' => 70, 'count' => 1, ), ), )ratel(true) ["#ajax"]=> NULL ["#process"]=> array(2) { [0]=> array(2) @ [0]=> string(32) "Drupal\fivestar\Element\Fivestar" [1]=> string(7) "process" [1]=> array(2) @ [0]=> string(32) "Drupal\fivestar\Element\Fivestar" [1]=> string(15) "processAjaxForm" } ["#theme_wrappers"]=> array(1) @ [0]=> string(12) "form_element" ["#value_callback"]=> array(2) @ [0]=> string(32) "Drupal\fivestar\Element\Fivestar" [1]=> string(13) "valueCallback" ["#defaults_loaded"]=> bool(true) ["#tree"]=> bool(false) ["#parents"]=> array(1) @ [0]=> string(4) "vote" ["#array_parents"]=> array(1) @ [0]=> string(4) "vote" ["#weight"]=> int(0) ["#processed"]=> bool(true) ["#required"]=> bool(false) ["#title_display"]=> string(6) "before" ["#description_display"]=> string(5) "after" ["#errors"]=> NULL ["#id"]=> string(12) "edit-vote--3" ["#name"]=> string(4) "vote" ["#value"]=> bool(false) ["vote"]=> array(31) { ["#type"]=> string(6) "select" ["#description"]=> array(5) @ ["#average_rating"]=> string(4) "77.5" ["#votes"]=> string(2) "12" ["#theme"]=> string(16) "fivestar_summary" ["#stars"]=> int(10) ["#microdata"]=> NULL
- π·πΊRussia a_sh
The full dump of PercentageFormatter.php $elements output
15 votes with average 5.3 for tastevotearray(1) { [0]=> array(3) { ["#theme"]=> string(29) "fivestar_formatter_percentage" ["#instance_settings"]=> array(9) @ ["stars"]=> int(10) ["allow_clear"]=> bool(false) ["allow_revote"]=> bool(true) ["allow_ownvote"]=> bool(true) ["rated_while"]=> string(7) "viewing" ["enable_voting_target"]=> bool(false) ["target_bridge_field"]=> string(0) "" ["target_fivestar_field"]=> string(0) "" ["vote_type"]=> string(9) "tastevote" ["#item"]=> array(3) @ ["user"]=> int(1) ["average"]=> int(70) ["count"]=> int(1) } }
- π·πΊRussia a_sh
I did check the output of StarsFormatter.
It calls FormBuilder that populates output with correct data, using resultManager->getResultsByVoteType function call.However, in PercentageFormatter this function isn't used........
PercentageFormatter use incorrectly populated $items input for calculations....That's why StarsFormatter produces correct results, unlike PercentageFormatter.
- π·πΊRussia a_sh
The same error is affect sorting of records using views and vote:rating as a sort criteria. Sort is using the last vote only.
- π·πΊRussia a_sh
It seems that problem occur during the population of $elements array. How is it populated by votes data?
- π·πΊRussia a_sh
Here is a related issue:
Make rating average indexable on Search API
cite
"I tried to index a field rating to a Solr Search API index, but the field only contains the last vote."The same as this issue.
- π·πΊRussia a_sh
And one more
Fivestar raiting formatter doesn't show average correctly (3167686)