--- loncom/interface/Attic/lonchart.pm 2002/07/01 13:59:13 1.47 +++ loncom/interface/Attic/lonchart.pm 2002/07/02 15:13:06 1.50 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonchart.pm,v 1.47 2002/07/01 13:59:13 stredwic Exp $ +# $Id: lonchart.pm,v 1.50 2002/07/02 15:13:06 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,16 +59,20 @@ my $jr; # ----- FORMAT PRINT DATA ---------------------------------------------- sub FormatStudentInformation { - my ($cache,$name,$studentInformation,$spacePadding)=@_; - my $Str='
';
+    my ($cache,$name,$studentInformation,$reselected,$spacePadding)=@_;
+    my $Str='';
 
-    foreach (@$studentInformation) {
-	my $data=$cache->{$name.':'.$_};
+    for(my $index=0; $index<(scalar @$studentInformation); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+	my $data=$cache->{$name.':'.$studentInformation->[$index]};
 	$Str .= $data;
 
 	my @dataLength=split(//,$data);
 	my $length=scalar @dataLength;
-	$Str .= (' 'x($cache->{$_.'Length'}-$length));
+	$Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
+                      $length));
 	$Str .= $spacePadding;
     }
 
@@ -76,7 +80,7 @@ sub FormatStudentInformation {
 }
 
 sub FormatStudentData {
-    my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
+    my ($reselected,$name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
     my ($sname,$sdom) = split(/\:/,$name);
     my $Str;
     my %CacheData;
@@ -87,26 +91,19 @@ sub FormatStudentData {
     # Handle Student information ------------------------------------------
     # Handle user data
     $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation, 
-                                   $spacePadding);
+                                   $reselected, $spacePadding);
 
     # Handle errors
     if($CacheData{$name.':error'} =~ /environment/) {
+        $Str .= '
'; untie(%CacheData); - $Str .= '
'; return $Str; -# my $errorMessage = $CacheData{$name.':error'}; -# return ''.$sname.''.$sdom. -# ''.$errorMessage.''; } if($CacheData{$name.':error'} =~ /course/) { + $Str .= '
'; untie(%CacheData); - $Str .= ''; - return $Str; -# my $errorMessage = 'May have no course data or '. -# $CacheData{$name.':error'}; -# return ''.$sname.''.$sdom. -# ''.$errorMessage.''; + return $Str; } # Handle problem data ------------------------------------------------ @@ -116,6 +113,10 @@ sub FormatStudentData { my $problemsSolved = 0; my $numberOfParts = 0; foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) { + if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) { + next; + } + my $characterCount=0; foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) { my $problem = $CacheData{$problemID.':problem'}; @@ -208,17 +209,21 @@ sub FormatStudentData { } $Str .= ''.$problemsSolved. - ' / '.$totalProblems.''; + ' / '.$totalProblems.'
'; untie(%CacheData); return $Str; } sub CreateTableHeadings { - my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; my $Str='
';
 
     for(my $index=0; $index<(scalar @$headings); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+
 	my $data=$$headings[$index];
 	$Str .= $data;
 
@@ -230,7 +235,12 @@ sub CreateTableHeadings {
     }
 
     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
-	$Str .= $CacheData->{$sequence.':title'};
+        if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+
+        my $name = $CacheData->{$sequence.':title'};
+	$Str .= $name;
 	my @titleLength=split(//,$CacheData->{$sequence.':title'});
 	my $leftover=$CacheData->{$sequence.':columnWidth'}-
                      (scalar @titleLength);
@@ -244,36 +254,90 @@ sub CreateTableHeadings {
     return $Str;
 }
 
-sub CreateColumnSelectors {
-    my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
-    my $Str='';
+sub CreateColumnSelectionBox {
+    my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_;
 
-    $Str .= '
'."\n"; - $Str .= ''; - $Str .= '
'."\n"; - return $Str; + my $missing=0; + my $notThere='Select column to view:'; + my $name; + $notThere .= ''; + $notThere .= ''; + } else { + $notThere=''; + } + + return $notThere.''; +} + +sub CreateColumnSelectors { + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; + + my $found=0; + my ($name, $length, $position); + my $present='
';
+    for(my $index=0; $index<(scalar @$headings); $index++) {
+        if(!&ShouldShowColumn($reselected, 'heading', $index)) {
+            next;
+        }
+        $name = $headings->[$index];
+        $length=$CacheData->{$$studentInformation[$index].'Length'};
+        $position=int($length/2);
+	$present .= (' 'x($position));
+        $present .= '';
+        $position+=2;
+	$present .= (' 'x($length-$position));
+	$present .= $spacePadding;
+        $found++;
     }
 
     foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
-	$Str .= $CacheData->{$sequence.':title'};
-	my @titleLength=split(//,$CacheData->{$sequence.':title'});
-	my $leftover=$CacheData->{$sequence.':columnWidth'}-
-                     (scalar @titleLength);
-	$Str .= (' 'x$leftover);
-	$Str .= $spacePadding;
+        if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) {
+            next;
+        }
+        $name = $CacheData->{$sequence.':title'};
+        $length=$CacheData->{$sequence.':columnWidth'};
+        $position=int($length/2);
+	$present .= (' 'x($position));
+        $present .= '';
+        $position+=2;
+	$present .= (' 'x($length-$position));
+	$present .= $spacePadding;
+        $found++;
     }
 
-    return $Str;
+    if($found) {
+        $present .= '
'; + $present = $present; + } else { + $present = ''; + } + + return $present.''."\n";; } sub CreateForm { @@ -285,42 +349,46 @@ sub CreateForm { elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; } else { $OpSel1 = 'selected'; } - my $Ptr = '
'."\n"; - $Ptr .= ' Sort by:   '."\n"; + my $Ptr .= ''."\n"; + $Ptr .= ''; + $Ptr .= ''; return $Ptr; } sub CreateLegend { - my $Str = '

'.$ENV{'course.'.$ENV{'request.course.id'}.'.description'}. - '

'.localtime(). - "

1..9: correct by student in 1..9 tries\n".
+    my $Str = "

".
+              "1..9: correct by student in 1..9 tries\n".
               "   *: correct by student in more than 9 tries\n".
 	      "   +: correct by override\n".
               "   -: incorrect by override\n".
 	      "   .: incorrect attempted\n".
 	      "   #: ungraded attempted\n".
               "    : not attempted\n".
-	      "   x: excused

"; + " x: excused". + "

"; return $Str; } @@ -332,7 +400,11 @@ sub StartDocument { $Str .= ''; $Str .= ''; $Str .= ''; - $Str .= '

Assessment Chart

'; + $Str .= '

Assessment Chart'.(' 'x8).localtime();
+    $Str .= '

'; + $Str .= '

'.$ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + $Str .= '

'; +# $Str .= '

'.localtime().'

'; return $Str; } @@ -668,7 +740,8 @@ sub ProcessClassList { my %CacheData; if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) { foreach my $name (keys(%$classlist)) { - if($name =~ /\:section/ || $name =~ /\:studentInformation/) { + if($name =~ /\:section/ || $name =~ /\:studentInformation/ || + $name eq '') { next; } if($c->aborted()) { @@ -683,8 +756,6 @@ sub ProcessClassList { $name,$courseID,$c); } - $CacheData{'NamesOfStudents'}=join(":::",@names); -# $CacheData{'NamesOfStudents'}=&Apache::lonnet::arrayref2str(\@names); untie(%CacheData); } @@ -763,12 +834,10 @@ sub ProcessFullName { } sub SortStudents { - my ($CacheData)=@_; - my @students = split(/:::/,$CacheData->{'NamesOfStudents'}); -# my @students=&Apache::lonnet::str2array($CacheData->{'NamesOfStudents'}); + my ($students,$CacheData)=@_; my @sorted1Students=(); - foreach (@students) { + foreach (@$students) { my ($end,$start)=split(/\:/,$CacheData->{$_.':date'}); my $active=1; my $now=time; @@ -805,7 +874,7 @@ sub SortStudents { } my @order = (); - foreach my $key (sort keys(%sortData)) { + foreach my $key (sort(keys(%sortData))) { push (@order,$sortData{$key}); } @@ -858,6 +927,11 @@ sub ExtractStudentData { foreach my $key (keys (%$courseData)) { $CacheData{$name.':'.$key}=$courseData->{$key}; } + if(defined($CacheData{'NamesOfStudents'})) { + $CacheData{'NamesOfStudents'}.=':::'.$name; + } else { + $CacheData{'NamesOfStudents'}=$name; + } } untie(%CacheData); } @@ -865,6 +939,30 @@ sub ExtractStudentData { return; } +sub ShouldShowColumn { + my ($reselected,$type,$value)=@_; + + if($ENV{'form.sort'} eq 'Recalculate Chart') { + return 1; + } + + if(defined($ENV{'form.'.$type.$value})) { + return 1; + } + + return &CheckForStringInArray($reselected, $type.$value); +} + +sub CheckForStringInArray { + my ($inputArray,$checkString)=@_; + foreach (@$inputArray) { + if($_ eq $checkString) { + return 1; + } + } + return 0; +} + # ----- END HELPER FUNCTIONS -------------------------------------------- sub BuildChart { @@ -882,6 +980,10 @@ sub BuildChart { my $cid=$ENV{'request.course.id'}; my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}". "_$ENV{'user.domain'}_$cid\_chart.db"; + # $ENV{'form.domains'} can be either a scalar or an array reference. + # We need an array. + my @reselected = (ref($ENV{'form.reselect'}) ? @{$ENV{'form.reselect'}} + : ($ENV{'form.reselect'})); $isCached=&TestCacheData($ChartDB); if($isCached < 0) { @@ -891,6 +993,7 @@ sub BuildChart { } # Download class list information if not using cached data + my %CacheData; my @students=(); my @studentInformation=('username','domain','section','id','fullname'); my @headings=('User Name','Domain','Section','PID','Full Name'); @@ -914,27 +1017,40 @@ sub BuildChart { &SpaceColumns(\@students,\@studentInformation,\@headings, $ChartDB); if($c->aborted()) { return; } + } else { + if(!$c->aborted() && tie(%CacheData,'GDBM_File',$ChartDB, + &GDBM_READER,0640)) { + @students=split(/:::/,$CacheData{'NamesOfStudents'}); + } } # Sort students and print out table desciptive data - my %CacheData; if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) { - if(!$c->aborted()) { @students=&SortStudents(\%CacheData); } + if(!$c->aborted()) { @students=&SortStudents(\@students,\%CacheData); } + if(!$c->aborted()) { $r->print('

'.(scalar @students). + ' students

'); } + if(!$c->aborted()) { $r->rflush(); } if(!$c->aborted()) { $r->print(&CreateLegend()); } if(!$c->aborted()) { $r->print(&CreateForm()); } - if(!$c->aborted()) { $r->print('

'.(scalar @students). - ' students

'); } - if(!$c->aborted()) { $r->rflush(); } -# if(!$c->aborted()) { $r->print(&CreateColumnSelectors( -# \%CacheData, -# \@studentInformation, -# \@headings, -# $spacePadding)); } + if(!$c->aborted()) { $r->print(&CreateColumnSelectionBox( + \%CacheData, + \@studentInformation, + \@headings, + \@reselected, + $spacePadding)); } + if(!$c->aborted()) { $r->print(&CreateColumnSelectors( + \%CacheData, + \@studentInformation, + \@headings, + \@reselected, + $spacePadding)); } if(!$c->aborted()) { $r->print(&CreateTableHeadings( \%CacheData, \@studentInformation, \@headings, + \@reselected, $spacePadding)); } + if(!$c->aborted()) { $r->rflush(); } untie(%CacheData); } else { $r->print("Init2: Unable to tie hash to db file"); @@ -943,30 +1059,32 @@ sub BuildChart { my @updateStudentList = (); my $courseData; + $r->print('
');
     foreach (@students) {
         if($c->aborted()) {
-            if(!$isCached && 
-               tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
-                $CacheData{'NamesOfStudents'}=join(":::", @updateStudentList);
-#		    $CacheData{'NamesOfStudents'}=
-#		            &Apache::lonnet::arrayref2str(\@updateStudentList);
-                untie(%CacheData);
-            }
             last;
         }
 
         if(!$isCached) {
             $courseData=&DownloadStudentCourseInformation($_, $cid);
-            if($c->aborted()) { next; }
+            if($c->aborted()) { last; }
             push(@updateStudentList, $_);
             &ExtractStudentData($courseData, $_, $ChartDB);
         }
-        $r->print(&FormatStudentData($_, $cid, \@studentInformation,
+        $r->print(&FormatStudentData(\@reselected, $_, $cid, 
+                                     \@studentInformation,
                                      $spacePadding, $ChartDB));
         $r->rflush();
     }
 
-    $r->print('');
+    if(!$isCached && tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
+        $CacheData{'NamesOfStudents'}=join(":::", @updateStudentList);
+#		    $CacheData{'NamesOfStudents'}=
+#		            &Apache::lonnet::arrayref2str(\@updateStudentList);
+        untie(%CacheData);
+    }
+
+    $r->print('
'); $r->rflush(); return;
'; + $Ptr .= ''; + $Ptr .= ''. ' '."\n"; - $Ptr .= '

'; - $Ptr .= ''; - $Ptr .= "\n"; - $Ptr .= '   '; - $Ptr .= ''; - $Ptr .= "\n"; - $Ptr .= ''."\n"; + $Ptr .= '