Install instructions
Simply download the project and place all modules within the /modules subdirectory.
Please make sure that you have downloaded BOTH VotingAPI and some voting module (for example: SimpleVote)
And then turn them on!
To use SimpleVote on comments
Add this function to SimpleVote.module
<?php
function simplevote_comment(&$comment, $op) {
switch ($op) {
case 'view':
$comment->comment = theme('simplevote_widget', $comment->cid, 'comment') . $comment->comment;
break;
}
}
?>To install over existing VotingAPI data please make sure cron runs are enabled. As existing voting data is processed via cron.
user_recommendation.module
Not your standard recommendation module no! It recommends users
So the general idea, to recommend a user because you might like what that user likes.
Alogrithm
First we want the difference between the averages of the current user and all other users.
SELECT a.uid as 'current_user', a2.uid as 'sugguested_user', a.sum/a.count as 'current_average', a2.sum/a2.count as
'sugguested_average',ABS((a.sum/a.count)-(a2.sum/a2.count)) as 'avg_diff' FROM cre_average_vote a, cre_average_vote a2 WHERE
a.uid <> a2.uid AND a.uid=2 ORDER BY avg_diff;
Next, we want to use a count of votes that were cast for the same piece of content to weight the 'avg_diff' between the two users
SELECT COUNT(*) FROM votingapi_vote r, votingapi_vote r2 WHERE r.uid = 2 AND r2.uid = 3 AND abs( r.value-r2.value) <= 20;
Here I used a difference of 20 percentage points. This difference is what determines what votes are revelant. Any vote that is on the same piece of content BUT the difference between user1's vote and user2's vote is MORE THAN 20, it doesnt get counted.
So combining those two sql statements into one HUGE SQL statement
SELECT COUNT() as 'count', a.uid as 'current_user', a2.uid as 'sugguested_user', a.sum/a.count as 'current_average',a2.sum/a2.count
as 'sugguested_average',ABS((a.sum/a.count)-(a2.sum/a2.count)) as 'avg_diff',ABS((a.sum/a.count)-( a2.sum/a2.count)) / count() as
'score' from votingapi_vote r, votingapi_vote r2,cre_average_vote a, cre_average_vote a2 where r.uid = a.uid AND r2.uid = a2.uid AND
abs(r.value-r2.value) <= 20 AND a.uid <> a2.uid AND a.uid=2 GROUP BY avg_diff ORDER BY score ASC; </code
score is calculated by taking the avg_diff and dividing it by the number of revelant votes (votes cast on the same piece of content whos difference was less then or equal to 20). Obviosuly, all those columns are not needed in the final module, they are there because they helped me better understand what I was playing with and I hope they help you understand.
_user_recommendation_user_to_user($uid) is a function that will return a db_result object for the big query ^ It is a great way to tie your module into recommended users
Please Thoughts? Sugguestions? Criticisms?
