[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm

www www at source.lon-capa.org
Fri Jan 6 14:18:11 EST 2012


www		Fri Jan  6 19:18:11 2012 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  Work on likes/unlikes
  
  
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.324 loncom/interface/lonfeedback.pm:1.325
--- loncom/interface/lonfeedback.pm:1.324	Fri Jan  6 18:17:44 2012
+++ loncom/interface/lonfeedback.pm	Fri Jan  6 19:18:11 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.324 2012/01/06 18:17:44 www Exp $
+# $Id: lonfeedback.pm,v 1.325 2012/01/06 19:18:11 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -975,7 +975,37 @@
             ($skiptest,$roleregexp,$secregexp,$statusregexp) = 
                      &filter_regexp($rolefilter,$sectionpick,$statusfilter);
             $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
-        } 
+        }
+# We need to go through this twice, first to get the likes/dislikes, then to actually build the display
+        for (my $id=1;$id<=$contrib{'version'};$id++) {
+            my $idx=$id;
+            next if ($contrib{$idx.':deleted'});
+            next if ($contrib{$idx.':hidden'});
+            unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
+                push(@theselikes,$likes{$symb.':'.$idx.':likes'});
+            }
+        }
+# Figure out average likes and standard deviation if there are enough discussions to warrant that
+        my $ave=0;
+        my $stddev=10000;
+        if ($#theselikes>1) {
+            my $sum=0;
+            my $num=$#theselikes+1;
+            foreach my $thislike (@theselikes) {
+                $sum+=$thislike;
+            }
+            $ave=$sum/$num;
+            my $sumsq=0;
+            foreach my $thislike (@theselikes) {
+                $sumsq+=($thislike-$ave)*($thislike-$ave);
+            }
+            $stddev=sqrt($sumsq/$num);
+        }
+# Now we know the average likes $ave and the standard deviation $stddev
+#            &Apache::lonnet::logthis(join(',', at theselikes)." Ave $ave StdDev $stddev");
+#
+# This is now the real loop. Go through all entries, pick up what we need
+# 
 	for (my $id=1;$id<=$contrib{'version'};$id++) {
 	    my $idx=$id;
             next if ($contrib{$idx.':deleted'});
@@ -1116,7 +1146,6 @@
                                     $sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group));
                                 }
                                 my $thislikes=$likes{$symb.':'.$idx.':likes'};
-                                push(@theselikes,$thislikes);
                                 if ($thislikes>0) { 
                                     $sender.=' ('.&mt("[_1] likes",$thislikes).')';
                                 } elsif ($thislikes<0) {
@@ -1334,22 +1363,7 @@
             }
 # end of the loop over all discussion entries
 	}
-# Figure out average likes and standard deviation if there are enough discussions to warrant that
-        if ($#theselikes>1) {
-            my $sum=0;
-            my $num=$#theselikes+1;
-            foreach my $thislike (@theselikes) {
-                $sum.=$thislike;
-            }
-            my $ave=$sum/$num;
-            my $sumsq=0;
-            foreach my $thislike (@theselikes) {
-                $sumsq+=($thislike-$ave)*($thislike-$ave);
-            }
-            my $stddev=sqrt($sumsq/$num);
-#            &Apache::lonnet::logthis(join(',', at theselikes)." Ave $ave StdDev $stddev");
-        }
-# end of "if there actually are any discussion
+# end of "if there actually are any discussions
     }
 # end of subroutine "build_posting_display" 
 }




More information about the LON-CAPA-cvs mailing list