I'm trying to find a solution for displaying the average votes of multi-axis votes via views. I need this information to sort my nodes by overall average votes.

For example, given voting scores like below:

First axis: Quality - 60%
Second axis: Value - 50%
Third axis: Reliability - 90%

I'd like to get the overall average of above as = (60+50+90)/3 = 66.67%

I was able to show the average on node page by using this code:

$overall_score = (($quality_rating[0]['value'])+($value_rating[0]['value'])+($reliability_rating[0]['value']))/3;
print theme('fivestar_static', $overall_score, '5'); in page.tpl.php

What is the best way to achieve getting this information in views? Is there a way I can store it in the CCK for each node? I'd also like to be able to search for the overall rating in the database.

Any help would me much appreciated!

Comments

HelloStephanie’s picture

Title: Displaying mult-axis average of all votes in Views » Displaying multi-axis average of all votes in Views
IWasBornToWin’s picture

Priority: Normal » Major

Wow, everywhere I look for the solution to this question I see old, unanswered questions. Is this module maintained? I need the answer to this question also.

JCB’s picture

Hi Guys,

I have not tried it myself; so this is just pure speculation:

1. Install Computed Field

2. Create a cck field which uses the Computed Field.

3. Place calculations in the Computed Field's configuration
Example can be found here (see #14)
https://drupal.org/node/335493

It will probably look something like below.

<?php
$average = ($node->field_axis_a[0]['rating'] + $node->field_axis_b[0]['rating'] + $node->field_axis_c[0]['rating'] + $node->field_axis_d[0]['rating']) / 4;
$node_field[0]['value'] = $average;
?>

4. Install Module Views Custom Field

5. Create a view
add a "Custom PHP" field provided by "Views Custom Field" and enter something like this (where '5' will be your views custom field's value):

<?php
$display = theme('fivestar_static', $node_field_item['value'], '5');
?>

If you want to go further to get the overall rating for all average counts.
6. Install Views Calc

7. Calculate the average of a view by using the "Views Calc" module

8. You can now insert the average of the average on a node by embedding a view to a node by printing it to a template file such as node.tpl.php (this is usually tricky and involves a lot of patience)
See this thread for instructions on embedding a view:
https://drupal.org/node/719330

Let me know if this solved your problem :-)

whiteph’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)