--- loncom/interface/spreadsheet/studentcalc.pm 2003/12/05 22:24:20 1.16.2.1 +++ loncom/interface/spreadsheet/studentcalc.pm 2003/09/08 18:25:26 1.19 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.16.2.1 2003/12/05 22:24:20 matthew Exp $ +# $Id: studentcalc.pm,v 1.19 2003/09/08 18:25:26 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,6 +45,9 @@ studentcalc ################################################### package Apache::studentcalc; +use warnings FATAL=>'all'; +no warnings 'uninitialized'; + use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; @@ -98,8 +101,9 @@ sub initialize_sequence_cache { } sub clear_package { - @Sequences = undef; - %Exportrows = undef; + undef(@Sequences); + undef(%Exportrows); + &Apache::assesscalc::clear_package(); } sub get_title { @@ -125,7 +129,7 @@ sub get_html_title { my $title = '

'.$name; if ($ENV{'user.name'} ne $self->{'name'} && $ENV{'user.domain'} ne $self->{'domain'}) { - $title .= &Apache::loncommon::aboutmewrapper + $title .= ' '.&Apache::loncommon::aboutmewrapper ($self->{'name'}.'@'.$self->{'domain'}, $self->{'name'},$self->{'domain'}); } @@ -174,10 +178,6 @@ sub outsheet_html { my $editing_is_allowed = &Apache::lonnet::allowed('mgr', $ENV{'request.course.id'}); #################################### - # Report any calculation errors # - #################################### - $r->print($self->html_report_error()); - #################################### # Determine table structure # #################################### my $num_uneditable = 26; @@ -415,6 +415,9 @@ sub outsheet_recursive_excel { sub compute { my $self = shift; + my ($r) = @_; + my $connection = $r->connection(); + if ($connection->aborted()) { $self->cleanup; return; } if (! defined($current_course) || $current_course ne $ENV{'request.course.id'}) { $current_course = $ENV{'request.course.id'}; @@ -441,6 +444,7 @@ sub compute { foreach my $seq (@sequences) { next if ($seq->{'num_assess'}<1); foreach my $resource (@{$seq->{'contents'}}) { + if ($connection->aborted()) { $self->cleanup(); return; } next if ($resource->{'type'} ne 'assessment'); my $rownum = $self->get_row_number_from_key($resource->{'symb'}); my $cell = 'A'.$rownum; @@ -451,17 +455,13 @@ sub compute { $self->{'row_source'}->{$rownum} = $assess_filename; } $f{$cell} = $resource->{'symb'}.'__&&&__'.$assess_filename; + if ($connection->aborted()) { $self->cleanup(); return; } my $assessSheet = Apache::assesscalc->new($self->{'name'}, $self->{'domain'}, $assess_filename, $resource->{'symb'}); - my @exportdata = $assessSheet->export_data(); - if ($assessSheet->badcalc()) { - $self->set_calcerror( - 'Error computing row for assessment '. - $assessSheet->get_title().'(row '.$rownum.'):'. - $assessSheet->calcerror()); - } + my @exportdata = $assessSheet->export_data($r); + if ($connection->aborted()) { $self->cleanup(); return; } if ($assessSheet->blackout()) { $self->blackout(1); $self->{'blackout_rows'}->{$rownum} = 1; @@ -503,7 +503,7 @@ sub compute { sub set_row_sources { my $self = shift; while (my ($cell,$value) = each(%{$self->{'formulas'}})) { - next if ($cell !~ /^A(\d+)/ && $1 > 0); + next if ($cell !~ /^A(\d+)$/ || $1 < 1); my $row = $1; (undef,$value) = split('__&&&__',$value); $value = 'Default' if (! defined($value)); @@ -520,7 +520,7 @@ sub set_row_numbers { next if ($row == 0); my ($symb,undef) = split('__&&&__',$formula); $self->{'row_numbers'}->{$symb} = $row; - $self->{'maxrow'} = $1 if ($1 > $self->{'maxrow'}); + $self->{'maxrow'} = $row if ($row > $self->{'maxrow'}); } } @@ -550,7 +550,7 @@ These rows are saved in the courses dire ############################################# ############################################# sub load_cached_export_rows { - %Exportrows = undef; + undef(%Exportrows); my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets', $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'},undef); @@ -591,11 +591,6 @@ sub save_export_data { my $self = shift; return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; - if ($self->badcalc()){ - # do not save data away when calculations have not been done properly. - delete($Exportrows{$student}); - return; - } return if (! exists($Exportrows{$student})); return if (! $self->is_default()); my $key = join(':',($self->{'name'},$self->{'domain'},'studentcalc')).':'; @@ -627,6 +622,8 @@ spreadsheet only if necessary. ############################################# sub export_data { my $self = shift; + my ($r) = @_; + my $connection = $r->connection(); my $student = $self->{'name'}.':'.$self->{'domain'}; if (! exists($Exportrows{$student}) || ! defined($Exportrows{$student}) || @@ -635,18 +632,12 @@ sub export_data { ! exists($Exportrows{$student}->{'time'}) || ! defined($Exportrows{$student}->{'time'}) || ! $self->check_expiration_time($Exportrows{$student}->{'time'})) { - $self->compute(); + $self->compute($r); } - my @Data; - if ($self->badcalc()) { - @Data = (); - } else { - @Data = @{$Exportrows{$student}->{'data'}}; - for (my $i=0; $i<=$#Data;$i++) { - if ($Data[$i]=~/\D/ && defined($Data[$i])) { - $Data[$i]="'".$Data[$i]."'"; - } - } + if ($connection->aborted()) { $self->cleanup(); return; } + my @Data = @{$Exportrows{$student}->{'data'}}; + for (my $i=0; $i<=$#Data;$i++) { + $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i])); } return @Data; }