Add Condorcet Voting to ranking.module
Gauntlet - August 2, 2009 - 04:20
| Project: | Decisions |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | critical |
| Assigned: | Gauntlet |
| Status: | closed |
Description
Add Condorcet voting, display, and calculation to the ranking.module.
Have the results display as a pairwise matrix, and have the rankings determined by Shultze method.
This issue is being created at the request of the maintainer after I mentioned to them that I was working on a patch that did this.

#1
#2
OK, so this is my first-ever attempt to use CVS, or Eclipse, or this commenting tool. I can't count the number of things I'm probably doing wrong. Here goes.
Oh, and one thing. I'm diffing from the latest version, but it was actually developed against 0.1 beta three. I've tried to accommodate any changes, but it may show up.
#3
#4
A quick review:
+ 'borda count' => t('Borda count is an algorithm by which each candidate gets a number of points assigned based on the number of candidates standing. See the <a href="http://en.wikipedia.org/wiki/Borda_count">Borda count article on Wikipedia</a> for more information.'),+ 'condorcet' => t('Condorcet finds the one candidate who would beat all other candidates in all possible two-person races. In this implementation, ties are broken using Schulze method. See the <a href="http://en.wikipedia.org/wiki/Schulze_method">Schulze method article on Wikipedia</a> for more information.'));
Please respect existing indentation.
+ $output .= t('<p>The number in a given square is the number of times the row was preferred to the column.</p> ') . '<table>';+ // Display a matrix of preference votes.
same here. That code should also be made themable, see: http://api.drupal.org/api/function/theme_table/6 This will also make the code more readable.
I haven't reviewed the actual algorithms.
+function _compare_beatpaths($a, $b) {Isn't that just a reimplementation of strcmp?
Do you have experience with unit testing? I would love to get this in to make sure Condorcet actually works and that it works even when we change things around it... See:
http://drupal.org/handbook/modules/simpletest
http://drupal.org/project/simpletest
http://www.lullabot.com/articles/introduction-unit-testing
http://www.lullabot.com/articles/drupal-module-developer-guide-simpletest
I know I haven't got a single test in yet, but now is as good time as any! ;) I *will* still accept your patch without unit tests however, so don't worry about that.
Thank you very much for your patch, keep up the good work!
#5
I'll look into all of the above. Also, I've found at least one case where the algorithm goes loopy, so it's going to need some tweaking before it's ready for the light of day. Thanks for your patience and help.
#6
OK, with the exception of unit testing, which is going to require a whole other level of learning for me, I think I've addressed all your concerns, and the circumstances of which I'm aware in which ties were screwing things up.
Until I learn more about unit testing, I don't know where to go from here except getting people to try it.
#7
Alright! You rock!
I will commit this patch shortly, but I would like you to make some adjustments, mostly on the documentation side. Mainly, the results display says this:
I don't see numbers in squares. In the results. I think that's all, this will be part of the next release!
Note that to test the patch, I have (painfully) inputed the voting results described on the wikipedia page (and they match) here:
http://decisions.test.koumbit.net/node/4
To fill in the results, I used this dummy SQL request I was tuning as I went along:
mysql> set @newuid=1+@newuid;insert into votingapi_vote (content_type,content_id,value,value_type,tag,uid,vote_source) values ("decisions",4,1,"option",4,@newuid,"72.0.72.144"),("decisions",4,2,"option",2,@newuid,"72.0.72.144"),("decisions",4,3,"option",3,@newuid,"72.0.72.144"),("decisions",4,4,"option",1,@newuid,"72.0.72.144");This is the kind of things I would like a simple test unit to do...
#8
Patch committed to head, thanks! Just figure out the "number given in square" issue and we can close this.
#9
Hey, anarcat. Sorry for disappearing off the face of the earth, there. School started.
I think you just need to change the sentence to "The table below indicates the number of voters who preferred the row to the column."
If I try to make a diff for that I'm going to screw it up. Easier for you to copy and paste, probably. :)
#10
Alright, I'll try to push this in the next release, thanks!
#11
Committed a fix, thanks!
#12
Automatically closed -- issue fixed for 2 weeks with no activity.