--- loncom/interface/statistics/lonstudentassessment.pm 2005/03/14 20:28:22 1.119 +++ loncom/interface/statistics/lonstudentassessment.pm 2006/01/29 19:39:03 1.129 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentassessment.pm,v 1.119 2005/03/14 20:28:22 matthew Exp $ +# $Id: lonstudentassessment.pm,v 1.129 2006/01/29 19:39:03 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -153,10 +153,10 @@ sub BuildStudentAssessmentPage { &Apache::lonstatistics::PrepareClasslist(); # $single_student_mode = 0; - $single_student_mode = 1 if ($ENV{'form.SelectedStudent'}); + $single_student_mode = 1 if ($env{'form.SelectedStudent'}); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['selectstudent']); - if ($ENV{'form.selectstudent'}) { + if ($env{'form.selectstudent'}) { &Apache::lonstatistics::DisplayClasslist($r); return; } @@ -167,10 +167,10 @@ sub BuildStudentAssessmentPage { $r->print(&CreateInterface()); $r->print(''); $r->print(''); + $env{'form.sort'}.'" />'); $r->rflush(); # - if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) { + if (! exists($env{'form.notfirstrun'}) && ! $single_student_mode) { return; } $r->print('

'. @@ -234,7 +234,7 @@ sub BuildStudentAssessmentPage { sub next_and_previous_buttons { my $Str = ''; $Str .= ''; + $env{'form.SelectedStudent'}.'" />'; # # Build the previous student link my $previous = &Apache::lonstatistics::previous_student(); @@ -353,7 +353,7 @@ sub CreateInterface { &mt('Clear Caches').'" />'; $Str .= ' 'x5; $Str .= - &mt('Status[_1]', + &mt('Status [_1]', ''); $Str .= '
'; return $Str; @@ -430,14 +430,9 @@ sub CreateAndParseOutputSelector { [$elementname]); # # Format for output options is 'mode, restrictions'; - my $selected = 'html, without links'; - if (exists($ENV{'form.'.$elementname})) { - if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { - $selected = $ENV{'form.'.$elementname}->[0]; - } else { - $selected = $ENV{'form.'.$elementname}; - } - } + my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0]; + $selected = 'html, without links' if (!$selected); + # # Set package variables describing output mode $show_links = 'no'; @@ -477,6 +472,7 @@ my @OutputDataOptions = grand_maximum => 1, summary_table => 1, maximum_row => 1, + ignore_weight => 0, shortdesc => 'Total Score and Maximum Possible for each '. 'Sequence or Folder', longdesc => 'The score of each student as well as the '. @@ -495,6 +491,7 @@ my @OutputDataOptions = grand_maximum => 1, summary_table => 1, maximum_row => 1, + ignore_weight => 0, shortdesc => 'Score on each Problem Part', longdesc =>'The students score on each problem part, computed as'. 'the part weight * part awarded', @@ -512,6 +509,7 @@ my @OutputDataOptions = grand_maximum => 0, summary_table => 0, maximum_row => 0, + ignore_weight => 0, shortdesc => 'Number of Tries before success on each Problem Part', longdesc =>'The number of tries before success on each problem part.', non_html_notes => 'negative values indicate an incorrect problem', @@ -529,6 +527,7 @@ my @OutputDataOptions = grand_maximum => 1, summary_table => 1, maximum_row => 0, + ignore_weight => 1, shortdesc => 'Number of Problem Parts completed successfully.', longdesc => 'The Number of Problem Parts completed successfully and '. 'the maximum possible for each student', @@ -551,14 +550,9 @@ sub CreateAndParseOutputDataSelector { my $Str = ''; my $elementname = 'chartoutputdata'; # - my $selected = 'scores'; - if (exists($ENV{'form.'.$elementname})) { - if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { - $selected = $ENV{'form.'.$elementname}->[0]; - } else { - $selected = $ENV{'form.'.$elementname}; - } - } + my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0]; + $selected = 'scores' if (!$selected); + # $chosen_output = $OutputDataOptions[0]; foreach my $option (@OutputDataOptions) { @@ -632,17 +626,21 @@ Return a line of the chart for a student my @sequences; my $navmap; # Have to keep this around since weakref is a bit zealous +sub html_cleanup { + undef(%prog_state); + undef(%width); + # + undef($navmap); + undef(@sequences); +} + sub html_initialize { my ($r) = @_; # $padding = ' 'x3; $count = 0; $nodata_count = 0; - undef(%prog_state); - undef(%width); - # - undef($navmap); - undef(@sequences); + &html_cleanup(); ($navmap,@sequences) = &Apache::lonstatistics::selected_sequences_with_assessments(); if (! ref($navmap)) { @@ -652,7 +650,7 @@ sub html_initialize { '

'); } # - $r->print("

".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}. + $r->print("

".$env{'course.'.$env{'request.course.id'}.'.description'}. "  ".localtime(time)."

"); # if ($chosen_output->{'base'} !~ /^final table/) { @@ -720,6 +718,21 @@ sub html_initialize { $Str .= "
";
     $r->print($Str);
     $r->rflush();
+    #
+    # Let the user know what we are doing
+    my $studentcount = scalar(@Apache::lonstatistics::Students); 
+    if ($env{'form.SelectedStudent'}) {
+        $studentcount = '1';
+    }
+    #
+    # Initialize progress window
+    %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
+        ($r,'HTML Chart Status',
+         'HTML Chart Progress', $studentcount,
+         'inline',undef,'Statistics','stats_status');
+    #
+    &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+                                          'Processing first student');
     return;
 }
 
@@ -747,7 +760,7 @@ sub html_outputstudent {
     my %StudentsData;
     my @tmp = &Apache::loncoursedata::get_current_state
         ($student->{'username'},$student->{'domain'},undef,
-         $ENV{'request.course.id'});
+         $env{'request.course.id'});
     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %StudentsData = @tmp;
     }
@@ -772,7 +785,8 @@ sub html_outputstudent {
         } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &student_performance_on_sequence($student,\%StudentsData,
-                                                 $navmap,$seq,$show_links);
+                                                 $navmap,$seq,$show_links,
+                                                 $chosen_output->{ignore_weight});
         }
         my $ratio='';
         if ($chosen_output->{'every_problem'} && 
@@ -832,6 +846,7 @@ sub html_outputstudent {
     $r->print($Str);
     #
     $r->rflush();
+    &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
     return;
 }    
 
@@ -849,7 +864,8 @@ sub html_finish {
         }
     }
     $r->rflush();
-    undef($navmap);
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+    &html_cleanup();
     return;
 }
 
@@ -956,8 +972,7 @@ my %formula_data;
 my $navmap;
 my @sequences;
 
-sub excel_initialize {
-    my ($r) = @_;
+sub excel_cleanup {
     #
     undef ($excel_sheet);
     undef ($excel_workbook);
@@ -973,6 +988,12 @@ sub excel_initialize {
     #
     undef($navmap);
     undef(@sequences);
+}
+
+sub excel_initialize {
+    my ($r) = @_;
+
+    &excel_cleanup();
     ($navmap,@sequences) = 
         &Apache::lonstatistics::selected_sequences_with_assessments();
     if (! ref($navmap)) {
@@ -1039,36 +1060,22 @@ sub excel_initialize {
     return if (! defined($excel_workbook));
     #
     # Add a worksheet
-    my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+    my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
     $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
     $excel_sheet = $excel_workbook->addworksheet($sheetname);
     #
     # Put the course description in the header
     $excel_sheet->write($header_row,$cols_output++,
-                   $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
+                   $env{'course.'.$env{'request.course.id'}.'.description'},
                         $format->{'h1'});
     $cols_output += 3;
     #
     # Put a description of the sections listed
     my $sectionstring = '';
     my @Sections = &Apache::lonstatistics::get_selected_sections();
-    if (scalar(@Sections) > 1) {
-        if (scalar(@Sections) > 2) {
-            my $last = pop(@Sections);
-            $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
-        } else {
-            $sectionstring = "Sections ".join(' and ',@Sections);
-        }
-    } else {
-        if ($Sections[0] eq 'all') {
-            $sectionstring = "All sections";
-        } else {
-            $sectionstring = "Section ".$Sections[0];
-        }
-    }
-    $excel_sheet->write($header_row,$cols_output++,$sectionstring,
+    $excel_sheet->write($header_row,$cols_output++,
+                        &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
                         $format->{'h3'});
-    $cols_output += scalar(@Sections);
     #
     # Put the date in there too
     $excel_sheet->write($header_row,$cols_output++,
@@ -1142,9 +1149,11 @@ sub excel_initialize {
             ! defined($formula_data{$symb}->{'Excel:endcell'})) {
             $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'};
         }
+
+        my $start = $formula_data{$symb}->{'Excel:startcell'};
+        my $end = $formula_data{$symb}->{'Excel:endcell'};
         $formula_data{$symb}->{'Excel:sum'}= $excel_sheet->store_formula
-            ('=SUM('.$formula_data{$symb}->{'Excel:startcell'}.
-             ':'.$formula_data{$symb}->{'Excel:endcell'}.')');
+            ("=IF(COUNT($start\:$end),SUM($start\:$end),\"\")");
         # Determine cell the score is held in
         $formula_data{$symb}->{'Excel:scorecell'} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
@@ -1229,7 +1238,7 @@ sub excel_initialize {
                     $weight = 1;
                     if ($chosen_output->{'scores'}) {
                         $weight = &Apache::lonnet::EXT
-                            ('resource.'.$part.'.weight',$resource->{'symb'},
+                            ('resource.'.$part.'.weight',$resource->symb,
                              undef,undef,undef);
                         if (!defined($weight) || ($weight eq '')) { 
                             $weight=1;
@@ -1253,7 +1262,7 @@ sub excel_initialize {
 		     &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($maximum_data_row,$formula_data{$symb}->{'Excel:endcol'}));
                 $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
                                              $formula_data{$symb}->{'Excel:sum'},undef,
-					     %replaceCells);
+					     %replaceCells, %replaceCells);
 			
             } elsif ($chosen_output->{'sequence_sum'}) {
                 $excel_sheet->write($maximum_data_row,$cols_output++,$max);
@@ -1328,7 +1337,7 @@ sub excel_initialize {
     #
     # Let the user know what we are doing
     my $studentcount = scalar(@Apache::lonstatistics::Students); 
-    if ($ENV{'form.SelectedStudent'}) {
+    if ($env{'form.SelectedStudent'}) {
         $studentcount = '1';
     }
     if ($studentcount > 1) {
@@ -1375,7 +1384,7 @@ sub excel_outputstudent {
     my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
                                                         $student->{'domain'},
                                                         undef,
-                                                   $ENV{'request.course.id'});
+                                                   $env{'request.course.id'});
     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %StudentsData = @tmp;
     }
@@ -1403,14 +1412,16 @@ sub excel_outputstudent {
         } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &student_performance_on_sequence($student,\%StudentsData,
-                                                 $navmap,$seq,'no');
+                                                 $navmap,$seq,'no',
+                                                 $chosen_output->{ignore_weight});
         } 
         if ($chosen_output->{'every_problem'}) {
             if ($chosen_output->{'correct'}) {
                 # only indiciate if each item is correct or not
                 foreach my $value (@$rawdata) {
-                    # nonzero means correct
-                    $value = 1 if ($value > 0);
+                    # positive means correct, 0 or negative means
+                    # incorrect
+                    $value = $value > 0 ? 1 : 0;
                     $excel_sheet->write($rows_output,$cols_output++,$value);
                 }
             } else {
@@ -1436,7 +1447,7 @@ sub excel_outputstudent {
             # The undef is for the format	    
 	    $excel_sheet->repeat_formula($rows_output,$cols_output++,
 					 $formula_data{$symb}->{'Excel:sum'},undef,
-					 %replaceCells);
+					 %replaceCells, %replaceCells);
         } elsif ($chosen_output->{'sequence_sum'}) {
             if ($score eq ' ') {
                 $cols_output++;
@@ -1472,14 +1483,12 @@ sub excel_outputstudent {
 sub excel_finish {
     my ($r) = @_;
     if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
+	&excel_cleanup();
         return;
     }
     #
     # Write the excel file
     $excel_workbook->close();
-    my $c = $r->connection();
-    #
-    return if($c->aborted());
     #
     # Close the progress window
     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
@@ -1488,6 +1497,7 @@ sub excel_finish {
     $r->print('
'. 'Your Excel spreadsheet.'."\n"); $r->rflush(); + &excel_cleanup(); return; } @@ -1518,10 +1528,7 @@ my %prog_state; # progress window state my $navmap; my @sequences; -sub csv_initialize{ - my ($r) = @_; - # - # Clean up +sub csv_cleanup { undef($outputfile); undef($filename); undef($request_aborted); @@ -1529,6 +1536,12 @@ sub csv_initialize{ # undef($navmap); undef(@sequences); +} + +sub csv_initialize{ + my ($r) = @_; + + &csv_cleanup(); ($navmap,@sequences) = &Apache::lonstatistics::selected_sequences_with_assessments(); if (! ref($navmap)) { @@ -1559,22 +1572,18 @@ END 'inline',undef,'Statistics','stats_status'); # # Open a file - $filename = '/prtspool/'. - $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. - time.'_'.rand(1000000000).'.csv'; - unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) { - $r->log_error("Couldn't open $filename for output $!"); - $r->print("Problems occured in writing the csv file. ". - "This error has been logged. ". - "Please alert your LON-CAPA administrator."); - $outputfile = undef; - } + ($outputfile,$filename) = &Apache::loncommon::create_text_file($r,'csv'); + if (! defined($outputfile)) { return ''; } # # Datestamp - my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + my $description = $env{'course.'.$env{'request.course.id'}.'.description'}; print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'. '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'. "\n"; + print $outputfile '"'. + &Apache::loncommon::csv_translate + (&Apache::lonstatistics::section_and_enrollment_description()). + '"'."\n"; foreach my $item ('shortdesc','non_html_notes') { next if (! exists($chosen_output->{$item})); print $outputfile @@ -1657,7 +1666,7 @@ sub csv_outputstudent { my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'}, $student->{'domain'}, undef, - $ENV{'request.course.id'}); + $env{'request.course.id'}); if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) { %StudentsData = @tmp; } @@ -1674,7 +1683,8 @@ sub csv_outputstudent { } else { ($performance,$performance_length,$score,$seq_max,$rawdata) = &student_performance_on_sequence($student,\%StudentsData, - $navmap,$seq,'no'); + $navmap,$seq,'no', + $chosen_output->{ignore_weight}); } if ($chosen_output->{'every_problem'}) { if ($chosen_output->{'correct'}) { @@ -1718,13 +1728,11 @@ sub csv_outputstudent { sub csv_finish { my ($r) = @_; if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) { + &csv_cleanup(); return; } close($outputfile); # - my $c = $r->connection(); - return if ($c->aborted()); - # # Close the progress window &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); # @@ -1732,6 +1740,7 @@ sub csv_finish { $r->print('
'. ''.&mt('Your csv file.').''."\n"); $r->rflush(); + &csv_cleanup(); return; } @@ -1825,7 +1834,7 @@ sub student_tries_on_sequence { } elsif ($status eq 'incorrect_by_override') { $symbol = '-'; } elsif ($status eq 'ungraded_attempted') { - $symbol = '#'; + $symbol = 'u'; } elsif ($status eq 'incorrect_attempted' || $tries > 0) { $symbol = '.'; @@ -1896,7 +1905,7 @@ Inputs: ####################################################### ####################################################### sub student_performance_on_sequence { - my ($student,$studentdata,$navmap,$seq,$links) = @_; + my ($student,$studentdata,$navmap,$seq,$links,$awarded_only) = @_; $links = 'no' if (! defined($links)); my $Str = ''; # final result string my ($score,$max) = (0,0); @@ -1910,11 +1919,14 @@ sub student_performance_on_sequence { my $resource_data = $studentdata->{$symb}; foreach my $part (@{$resource->parts()}) { $partscore = undef; - my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight', - $symb, - $student->{'domain'}, - $student->{'username'}, - $student->{'section'}); + my $weight; + if (!$awarded_only){ + $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight', + $symb, + $student->{'domain'}, + $student->{'username'}, + $student->{'section'}); + } if (!defined($weight) || ($weight eq '')) { $weight=1; } @@ -1942,13 +1954,19 @@ sub student_performance_on_sequence { if (length($symbol) > 1) { $symbol = '*'; } - if (exists($resource_data->{'resource.'.$part.'.solved'})) { + if (exists($resource_data->{'resource.'.$part.'.solved'}) && + $resource_data->{'resource.'.$part.'.solved'} ne '') { my $status = $resource_data->{'resource.'.$part.'.solved'}; if ($status eq 'excused') { $symbol = 'x'; $max -= $weight; # Do not count 'excused' problems. + } elsif ($status eq 'ungraded_attempted') { + $symbol = 'u'; } $hasdata = 1; + } elsif ($resource_data->{'resource.'.$part.'.award'} eq 'DRAFT') { + $symbol = 'd'; + $hasdata = 1; } elsif (!exists($resource_data->{'resource.'.$part.'.awarded'})){ # Unsolved. Did they try? if (exists($resource_data->{'resource.'.$part.'.tries'})){ @@ -1997,13 +2015,13 @@ problems. ####################################################### sub CreateLegend { my $Str = "

".
-              "   1  correct by student in 1 try\n".
-              "   7  correct by student in 7 tries\n".
+              " digit score or number of tries to get correct ".
               "   *  correct by student in more than 9 tries\n".
 	      "   +  correct by hand grading or override\n".
               "   -  incorrect by override\n".
 	      "   .  incorrect attempted\n".
-	      "   #  ungraded attempted\n".
+	      "   u  ungraded attempted\n".
+              "   d  draft answer saved but not submitted\n".
               "      not attempted (blank field)\n".
 	      "   x  excused".
               "

";