--- loncom/interface/statistics/lonstudentassessment.pm 2002/07/25 21:23:51 1.2 +++ loncom/interface/statistics/lonstudentassessment.pm 2002/08/05 20:53:38 1.7 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonstudentassessment.pm,v 1.2 2002/07/25 21:23:51 stredwic Exp $ +# $Id: lonstudentassessment.pm,v 1.7 2002/08/05 20:53:38 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,67 +42,93 @@ use Apache::lonhtmlcommon; use Apache::loncoursedata; use GDBM_File; +#my $jr; + sub BuildStudentAssessmentPage { my ($cacheDB,$students,$courseID,$formName,$headings,$spacing, $studentInformation,$r,$c)=@_; - +# $jr = $r; my %cache; - unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) { + unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) { $r->print('Unable to tie database.'); return; } + + # Remove students who don't have the proper section. + my @sectionsSelected = split(':',$cache{'sectionsSelected'}); + for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0; + $studentIndex--) { + my $value = $cache{$students->[$studentIndex].':section'}; + my $found = 0; + foreach (@sectionsSelected) { + if($_ eq 'none') { + if($value eq '' || !defined($value) || $value eq ' ') { + $found = 1; + last; + } + } else { + if($value eq $_) { + $found = 1; + last; + } + } + } + if($found == 0) { + splice(@$students, $studentIndex, 1); + } + } + my ($infoHeadings, $infoKeys, $sequenceHeadings, $sequenceKeys, + $doNotShow) = + &ShouldShowColumns(\%cache, $headings, $studentInformation); + my $selectedName = &FindSelectedStudent(\%cache, $cache{'StudentAssessmentStudent'}, $students); - $r->print(&CreateInterface(\%cache, $selectedName, $students, $formName)); + $r->print(&CreateInterface(\%cache, $selectedName, $students, $formName, + $doNotShow)); + $r->rflush(); - my $Ptr = ''; + my $Str = ''; if($selectedName eq 'No Student Selected') { - $Ptr .= '

WARNING: '; - $Ptr .= 'Please select a student

'; - $r->print($Ptr); + $Str .= '

WARNING: '; + $Str .= 'Please select a student

'; + $r->print($Str); return; } - my ($infoHeadings, $infoKeys, $sequenceHeadings, $sequenceKeys) = - &ShouldShowColumns(\%cache, $headings, $studentInformation); - $r->print(&CreateTableHeadings(\%cache, $spacing, $infoKeys, $infoHeadings, $sequenceKeys, $sequenceHeadings)); untie(%cache); + if($c->aborted()) { return $Str; } my $selected=0; $r->print('
'."\n");
     foreach (@$students) {
+        if($c->aborted()) {  return $Str; }
         next if ($_ ne $selectedName && 
                  $selectedName ne 'All Students');
         $selected = 1;
         my $courseData; 
-        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
-            if($cache{$_.':lastDownloadTime'} eq 'Not downloaded') {
-                untie(%cache);
-                $courseData = 
-                    &Apache::loncoursedata::DownloadCourseInformation($_, 
-                                                                      $courseID);
-                if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
-                    &Apache::loncoursedata::ProcessStudentData(\%cache, 
-                                                               $courseData, $_);
-                    untie(%cache);
-                } else {
-                    last if($c->aborted());
-                    next;
-                }
-            } else {
-                untie(%cache);
+        my $downloadTime='';
+        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
+            $downloadTime = $cache{$_.':lastDownloadTime'};
+            untie(%cache);
+        }
+        if($downloadTime eq 'Not downloaded') {
+            $courseData = 
+                &Apache::loncoursedata::DownloadCourseInformation($_, 
+                                                                  $courseID);
+            unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
+                next;
             }
-        } else {
-            last if($c->aborted());
-            next;
+            &Apache::loncoursedata::ProcessStudentData(\%cache, 
+                                                       $courseData, $_);
+            untie(%cache);
         }
 
-        last if ($c->aborted());
+        next if($c->aborted());
 
-        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
+        if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
             my $displayString = 'DISPLAYDATA'.$spacing;
             $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
                                                          \%cache, $_,
@@ -111,14 +137,15 @@ sub BuildStudentAssessmentPage {
                                                          'preformatted'));
             $r->print(&StudentReport(\%cache, $_, $spacing, $sequenceKeys));
             $r->print("\n");
+            $r->rflush();
             untie(%cache);
         }
     }
     $r->print('
'."\n"); if($selected == 0) { - $Ptr .= '

WARNING: '; - $Ptr .= 'Please select a student

'; - $r->print($Ptr); + $Str .= '

WARNING: '; + $Str .= 'Please select a student

'; + $r->print($Str); } return; @@ -127,23 +154,42 @@ sub BuildStudentAssessmentPage { #---- Student Assessment Web Page -------------------------------------------- sub CreateInterface { - my($cache,$selectedName,$students,$formName)=@_; - my $Ptr = ''; - $Ptr .= &CreateLegend(); - $Ptr .= ''."\n"; @@ -398,41 +450,22 @@ which has a size of four. =cut sub CreateColumnSelectionBox { - my ($CacheData,$headings)=@_; - - my $missing=0; - my $notThere=''; + return $notThere; } =pod @@ -462,37 +495,24 @@ for consistency of location over the col =cut sub CreateColumnSelectors { - my ($headings)=@_; -=pod - my $found=0; - my ($name, $length, $position); + my ($infoHeadings, $sequenceHeadings, $sequenceKeys)=@_; - my $present = ''; - for(my $index=0; $index<(scalar @$headings); $index++) { + my $present = ''; + for(my $index=0; $index<(scalar @$infoHeadings); $index++) { $present .= ''; - $found++; + $present .= 'name="HeadingColumn'.$infoHeadings->[$index].'" />'; + $present .= ''."\n"; } - foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) { - if(!&ShouldShowColumn($CacheData, 'ChartSequence'.$sequence)) { - next; - } + for(my $index=0; $index<(scalar @$sequenceHeadings); $index++) { $present .= ''; - $found++; + $present .= 'name="SequenceColumn'.$sequenceKeys->[$index].'" />'; + $present .= ''."\n"; } - if(!$found) { - $present = ''; - } - - return $present.''."\n";; -=cut + return $present; } #---- END Student Assessment Web Page ---------------------------------------- @@ -501,31 +521,40 @@ sub CreateColumnSelectors { sub FindSelectedStudent { my($cache, $selectedName, $students)=@_; - for(my $index=0; - ($selectedName ne 'All Students') && ($index<(scalar @$students)); - $index++) { + + if($selectedName eq 'All Students' || + $selectedName eq 'No Student Selected') { + return $selectedName; + } + + for(my $index=0; $index<(scalar @$students); $index++) { my $fullname = $cache->{$students->[$index].':fullname'}; if($fullname eq $selectedName) { if($cache->{'StudentAssessmentMove'} eq 'next') { if($index == ((scalar @$students) - 1)) { $selectedName = $students->[0]; + return $selectedName; } else { $selectedName = $students->[$index+1]; + return $selectedName; } } elsif($cache->{'StudentAssessmentMove'} eq 'previous') { if($index == 0) { $selectedName = $students->[-1]; + return $selectedName; } else { $selectedName = $students->[$index-1]; + return $selectedName; } } else { $selectedName = $students->[$index]; + return $selectedName; } last; } } - return $selectedName; + return 'No Student Selected'; } =pod @@ -558,26 +587,40 @@ sub ShouldShowColumns { my @sequenceKeys=(); my @sequenceHeadings=(); + my %doNotShow; + my $index; + my $count = 0; + my $check = ''; for($index=0; $index < scalar @$headings; $index++) { - push(@infoHeadings, $headings->[$index]); - push(@infoKeys, $cacheKey->[$index]); + $check = 'HeadingColumn'.$headings->[$index]; + if($cache->{'HeadingsFound'} =~ /$check/) { + push(@infoHeadings, $headings->[$index]); + push(@infoKeys, $cacheKey->[$index]); + } else { + $doNotShow{$count.':name'} = $headings->[$index]; + $doNotShow{$count.':id'} = 'HeadingColumn'.$headings->[$index]; + $count++; + } } foreach my $sequence (split(/\:/,$cache->{'orderedSequences'})) { - push(@sequenceHeadings, $cache->{$sequence.':title'}); - push(@sequenceKeys, $sequence); + $check = 'SequenceColumn'.$sequence; + if($cache->{'SequencesFound'} eq 'All Sequences' || + $cache->{'SequencesFound'} =~ /$check/) { + push(@sequenceHeadings, $cache->{$sequence.':title'}); + push(@sequenceKeys, $sequence); + } else { + $doNotShow{$count.':name'} = $cache->{$sequence.':title'}; + $doNotShow{$count.':id'} = 'SequenceColumn'.$sequence; + $count++; + } } -# my $headings=$cache->{'form.ChartHeadings'}; -# my $sequences=$cache->{'form.ChartSequences'}; -# if($headings eq 'ALLHEADINGS' || $sequences eq 'ALLSEQUENCES' || -# $headings=~/$test/ || $sequences=~/$test/) { -# return 1; -# } + $doNotShow{'count'} = $count; return (\@infoHeadings, \@infoKeys, \@sequenceHeadings, - \@sequenceKeys); + \@sequenceKeys, \%doNotShow); } #---- END Student Assessment Worker Functions --------------------------------
'."\n"; - $Ptr .= '{'sectionList'}); + my @selectedSections = split(':',$cache->{'sectionsSelected'}); + $Str .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections, + \@selectedSections, + 'Statistics'); + $Str .= ''; + $Str .= &CreateColumnSelectionBox($doNotShow); + $Str .= ''."\n"; + $Str .= '
Select column to view:'; - my $name; - $notThere .= ''; - $notThere .= '{'count'}; $index++) { + my $name = $doNotShow->{$index.':name'}; + $notThere .= ''."\n"; - $missing++; } - if($missing) { - $notThere .= ''; - } else { - $notThere='
'; - } + $notThere .= ''; - return $notThere.'
'; $present .= ''; - $present .= ''; $present .= ''; - $present .= '