Patch fürs VotePlugin

07 June 2025 - 20:29 | Version 2 |

Quelle: http://twiki.org/cgi-bin/view/Plugins/VotePluginDev

Grund: Damit er die einzelnen Umfragen einzeln wertet, auch wenn alle mit saveto ans gleiche ort gespeichert werden.
--- 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'

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding wiki.doebe.li? Send feedback
This page was cached on 08 Jun 2025 - 18:20.