--- loncom/interface/Attic/lonspreadsheet.pm 2002/11/12 22:44:28 1.139 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/11/15 18:19:10 1.140 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.139 2002/11/12 22:44:28 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.140 2002/11/15 18:19:10 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,16 +53,16 @@ built-in functions. package Apache::lonspreadsheet; use strict; +use Apache::Constants qw(:common :http); +use Apache::lonnet; +use Apache::lonhtmlcommon; +use Apache::loncoursedata; +use Apache::File(); use Safe; use Safe::Hole; use Opcode; -use Apache::lonnet; -use Apache::Constants qw(:common :http); use GDBM_File; use HTML::TokeParser; -use Apache::lonhtmlcommon; -use Apache::loncoursedata; -use Apache::File(); use Spreadsheet::WriteExcel; # @@ -1149,7 +1149,7 @@ sub exportdata { sub update_student_sheet{ - my $sheet = shift; + my ($sheet,$c) = @_; # Load in the studentcalc sheet &readsheet($sheet,'default_studentcalc'); # Determine the structure (contained assessments, etc) of the sheet @@ -1157,7 +1157,7 @@ sub update_student_sheet{ # Load in the cached sheets for this student &cachedssheets($sheet); # Load in the (possibly cached) data from the assessment sheets - &loadstudent($sheet); + &loadstudent($sheet,$c); # Compute the sheet &calcsheet($sheet); } @@ -1496,7 +1496,7 @@ END # Create a new spreadsheet my $studentsheet = &makenewsheet($sname,$sdom,'studentcalc',undef); # Read in the spreadsheet definition - &update_student_sheet($studentsheet); + &update_student_sheet($studentsheet,$c); # Stuff the sheet into excel &export_sheet_as_excel($studentsheet,$student_excel_worksheet); my $totaltime = int((time - $starttime) / $count * $sheet->{'maxrow'}); @@ -2296,9 +2296,9 @@ sub updatestudentassesssheet { # ------------------------------------------------ Load data for one assessment sub loadstudent{ - my ($sheet)=@_; - my %c=(); - my %f=&getformulas($sheet); + my ($sheet,$r,$c)=@_; + my %constants=(); + my %formulas=&getformulas($sheet); $cachedassess=$sheet->{'uname'}.':'.$sheet->{'udom'}; # Get ALL the student preformance data my @tmp = &Apache::lonnet::dump($sheet->{'cid'}, @@ -2311,26 +2311,29 @@ sub loadstudent{ undef @tmp; # my @assessdata=(); - while (my ($cell,$value) = each (%f)) { + while (my ($cell,$value) = each (%formulas)) { + if(defined($c) && ($c->aborted())) { + last; + } next if ($cell !~ /^A(\d+)/); my $row=$1; next if (($value =~ /^[!~-]/) || ($row==0)); my ($usy,$ufn)=split(/__&&&\__/,$value); @assessdata=&exportsheet($sheet,$sheet->{'uname'}, $sheet->{'udom'}, - 'assesscalc',$usy,$ufn); + 'assesscalc',$usy,$ufn,$r); my $index=0; foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') { if (defined($assessdata[$index])) { my $col=$_; if ($assessdata[$index]=~/\D/) { - $c{$col.$row}="'".$assessdata[$index]."'"; + $constants{$col.$row}="'".$assessdata[$index]."'"; } else { - $c{$col.$row}=$assessdata[$index]; + $constants{$col.$row}=$assessdata[$index]; } unless ($col eq 'A') { - $f{$col.$row}='import'; + $formulas{$col.$row}='import'; } } $index++; @@ -2338,23 +2341,23 @@ sub loadstudent{ } $cachedassess=''; undef %cachedstores; - $sheet->{'f'} = \%f; + $sheet->{'f'} = \%formulas; &setformulas($sheet); - &setconstants($sheet,\%c); + &setconstants($sheet,\%constants); } # --------------------------------------------------- Load data for one student # sub loadcourse { - my ($sheet,$r)=@_; + my ($sheet,$r,$c)=@_; # - my %c=(); - my %f=&getformulas($sheet); + my %constants=(); + my %formulas=&getformulas($sheet); # my $total=0; - foreach (keys(%f)) { + foreach (keys(%formulas)) { if ($_=~/^A(\d+)/) { - unless ($f{$_}=~/^[\!\~\-]/) { $total++; } + unless ($formulas{$_}=~/^[\!\~\-]/) { $total++; } } } my $now=0; @@ -2371,12 +2374,16 @@ sub loadcourse { ENDPOP $r->rflush(); - foreach (keys(%f)) { + foreach (keys(%formulas)) { + if(defined($c) && ($c->aborted())) { + last; + } next if ($_!~/^A(\d+)/); my $row=$1; - next if (($f{$_}=~/^[\!\~\-]/) || ($row==0)); - my ($sname,$sdom) = split(':',$f{$_}); - my @studentdata=&exportsheet($sheet,$sname,$sdom,'studentcalc'); + next if (($formulas{$_}=~/^[\!\~\-]/) || ($row==0)); + my ($sname,$sdom) = split(':',$formulas{$_}); + my @studentdata=&exportsheet($sheet,$sname,$sdom,'studentcalc', + undef,undef,$r); undef %userrdatas; $now++; $r->print(''); $r->rflush(); } @@ -2411,7 +2418,7 @@ ENDPOP # ------------------------------------------------ Load data for one assessment # sub loadassessment { - my ($sheet)=@_; + my ($sheet,$r,$c)=@_; my $uhome = $sheet->{'uhome'}; my $uname = $sheet->{'uname'}; @@ -2575,13 +2582,14 @@ sub updatesheet { sub loadrows { my ($sheet,$r)=@_; + my $c = $r->connection; my $stype=$sheet->{'sheettype'}; if ($stype eq 'classcalc') { - &loadcourse($sheet,$r); + &loadcourse($sheet,$r,$c); } elsif ($stype eq 'studentcalc') { - &loadstudent($sheet); + &loadstudent($sheet,$r,$c); } else { - &loadassessment($sheet); + &loadassessment($sheet,$r,$c); } } @@ -2622,7 +2630,7 @@ sub forcedrecalc { # returns the export row for a spreadsheet. # sub exportsheet { - my ($sheet,$uname,$udom,$stype,$usymb,$fn)=@_; + my ($sheet,$uname,$udom,$stype,$usymb,$fn,$r)=@_; $uname = $uname || $sheet->{'uname'}; $udom = $udom || $sheet->{'udom'}; $stype = $stype || $sheet->{'sheettype'}; @@ -2676,7 +2684,7 @@ sub exportsheet { my ($newsheet)=&makenewsheet($uname,$udom,$stype,$usymb); &readsheet($newsheet,$fn); &updatesheet($newsheet); - &loadrows($newsheet); + &loadrows($newsheet,$r); &calcsheet($newsheet); @exportarr=&exportdata($newsheet); ## @@ -2742,7 +2750,7 @@ sub load_spreadsheet_expirationdates { my @tmp = &Apache::lonnet::dump('nohist_expirationdates', $ENV{'course.'.$cid.'.domain'}, $ENV{'course.'.$cid.'.num'}); - if (lc($tmp[0])!~/^error/){ + if (lc($tmp[0]) !~ /^error/){ %expiredates = @tmp; } } @@ -3110,7 +3118,7 @@ ENDSCRIPT if ($sheet->{'sheettype'} eq 'studentcalc') { $r->print('

Show rows with empty A column: '); } else { - $r->print('

>Show empty rows: '); + $r->print('

Show empty rows: '); } # $r->print(&hiddenfield('userselhidden','true').