Item12672: VotePlugin counts votes regardless of ID

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: VotePlugin
Branches: master
Reported By: BeatDoebeli
Waiting For:
Last Change By: CrawfordCurrie
Under Foswiki 1.1.8 VotePlugin seems to count votes regardless the ID of the vote as long as the starsX-var is the same. This worked under Foswiki 1.1.3.

To reproduce the error:
  1. Setup vote %VOTE{id="foo" stars1="bar" saveto="VotingResults"}%
  2. Vote once (the plugin now shows 1 vote)
  3. Change the id of the vote =%VOTE{id="food" stars1="bar" saveto="VotingResults"}%
  4. The vote still shows one vote frown, sad smile

I tried this scenario in the sandbox of this server: VotePluginTest

-- BeatDoebeli - 29 Nov 2013

I realised that this is the second time I had the problem (because I am reinstalling foswiki from scratch...). Here is the patch for this problem: http://www.cyberhome.ch/Cyberhome/VotePluginGepatcht

-- BeatDoebeli - 01 Dec 2013

Thanks for the patch. Copied here so we don't risk losing it. Note that we're now on github. You can fork / maintain and contribute back patches for this extension at Github:foswiki/VotePlugin

--- Core.pm.orig        2008-03-04 08:41:23.000000000 +0000
+++ Core.pm     2008-03-04 08:44:36.000000000 +0000
@@ -167,22 +167,22 @@
     my %totalVoters;  # how many different people voted for each key
     my %totalRate;    # Total of all ratings for each key
     my %items;        # Hash of id's that have the same key
-    my $voteSum = 0;  # Sum of the number of votes on all rated items
-    my $rateSum = 0;  # Sum of all ratings of rated items
+    my %voteSum;      # Sum of the number of votes on all rated items
+    my %rateSum;      # Sum of all ratings of rated items
     foreach my $voter (keys %votes) {
         foreach my $vid (keys %{$votes{$voter}}) {
             foreach my $key (keys %{$votes{$voter}{$vid}}) {
                 my $choice = $votes{$voter}{$vid}{$key}->[0];
                 my $weight = $votes{$voter}{$vid}{$key}->[1];
                 $keyValueFreq{$vid}{$key}{$choice} += $weight;
-                $totalVotes{$key} += $weight;
+                $totalVotes{$key}{$vid} += $weight;
                 $items{$key}{$vid} = 1;
-                $voteSum += $weight;
+                $voteSum{$key} += $weight;
                 if ($choice =~ /^[\d.]+$/) {
-                    $totalRate{$key} += $choice * $weight;
-                    $rateSum += $choice * $weight;
+                    $totalRate{$key}{$vid} += $choice * $weight;
+                    $rateSum{$key} += $choice * $weight;
                 }
-                $totalVoters{$key}++;
+                $totalVoters{$key}{$vid}++;
             }
         }
     }
@@ -218,22 +218,22 @@
             # num_votes>0
             # avg_rating: The average rating of each item (again, of those that
             # have num_votes>0)
-            my $avg_num_votes = $numItems ? $voteSum / $numItems : 0;
-            my $avg_rating = $voteSum ? $rateSum / $voteSum : 0;
+            my $avg_num_votes = $numItems ? $voteSum{$key} / $numItems : 0;
+            my $avg_rating = $voteSum{$key} ? $rateSum{$key} / $voteSum{$key} : 0;
             my $myLastVote =
               $votes{getIdent($isSecret, $isOpen)}{$id}{$key}->[0] || 0;
             my $mean = 0;
-            if ($totalVotes{$key}) {
-                $mean = $totalRate{$key} / $totalVotes{$key};
+            if ($totalVotes{$key}{$id}) {
+                $mean = $totalRate{$key}{$id} / $totalVotes{$key}{$id};
                 if ($bayesian) {
                     $mean = ($avg_num_votes * $avg_rating +
-                               $totalVotes{$key} * $mean) /
-                                 ($avg_num_votes + $totalVotes{$key});
+                               $totalVotes{$key}{$id} * $mean) /
+                                 ($avg_num_votes + $totalVotes{$key}{$id});
                 }
             }
             push(@rows, showLineOfStars(
                 $id, $prompt, $submit, $needSubmit, $act,
-                $mean, $myLastVote, $totalVoters{$key} || 0));
+                $mean, $myLastVote, $totalVoters{$key}{$id} || 0));
         }
         else {
             my $opts = CGI::option({selected=>'selected'

-- GeorgeClark - 24 Dec 2014
 
Topic revision: r4 - 11 May 2017, CrawfordCurrie - This page was cached on 15 Jun 2019 - 22:52.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy