--- loncom/interface/statistics/lonstudentassessment.pm 2005/04/19 01:28:25 1.124 +++ loncom/interface/statistics/lonstudentassessment.pm 2006/01/22 21:11:59 1.127 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentassessment.pm,v 1.124 2005/04/19 01:28:25 matthew Exp $ +# $Id: lonstudentassessment.pm,v 1.127 2006/01/22 21:11:59 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -622,17 +622,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)) { @@ -856,7 +860,7 @@ sub html_finish { } $r->rflush(); &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - undef($navmap); + &html_cleanup(); return; } @@ -963,8 +967,7 @@ my %formula_data; my $navmap; my @sequences; -sub excel_initialize { - my ($r) = @_; +sub excel_cleanup { # undef ($excel_sheet); undef ($excel_workbook); @@ -980,6 +983,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)) { @@ -1135,9 +1144,11 @@ sub excel_initialize { ! defined($formula_data{$symb}->{'Excel:endcell'})) { $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'}; } + # =IF(COUNT(B31:L31);SUM(B31:L31);"") + 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 @@ -1246,7 +1257,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); @@ -1402,8 +1413,9 @@ sub excel_outputstudent { 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 { @@ -1429,7 +1441,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++; @@ -1465,14 +1477,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); @@ -1481,6 +1491,7 @@ sub excel_finish { $r->print('
'. 'Your Excel spreadsheet.'."\n"); $r->rflush(); + &excel_cleanup(); return; } @@ -1511,10 +1522,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); @@ -1522,6 +1530,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)) { @@ -1707,13 +1721,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); # @@ -1721,6 +1733,7 @@ sub csv_finish { $r->print('
'. ''.&mt('Your csv file.').''."\n"); $r->rflush(); + &csv_cleanup(); return; }