[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 15 Nov 2002 18:19:10 -0000


This is a MIME encoded message

--matthew1037384350
Content-Type: text/plain

matthew		Fri Nov 15 13:19:10 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Added checks to determine connection status with browser so we can abort
  the computations if no one will see the resulting spreadsheet.
  
  
--matthew1037384350
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20021115131910.txt"

Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.139 loncom/interface/lonspreadsheet.pm:1.140
--- loncom/interface/lonspreadsheet.pm:1.139	Tue Nov 12 17:44:28 2002
+++ loncom/interface/lonspreadsheet.pm	Fri Nov 15 13:19:10 2002
@@ -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 @@
 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 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 @@
     # 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 @@
         # 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 @@
 # ------------------------------------------------ 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 @@
     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 @@
     }
     $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 @@
 </script>
 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('<script>popwin.document.popremain.remaining.value="'.
@@ -2390,20 +2397,20 @@
             if (defined($studentdata[$index])) {
                 my $col=$_;
                 if ($studentdata[$index]=~/\D/) {
-                    $c{$col.$row}="'".$studentdata[$index]."'";
+                    $constants{$col.$row}="'".$studentdata[$index]."'";
                 } else {
-                    $c{$col.$row}=$studentdata[$index];
+                    $constants{$col.$row}=$studentdata[$index];
                 }
                 unless ($col eq 'A') { 
-                    $f{$col.$row}='import';
+                    $formulas{$col.$row}='import';
                 }
             } 
             $index++;
         }
     }
-    $sheet->{'f'}=\%f;
+    $sheet->{'f'}=\%formulas;
     &setformulas($sheet);
-    &setconstants($sheet,\%c);
+    &setconstants($sheet,\%constants);
     $r->print('<script>popwin.close()</script>');
     $r->rflush(); 
 }
@@ -2411,7 +2418,7 @@
 # ------------------------------------------------ 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 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 @@
 # 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 @@
     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 @@
     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 @@
     if ($sheet->{'sheettype'} eq 'studentcalc') {
         $r->print('<p>Show rows with empty A column: ');
     } else {
-        $r->print('<p>>Show empty rows: ');
+        $r->print('<p>Show empty rows: ');
     }
     #
     $r->print(&hiddenfield('userselhidden','true').

--matthew1037384350--