Closed (fixed)
Project:
Voting API
Version:
6.x-2.0-rc2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 Mar 2009 at 10:39 UTC
Updated:
31 Aug 2009 at 23:10 UTC
I spent two hours on this but couldn't find helpful information, so opening this issue. Where can I find some information about implementing own calculating algorithms?
Thanks.
Comments
Comment #1
eaton commentedThere's some example code in the API.txt document:
The following function adds a standard_deviation result to the calculated result data. Note that in previous versions of VotingAPI, this function received in-memory copies of each and every cast vote to avoid the need for custom SQL. This turned out to be very, very, very inefficient -- the slowdown of possibly running multiple aggregate queries is far outweighed by the memory savings of each module handling its own queries. After all, MySQL calculates standard deviation far faster than you can in PHP.
Comment #2
eaton commentedComment #3
Equ commentedDeleted.
Comment #4
Equ commentedSorry for opening this issue again, but I don't get how to use my custom algorithm. I'm not a coder, I just started dealing with php and this example doesn't really say much to me.
I know that I have to make a new module, ok that's easy. But what code should I use and where can I apply my algorithm...?
Comment #5
Equ commentedAnyone?
Comment #6
eaton commentedEqu, to implement a custom voting algorithm you'll need to make a custom module and enable it. That module will need to implement a function called yourmodulename_votingapi_results_alter() -- basically, a customized version of the function that's outlined above.
Every time someone casts a vote, that function will be triggered, giving you a chance to look at all the votes that have been cast and tally up your own custom totals.
Comment #7
tommytom commentedso this line in the sample code above
$cache[$result['tag']]['percent']['standard_deviation'] = $result['standard_deviation'];creates a single row in table votingapi_cache with function='standard_deviation' ... , right ?
And I have one more question. Why is the "while" loop needed ?
( in
while ($result = db_fetch_array($results)) {)will this not work (wiithout the 'while') :
$result = db_fetch_array($results)?Comment #8
Equ commentedComment #10
eaton commentedDurr. Replied to the *first* comment in the thread rather than the last. Whoops!
Comment #11
Equ commentedYeah, it took me a while to understand how it works =)