--- loncom/interface/statistics/lonstudentassessment.pm 2003/02/28 21:19:00 1.30 +++ loncom/interface/statistics/lonstudentassessment.pm 2003/03/03 19:28:29 1.31 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentassessment.pm,v 1.30 2003/02/28 21:19:00 matthew Exp $ +# $Id: lonstudentassessment.pm,v 1.31 2003/03/03 19:28:29 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,7 +54,23 @@ use Apache::lonstatistics; use Apache::lonhtmlcommon; use Apache::loncoursedata; use Apache::lonnet; # for logging porpoises -use GDBM_File; +use Spreadsheet::WriteExcel; + +####################################################### +####################################################### +=pod + +=item Package Variables + +=over 4 + +=item $Statistics Hash ref to store student data. Indexed by symb, + contains hashes with keys 'score' and 'max'. + +=cut + +####################################################### +####################################################### my $Statistics; @@ -63,27 +79,40 @@ my $Statistics; =pod -=item &BuildStudentAssessmentPage() +=item $show_links 'yes' or 'no' for linking to student performance data -Inputs: +=item $output_mode 'html', 'excel', or 'csv' for output mode -=over 4 +=item $show 'all' or 'totals' determines how much data is output -=item $cacheDB The name of the cache file used to store student data +=cut -=item $students Array ref containing the name(s) of the students -selected for display +####################################################### +####################################################### +my $show_links; +my $output_mode; +my $show; -=item $courseID The ID of the course +####################################################### +####################################################### +# End of package variable declarations -=item $formName The name of the html form - 'Statistics' +=pod -=item $headings Array ref of headings to show +=back -=item $spacing A string of spaces +=cut -=item $studentInformation Array ref of possible headings for student info -('fullname','section',...) +####################################################### +####################################################### + +=pod + +=item &BuildStudentAssessmentPage() + +Inputs: + +=over 4 =item $r Apache Request @@ -98,36 +127,88 @@ selected for display sub BuildStudentAssessmentPage { my ($r,$c)=@_; undef($Statistics); - # + # Print out the HTML headers for the interface + # This also parses the output mode selector + # This step must always be done. $r->print(&CreateInterface()); + $r->print(''); $r->rflush(); + if (! exists($ENV{'form.notfirstrun'})) { + $r->print(< + +Please make your selections in the boxes above and hit +the button marked "Update Display". + +

+ENDMSG + return; + } + # + # + my $initialize = \&html_initialize; + my $output_student = \&html_outputstudent; + my $finish = \&html_finish; + # + if ($output_mode eq 'excel') { + $initialize = \&excel_initialize; + $output_student = \&excel_outputstudent; + $finish = \&excel_finish; + } elsif ($output_mode eq 'csv') { + $initialize = \&csv_initialize; + $output_student = \&csv_outputstudent; + $finish = \&csv_finish; + } # - $r->print(&CreateTableHeadings()); if($c->aborted()) { return ; } - - my $Count = 0; - $r->print('
'."\n");
+    #
+    # Call the initialize routine selected above
+    $initialize->($r);
     foreach my $student (@Apache::lonstatistics::Students) {
-        if($c->aborted()) { return ; }
-        $r->print(&ChartOutputStudent($student));
-        # output it
-
-        $Count++;
-        if($Count % 5 == 0) {
-            $r->print("
\n
");
+        if($c->aborted()) { 
+            $finish->($r);
+            return ; 
         }
-
-        $r->rflush();
+        # Call the output_student routine selected above
+        $output_student->($r,$student);
     }
-    $r->print('
'."\n"); - my $Str; + # Call the "finish" routine selected above + $finish->($r); + # return; } ####################################################### ####################################################### +sub get_student_fields_to_show { + my @to_show = @Apache::lonstatistics::SelectedStudentData; + foreach (@to_show) { + if ($_ eq 'all') { + @to_show = @Apache::lonstatistics::StudentDataOrder; + last; + } + } + return @to_show; +} + +sub get_sequences_to_show { + my @Sequences; + foreach my $map_symb (@Apache::lonstatistics::SelectedMaps) { + foreach my $sequence (@Apache::lonstatistics::Sequences) { + next if ($sequence->{'symb'} ne $map_symb && $map_symb ne 'all'); + next if ($sequence->{'num_assess'} < 1); + push (@Sequences,$sequence); + } + } + return @Sequences; +} + + +####################################################### +####################################################### + =pod =item &CreateInterface() @@ -152,6 +233,7 @@ sub CreateInterface { $Str .= 'Sections'; $Str .= 'Student Data'; $Str .= 'Sequences and Folders'; + $Str .= 'Output Format'; $Str .= ''."\n"; # $Str .= ''."\n"; @@ -170,78 +252,108 @@ sub CreateInterface { $Str .= ''."\n"; $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, $only_seq_with_assessments); + $Str .= ''."\n"; + $Str .= &CreateAndParseOutputSelector(); $Str .= ''."\n"; $Str .= ''."\n"; return $Str; } - ####################################################### ####################################################### =pod -=item Table Output Routines - -=over 4 +=item &CreateAndParseOutputSelector() =cut ####################################################### ####################################################### -{ - my $padding; +sub CreateAndParseOutputSelector { + my $Str = ''; + my $elementname = 'outputmode'; + # + # Format for output options is 'mode, restrictions'; + my @Options = ('html, with links','html, without links', + 'html, totals only','excel, totals only', + 'csv, totals only','csv, everything'); + my $selected = 'html, with links'; + if (exists($ENV{'form.'.$elementname})) { + if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { + $selected = $ENV{'form.'.$elementname}->[0]; + } else { + $selected = $ENV{'form.'.$elementname}; + } + } + # + # Set package variables describing output mode + $show_links = 'no'; + $output_mode = 'html'; + $show = 'all'; + my ($mode,$restriction) = split(',',$selected); + $restriction =~ s/^\s*//; + if ($mode =~ /^(html|excel|csv)$/) { + $output_mode = $mode; + } else { + $output_mode = 'html'; + } + if ($restriction eq 'with links') { + $show_links = 'yes'; + } else { + $show_links = 'no'; + } + if ($restriction eq 'totals only') { + $show = 'totals'; + } else { + $show = 'everything'; + } + # + # Build the form element + $Str = qq/