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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 26 Mar 2003 16:26:35 -0000


This is a MIME encoded message

--matthew1048695995
Content-Type: text/plain

matthew		Wed Mar 26 11:26:35 2003 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  Changes to prevent the display of the problem part when all the problems
  ONLY have a part 0.
  Reworked the logic on sorting in &output_html_ungrouped.
  
  
--matthew1048695995
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030326112635.txt"

Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.42 loncom/interface/statistics/lonproblemstatistics.pm:1.43
--- loncom/interface/statistics/lonproblemstatistics.pm:1.42	Wed Mar 26 10:19:16 2003
+++ loncom/interface/statistics/lonproblemstatistics.pm	Wed Mar 26 11:26:35 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.42 2003/03/26 15:19:16 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.43 2003/03/26 16:26:35 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -243,6 +243,7 @@
                   "S.D.","Skew.");#,"D.F.1st","D.F.2nd");
     # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
     foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
+        my $show_part = 0;
         next if ($sequence->{'num_assess'}<1);
         $r->print("<h3>".$sequence->{'title'}."</h3>");
         $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
@@ -252,20 +253,22 @@
         foreach my $resource (@{$sequence->{'contents'}}) {
             next if ($resource->{'type'} ne 'assessment');
             foreach my $part (@{$resource->{'parts'}}) {
-                if ($part == 0) {
-                    $part = '&nbsp;';
-                }
                 my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
                     $SKEW) = &Apache::loncoursedata::get_problem_statistics
                         (undef,$resource->{'symb'},$part,
                          $ENV{'request.course.id'});
+                #
+                $show_part = 1 if ($part ne '0');
+                $part = '&nbsp;' if ($part == 0);
+                #
                 my $wrongpercent = 0;
                 if (defined($num) && $num > 0) {
                     $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
                 }
                 $r->print('<tr>'.&statistics_html_table_data
                           ($resource,$part,$num,$tries,$mod,$mean,$Solved,
-                           $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW).
+                           $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW,
+                           $show_part).
                           "</tr>\n");
             }
         }
@@ -287,10 +290,11 @@
     my ($r) = @_;
     #
     my $show_container = 0;
+    my $show_part = 0;
     #$r->print(&ProblemStatisticsLegend());
     my @Header = ("Title","Part","#Stdnts","Tries","Mod",
                   "Mean","#YES","#yes","%Wrng","DoDiff",
-                  "S.D.","Skew.");#,"D.F.1st","D.F.2nd");
+                  "S.D.","Skew");#,"D.F.1st","D.F.2nd");
     #
     my $sortby = undef;
     foreach (@Header) {
@@ -309,23 +313,9 @@
     }
     #
     $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
-    $r->print('<table border="0" cellpadding="3">'."\n");
-    my $Str = '';
-    foreach (@Header) {
-        if (/^(Part)$/) {  # Do not allow sorting on this field
-            $Str .= '<th>'.$_.'</th>';
-        } else {
-            $Str .= '<th>'.
-     '<a href="javascript:document.Statistics.sortby.value='."'$_'".
-         ';document.Statistics.submit();">'.
-             $_.'</a></th>';
-        }
-    }
-    $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
     $r->rflush();
     #
     # Compile the data
-    my %Statshash;
     my @Statsarray;
     foreach my $sequence (@Sequences) {
         next if ($sequence->{'num_assess'}<1);
@@ -336,14 +326,16 @@
                     $SKEW) = &Apache::loncoursedata::get_problem_statistics
                         (undef,$resource->{'symb'},$part,
                          $ENV{'request.course.id'});
+                #
+                $show_part = 1 if ($part ne '0');
+                $part = '&nbsp;' if ($part == 0);
+                #
                 my $wrongpercent = 0;
                 if (defined($num) && $num > 0) {
                     $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
                 }
-                my $key = $resource->{'symb'}.':'.$part;
-                $Statshash{$key} = 
-                    {
-                        'sequence' => $sequence,
+                push (@Statsarray,
+                      { 'sequence' => $sequence,
                         'resource' => $resource,
                         'Title' => $resource->{'title'},
                         'Part'  => $part,
@@ -357,39 +349,40 @@
                         'DoDiff' => $DegOfDiff,
                         'S.D.' => $STD,
                         'Skew' => $SKEW,
-                    };
-                push (@Statsarray,$Statshash{$key});
+                      });
             }
         }
     }
     #
+    # Table Headers
+    $r->print('<table border="0" cellpadding="3">'."\n");
+    my $Str = '';
+    foreach (@Header) {
+        next if ($_ eq 'Part' && !$show_part);
+        # Do not allow sorting on some fields
+        if ($_ eq $sortby || /^(Part)$/) {  
+            $Str .= '<th>'.$_.'</th>';
+        } else {
+            $Str .= '<th>'.
+     '<a href="javascript:document.Statistics.sortby.value='."'$_'".
+         ';document.Statistics.submit();">'.
+             $_.'</a></th>';
+        }
+    }
+    $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
+    #
     # Sort the data
+    my @OutputOrder;
     if ($sortby eq 'Container') {
-        foreach my $sequence (@Sequences) {
-            next if ($sequence->{'num_assess'}<1);
-            foreach my $resource (@{$sequence->{'contents'}}) {
-                next if ($resource->{'type'} ne 'assessment');
-                foreach my $part (@{$resource->{'parts'}}) {
-                    my $key = $resource->{'symb'}.':'.$part;
-                    $r->print('<tr>');
-                    if ($show_container) {
-                        $r->print('<td bgcolor="#FFFFE6">'
-                                  .$sequence->{'title'}.'</td>');
-                    }
-                    $r->print(&stats_row_from_hash($Statshash{$key}));
-                    $r->print("</tr>\n");
-                }
-            }
-        }
+        @OutputOrder = @Statsarray;
     } else {
         # $sortby is already defined, so we can charge ahead
-        my @OutputOrder;
         if ($sortby =~ /^(title|part)$/i) {
             # Alpha comparison
             @OutputOrder = sort {
-                $b->{$sortby} cmp $a->{$sortby} ||
-                    $b->{'Title'} cmp $a->{'Title'} ||
-                        $b->{'Part'} cmp $a->{'Part'};
+                lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
+                    lc($a->{'Title'}) cmp lc($b->{'Title'}) ||
+                        lc($a->{'Part'}) cmp lc($b->{'Part'});
             } @Statsarray;
         } else {
             # Numerical comparison
@@ -409,21 +402,21 @@
                 }
                 if ($retvalue eq '0') {
                     $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
-                                $b->{'Title'} <=> $a->{'Title'} ||
-                                $b->{'Part'}  <=> $a->{'Part'};
+                                lc($a->{'Title'}) <=> lc($b->{'Title'}) ||
+                                lc($a->{'Part'})  <=> lc($b->{'Part'});
                 }
                 $retvalue;
             } @Statsarray;
         }
-        foreach my $row (@OutputOrder) {
-            $r->print('<tr>');
-            if ($show_container) {
-                $r->print('<td bgcolor="#FFFFE6">'
-                          .$row->{'sequence'}->{'title'}.'</td>');
-            }
-            $r->print(&stats_row_from_hash($row));
-            $r->print("</tr>\n");
+    }
+    foreach my $row (@OutputOrder) {
+        $r->print('<tr>');
+        if ($show_container) {
+            $r->print('<td bgcolor="#FFFFE6">'
+                      .$row->{'sequence'}->{'title'}.'</td>');
         }
+        $r->print(&stats_row_from_hash($row,$show_part));
+        $r->print("</tr>\n");
     }
     $r->print("</table>\n");
     $r->print("</td></tr></table>\n");
@@ -433,17 +426,14 @@
 }
 
 sub stats_row_from_hash {
-    my ($data) = @_;
-    if (ref($data) ne 'HASH') {
-        my %Tmp = @_;
-        $data = \%Tmp;
-    }
+    my ($data,$show_part) = @_;
     return &statistics_html_table_data($data->{'resource'},$data->{'Part'},
                                        $data->{'#Stdnts'}, $data->{'Tries'},
                                        $data->{'Mod'},     $data->{'Mean'},
                                        $data->{'#YES'},    $data->{'#yes'},
                                        $data->{"\%Wrng"},  $data->{'DoDiff'},
-                                       $data->{'S.D.'},    $data->{'Skew'});
+                                       $data->{'S.D.'},    $data->{'Skew'},
+                                       $show_part);
 }
 
 ###############################################
@@ -453,13 +443,13 @@
 ###############################################
 sub statistics_html_table_data {
     my ($resource,$part,$num,$tries,$mod,$mean,$Solved,$solved,$wrongpercent,
-        $DegOfDiff,$STD,$SKEW) = @_;
+        $DegOfDiff,$STD,$SKEW,$show_part) = @_;
     my $row = '';
     $row .= '<td bgcolor="#FFFFE6">'.
         '<a href="'.$resource->{'src'}.'" target="_blank" >'.
             $resource->{'title'}.'</a>'.
                 '</td>';
-    $row .= '<td bgcolor="#FFFFE6">'.$part.'</td>' if (defined($part));
+    $row .= '<td bgcolor="#FFFFE6">'.$part.'</td>' if ($show_part);
     foreach ($num,$tries) {
         $row .= '<td bgcolor="#EEFFCC" align="right">'.$_.'</td>';
     }

--matthew1048695995--