Votes goes over 100%
pguillard - January 20, 2009 - 17:33
| Project: | Advanced Poll |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
Some votes sometimes go to 140%, 160% and brake the design with a bar up to width:160%.
Somebody can tell me where/which function implement the calculation?
Phil

#1
Can you provide more information on the settings you are using and what combination of votes generates this bug?
#2
I don't have aceess to any configuration, /admin/by-module gives me just a link to user permissions.
I should tell i mostly voted myself several times. The node is a advpoll-binary and its settings :
Basic question Yes/No
Allow users to cast a write-in vote by default=>inactive
Use electoral list by default=>inactive
Show individual votes by default=>active
Phil
#3
Have exactly the same issue. 3 options with the first one showing 111% of votes cast, second 33% of votes cast, third option showing 0% of votes cast. The foreground bar extends over the block. I am using latest dev release.
#4
Please include the actual votes cast in these bug reports so I can try to replicate the error.
#5
The three results for the poll I am running:
Option 1 - 111% (10 votes)
Option 2 - 33% (3 votes)
Option 3 - 0% (0 votes)
#6
I can't re-produce this. MAybe some votes have been cancelled, also some people may have vote again and again..
I can't find the individual votes in my database, but here is what i have found at the moment:
"In 2009, do you plan to buy or rent a flat ?"
Buy 200% (10 votes)
Rent 120% (6 votes)
Total voters: 5
mysql> select * from advpoll where nid=15;
+-----+--------+--------+----------+--------+-------------+-----------+------------+------------+----------+----------+---------------+----------+
| nid | quorum | mode | use_list | active | max_choices | algorithm | show_votes | start_date | end_date | writeins | show_writeins | question |
+-----+--------+--------+----------+--------+-------------+-----------+------------+------------+----------+----------+---------------+----------+
| 15 | 0 | binary | 0 | 0 | 1 | plurality | 1 | 0 | 0 | 0 | 0 | |
+-----+--------+--------+----------+--------+-------------+-----------+------------+------------+----------+----------+---------------+----------+
mysql> select * from advpoll_choices where nid=15;
+-----+-----+---------+--------+---------+
| cid | nid | label | weight | writein |
+-----+-----+---------+--------+---------+
| 6 | 15 | Buy | 0 | 0 |
| 7 | 15 | Rent | 1 | 0 |
+-----+-----+---------+--------+---------+
mysql> select * from votingapi_vote where content_id=15;
+---------+--------------+------------+-------+------------+-----+-----+------------+----------------+
| vote_id | content_type | content_id | value | value_type | tag | uid | timestamp | vote_source |
+---------+--------------+------------+-------+------------+-----+-----+------------+----------------+
| 6 | advpoll | 15 | 1 | option | 6 | 1 | 1231174276 | 88.177.191.216 |
+---------+--------------+------------+-------+------------+-----+-----+------------+----------------+
mysql> select * from votingapi_cache where content_id=15;
+---------------+--------------+------------+-------+------------+----------+-------------+------------+
| vote_cache_id | content_type | content_id | value | value_type | tag | function | timestamp |
+---------------+--------------+------------+-------+------------+----------+-------------+------------+
| 111 | advpoll | 15 | 1 | | _advpoll| total_votes| 1231860345 |
| 112 | advpoll | 15 | 1 | | 6 | option-1 | 1231860345 |
+---------------+--------------+------------+-------+------------+----------+-------------+------------+
mysql> select * from content_type_advpoll_binary where nid=15;
+-----+-----+-------------------+
| vid | nid | field_ferme_value |
+-----+-----+-------------------+
| 15 | 15 | 1 |
+-----+-----+-------------------+
mysql> select * from poll;
Empty set (0.00 sec)
mysql> select * from poll_choices;
Empty set (0.00 sec)
mysql> select * from poll_votes;
Empty set (0.00 sec)
Thanks
Philippe
#7
Browsing the votingapi_vote table showed 6 votes from the same IP address. Deleting the rows from the table fixed the voting going over 100% so the issue seems to be coming from multiple votes from the same ip.
#8
same problem
hi, I have a same problem,
I attached a screenshot
Igorik
#9
in poll settings, there is option to choose 2 from total 3 answers.
#10
I have the same problem. The way I see it is that the result precentage is calculated from VOTERS count, not VOTES. The same way as in the example above: 10 votes, 5 voters, result 200%. It adds up too.
Can't track the error though.
#11
I'm seeing this error, and believe the problem is with the totals in the cache table:
mysql> select * from votingapi_cache;+---------------+--------------+------------+-------+------------+----------+-------------+------------+
| vote_cache_id | content_type | content_id | value | value_type | tag | function | timestamp |
+---------------+--------------+------------+-------+------------+----------+-------------+------------+
| 45 | advpoll | 174 | 5 | | _advpoll | total_votes | 1236010670 |
| 46 | advpoll | 174 | 1 | | 1 | option-1 | 1236010670 |
| 47 | advpoll | 174 | 2 | | 2 | option-1 | 1236010670 |
| 48 | advpoll | 174 | 4 | | 3 | option-1 | 1236010670 |
+---------------+--------------+------------+-------+------------+----------+-------------+------------+
4 rows in set (0.00 sec)
The total votes is clearly not the sum of the options' total votes (5 vs 7). These votes were made by setting the anonymous vote reset to 'immediately' in the votingapi settings page, then voting on the same system with 3 different browsers, refreshing the page and revoting.
The duplicate anonymous votes increase the individual choice vote counts, but don't change the overall total vote count.
Updated:
Here's the problem (in my configuration, which allows anonymous votes AND multiple voting):
modes/binary.inc around line 170, there's this query:
$result = db_query('SELECT uid, vote_source FROM {votingapi_vote} WHERE content_type = "advpoll" AND content_id = %d AND value_type = "option" GROUP BY uid, vote_source', $node->nid);The 'GROUP BY uid, vote_source' combines multiple values into one vote. So, anonymous users voting multiple times (which is allowed in my setup), merges all the votes into one vote.
In this case, the total_votes value never updates. If the total_votes value doesn't update, while the individual counts increase, the percentages (votes / total_votes) go over 100%.
#12
hi
maybe you are right but I have this problem but anonymous can't vote on my site
Igorik
#13
Everyone is right here. There is a serious issue with Advanced Poll and am surprised that not many people are noticing it.
I have the following issues:
- number of votes is not adding up to the individual counts
- percentage count is adding up to more than 100%
- bars are going overboard, hence making the poll look really weird and funny
- Reset vote option doesn't do anything...am not sure what it is supposed to do.
- Vote button doesn't refresh the screen, we have to refresh to see the results (I tried it on multiple computers)
Please please someone get us a fix.
thanks!
#14
Hi,
I managed to reproduce the wrong (>100%) percentage issue.
1. Create a binary poll
2. Set the Voting API 'Anonymous vote rollover: ' to 'Never' (go to admin/settings/votingapi)
3. Cast votes using the same IP without being logged on (use different browsers)
As I understand it, if the Step 2 setting is 'Never' i should not be able to cast a second vote (with the same IP address) so this may be the actual problem.
Check out the attached image for a visual on the bug.
#15
Thanks for the info. I did your settings and created a new binary poll, but it's the same issue:
1. over 100%
2. when clicked on the Vote button it doesn't refresh but increments the count...
What about the VotingAPI's 3rd option: Do not tally results automatically: I am using a module that manages its own vote results?
#16
#17
Ugh, drupal.org just deleted the text of my comment for some reason. Here it is again:
Try out this patch and let me know if it works ("patch -p0 < advpoll_over_100pct.patch" in your advpoll directory). Or just edit line 170 in modes/binary.inc to be "GROUP BY uid, vote_source, timestamp".
#18
Thanks Chris. I did the change, however I got the following error:
should I run update.php perhaps?
#19
It's working now as follows:
- Make sure you don't leave the old binary.inc file in the same folder!
- run update.php after this change.
Thanks a lot Chris! it is working beautiful now, even the old polls are adjusted.
Will this patch be committed in the main source?
#20
Yep, I just needed someone to confirm that the patch worked. Committed: http://drupal.org/cvs?commit=186616
#21
One more issue I found today:
Option1: 64% (9 votes)
Option2: 21% (3 votes)
Option3: 14% (2 votes)
Option4: 0% (0 Votes)
Total Voters: 14
Total%: 99% doesn't add up to 100%
After submitting one more vote for the same poll, I got:
Option1: 56% (9 votes)
Option2: 19% (3 votes)
Option3: 13% (2 votes)
Option4: 13% (2 votes)
Total Voters: 16 (incremented by 2)
Total%: 101% <-- should be 100%
The above happens if we have more than 3 options to choose from and gets scewed more as the options increase.
Note that I also have the following problem (which might be related): When people press the Vote button, nothing happens, they can click it several times. To see the results, they have to refresh the whole page, the form doesn't refresh automatically.
I tried this on several computers in different locations. Could it be a theme issue or perhaps an AJAX issue?
thanks!
#22
Automatically closed -- issue fixed for 2 weeks with no activity.
#23
This issue still exists, if the choices are more than 2 then the numbers don't add up! I am using the latest code.
check this image, adds up to 105% and number of votes should be 215 not 204.
#24
it's weird that we still have this issue on this wonderful module. how come nobody else is complaining about it and why don't we have a solution??
Does anyone know of any other poll module that acts nicer than the standard poll? I would prefer one with Ajax functionality and color bars.
#25
Hmm this does seem to be an error. Can you come up with a repeatable way to get the error so I can fix it more quickly? e.g. Add X choices, vote A,B,C, then you'll see that the result doesn't add up to 100% - something along those lines would be very helpful.
#26
I will do more experimentation and let you know. But for now I have noticed that anything with more than 3 choices is consistently giving this issue - both vote-count and percentage-count are not adding-up.
will keep you updated.
#27
OK, here's the problem:
1. As long as the poll has 3 or less choices, it works great.
2. If you have 4 choices then the sum of the votes AND the percentages will be skewed.
This is consistent with every site that I have tried it with and am sure you can reproduce it easily.
Here's another image from another website:
#28
OK, I gave up on this module. It has nicer features, but only if they works!!
I'm going back to the regular one.
#29
I suppose the Advanced Poll module is an abandoned project. I hope someone will take ownership and continue development on it.
#30
I had the same problem this weekend. 114 % with 4 options. I have the clue that this is a result of entries in the table {votingapi_vote} with the same timestamp.
I updated this entries with varying stamps and everything worked fine. In sum: 100%
#31
Exactly! Thanks for finding the culprit, I found all the duplicate timestamps in the database. But can you please post the sql statement that you wrote to find the duplicates and change them using phpAdmin? or any other tips would be appreciated. Thanks!
I hope the developer Chris Kennedy is still around and can help in fixing this issue now that spiesser pin-pointed the reason for the wrong stats being that the module registers the same date stamp to multiple records.
#32
Can anyone help please? How many people are using this module anyways? can't they see the issue with it?
#33
OK, here's another approach: Does anyone know if the settings in the Voting API module will affect Advanced Poll?
#34
Can everyone who is experiencing the problem please share what version of Voting API and what version of Drupal they are using? Also, can you please double check and confirm that you are using 6.x-dev of Advanced Poll?
#35
Drupal 6.13
Voting API 6.x-2.3
Advanced poll 6.x-1.x-dev (the converter is not enabled)
thanks!
#36
Ok, after researching further, it seems kitt was right in comment #11. The SQL query used to count votes was wrong because it grouped multiple votes by one user into a single result. (By the way, it's important to point out that this bug only effects binary votes that allow users to select more than 1 vote choice.)
Try the attached patch for binary.inc.
You will need to register a new vote in each poll that has a problem in order to forced advpoll to update the vote total in voting_api_cache. (Does anyone know if there's a way to clear this table and recalculate all votes automatically? Just clearing Drupal's caches didn't do it for me.)
The patch works for me but I haven't fully tested with other vote types yet.
#37
Thanks a lot for the solution, I will test it on several of my polls and let you know.
Two issues:
1. My votes let users select only a single vote
2. How can I apply the patch? :(
thanks!
#38
Vako -- Strange that you're seeing the error when only allowing one vote. I couldn't reproduce the error on binary polls w/ one vote allowed.
In any case, here's a link that explain show to apply patches:
http://drupal.org/node/60108
In short:
1. make a backup copy of your modules/advpoll/modes/binary.inc file.
2. make a backup of your database.
3. place the patch file in the modules/advpoll/modes/ folder.
4. run this command (in the modules/advpolls/modes/ folder): patch < patch-binary-inc-361593.patch
I'm not sure if that'll overwrite your existing binary.inc file or create a binary.inc.new file. If it's the latter, then rename the binary.inc.new file to binary.inc.
Good luck!
#39
Worked great!
I downloaded a free ssh client called Putty from www.putty.org and applied the patch. Re-entered my vote on every poll and the numbers match now.
Although some of them still have small discrepancies, but I can live with that. Hopefully the new polls will be flawless.
thanks again for your great help!
#40
Vako: Excellent. Are the small discrepancies just minor issues due to rounding, or bigger than that? The rounding errors are going to be there unless the module is modified to display percentages with decimal points. For instance, you might see a poll with three options broken down like this: 34%, 34%, 33%. The first two, with 33.5% each were automatically rounded up.
#41
I get two issues:
1. Rounding issue, exactly as you described
2. If we had a poll that had 5 questions and after getting several votes, two questions were removed that already had votes.
I am not sure if the second case is totally valid, it might also be related to the rounding issue.
Question: what happens if we remove questions that already have votes applied to it?
For me the case is closed, perfect module thanks to all the developers!
When will this last patch be committed?