--- loncom/interface/spreadsheet/assesscalc.pm 2003/12/05 22:24:20 1.17.2.3 +++ loncom/interface/spreadsheet/assesscalc.pm 2003/09/09 18:46:28 1.20 @@ -1,5 +1,5 @@ # -# $Id: assesscalc.pm,v 1.17.2.3 2003/12/05 22:24:20 matthew Exp $ +# $Id: assesscalc.pm,v 1.20 2003/09/09 18:46:28 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,11 +44,12 @@ assesscalc package Apache::assesscalc; use strict; +use warnings FATAL=>'all'; +no warnings 'uninitialized'; use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::loncommon; use Apache::Spreadsheet; -use Apache::loncoursedata(); use HTML::Entities(); use Spreadsheet::WriteExcel; use GDBM_File; @@ -126,7 +127,6 @@ sub clear_package { sub initialize { &clear_package(); - &Apache::loncoursedata::clear_internal_caches(); } ######################################################## @@ -150,7 +150,6 @@ sub initialize_package { } &load_cached_export_rows(); &load_parameter_caches(); - &Apache::loncoursedata::clear_internal_caches(); } ######################################################## @@ -170,7 +169,6 @@ sub load_parameter_caches { # # Course Parameters Cache if (! %courseopt) { - &Apache::lonnet::logthis("loading course options"); $current_course = $ENV{'request.course.id'}; undef(%courseopt); if (! defined($current_name) || ! defined($current_domain)) { @@ -210,11 +208,17 @@ sub load_parameter_caches { ######################################################## sub ensure_current_parameter_caches { my $self = shift; + ## + ## Check for a modified parameters + ## if (! defined($current_course) || $current_course ne $ENV{'request.course.id'} ) { $current_course = $ENV{'request.course.id'}; undef(%courseopt); } + ## + ## Check for new user + ## if (! defined($current_name) || $current_name ne $self->{'name'} || ! defined($current_domain) || $current_domain ne $self->{'domain'}) { $current_domain = $self->{'domain'}; @@ -259,7 +263,7 @@ sub parmval { my $result=''; # # This should be a - my ($mapname,$id,$fn)=split(/___/,$symb); + my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb); # Cascading lookup scheme my $rwhat=$what; $what =~ s/^parameter\_//; @@ -374,10 +378,6 @@ sub parent_link { sub outsheet_html { my $self = shift; my ($r) = @_; - #################################### - # Report any calculation errors # - #################################### - $r->print($self->html_report_error()); ################################### # Determine table structure ################################### @@ -524,6 +524,9 @@ sub excel_rows { sub compute { my $self = shift; + my ($r) = @_; + my $connection = $r->connection(); + if ($connection->aborted()) { $self->cleanup(); return; } # $self->logthis('computing'); $self->initialize_safe_space(); ######################################### @@ -545,7 +548,7 @@ sub compute { my %parameters; # holds underscored parameters by name # # Get the metadata fields and determine their proper names - my ($symap,$syid,$srcf)=split(/___/,$self->{'symb'}); + my ($symap,$syid,$srcf)=&Apache::lonnet::decode_symb($self->{'symb'}); my @Metadata = split(/\,/,&Apache::lonnet::metadata($srcf,'keys')); foreach my $parm (@Mandatory_parameters,@Metadata) { next if ($parm !~ /^(resource\.|stores|parameter)_/); @@ -562,7 +565,9 @@ sub compute { } # # Get the values of the metadata fields + if ($connection->aborted()) { $self->cleanup(); return; } $self->ensure_current_parameter_caches(); + if ($connection->aborted()) { $self->cleanup(); return; } my $filename = $self->{'coursefilename'}.'_parms.db'; if (tie(%parmhash,'GDBM_File', $self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) { @@ -574,6 +579,7 @@ sub compute { } else { $self->logthis('unable to tie '.$filename); } + if ($connection->aborted()) { $self->cleanup(); return; } # # Clean out unnecessary parameters foreach (keys(%parameters)) { @@ -601,18 +607,17 @@ sub compute { while (my ($parm,$value) = each(%parameters)) { last if ($self->blackout()); next if ($parm !~ /^(parameter_.*)_problemstatus$/); - if ($parameters{$1.'_answerdate'} ne '' && - $parameters{$1.'_answerdate'} < time) { - next; - } + next if ($parameters{$1.'_answerdate'}blackout(1); } } } + if ($connection->aborted()) { $self->cleanup(); return; } # # Move the parameters into the spreadsheet + if ($connection->aborted()) { $self->cleanup(); return; } while (my ($parm,$value) = each(%parameters)) { my $cell = 'A'.$self->get_row_number_from_key($parm); $f{$cell} = $parm; @@ -621,6 +626,7 @@ sub compute { } $self->formulas(\%f); $self->constants(\%c); + if ($connection->aborted()) { $self->cleanup(); return; } $self->calcsheet(); # # Store export row in cache @@ -631,6 +637,7 @@ sub compute { # Save the export data $self->save_export_data(); $self->save() if ($self->need_to_save()); + if ($connection->aborted()) { $self->cleanup(); return; } return; } @@ -699,7 +706,7 @@ These rows are saved in the students dir ######################################################## ######################################################## sub load_cached_export_rows { - %Exportrows = undef; + undef(%Exportrows); my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'. $ENV{'request.course.id'}, $current_domain,$current_name,undef); @@ -740,28 +747,26 @@ spreadsheet only if necessary. ############################################# sub export_data { my $self = shift; + my ($r) = @_; + my $connection = $r->connection(); my $symb = $self->{'symb'}; if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} || ! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) || ! $self->check_expiration_time($Exportrows{$symb}->{'time'}) || ! exists($Exportrows{$symb}->{$self->{'filename'}}) || - ! defined($Exportrows{$symb}->{$self->{'filename'}})) { - $self->compute(); + ! defined($Exportrows{$symb}->{$self->{'filename'}}) || + ! ref($Exportrows{$symb}->{$self->{'filename'}}) + ) { + $self->compute($r); + } + if ($connection->aborted()) { $self->cleanup(); return; } + my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}}; + if ($Data[0] =~ /^(.*)___=___/) { + $self->{'sheetname'} = $1; + $Data[0] =~ s/^(.*)___=___//; } - my @Data; - if ($self->badcalc()) { - @Data = (); - } else { - @Data = @{$Exportrows{$symb}->{$self->{'filename'}}}; - if ($Data[0] =~ /^(.*)___=___/) { - $self->{'sheetname'} = $1; - $Data[0] =~ s/^(.*)___=___//; - } - for (my $i=0;$i<$#Data;$i++) { - if ($Data[$i]=~/\D/ && defined($Data[$i])) { - $Data[$i]="'".$Data[$i]."'"; - } - } + for (my $i=0;$i<$#Data;$i++) { + $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i])); } return @Data; } @@ -784,11 +789,6 @@ sub save_export_data { return if ($self->temporary()); my $student = $self->{'name'}.':'.$self->{'domain'}; my $symb = $self->{'symb'}; - if ($self->badcalc()){ - # do not save data away when calculations have not been done properly. - delete($Exportrows{$symb}); - return; - } if (! exists($Exportrows{$symb}) || ! exists($Exportrows{$symb}->{$self->{'filename'}})) { return;