[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm assesscalc.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 13 May 2005 21:14:46 -0000


albertel		Fri May 13 17:14:46 2005 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm assesscalc.pm 
  Log:
  - minimizing the number of elments in %t, and moving sheet_values to be out int Spreadsheet not in the safe space (student level sheet not taking aroun 0.5 seconds to compute)
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.45 loncom/interface/spreadsheet/Spreadsheet.pm:1.46
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.45	Fri May 13 11:59:07 2005
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Fri May 13 17:14:46 2005
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.45 2005/05/13 15:59:07 albertel Exp $
+# $Id: Spreadsheet.pm,v 1.46 2005/05/13 21:14:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -330,6 +330,10 @@
       $safehole->wrap(\&mask,$safeeval,'&mask');
       $safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&logthis');
       $safeeval->share('$@');
+    # Holds the (computed, final) values for the sheet
+    # This is only written to by &calc, the spreadsheet computation routine.
+    # It is read by many functions
+      $safeeval->share('%sheet_values');
       my $code=<<'ENDDEFS';
 # ---------------------------------------------------- Inside of the safe space
 #
@@ -339,12 +343,9 @@
 # c: preloaded constants (A-column)
 # rl: row label
 # os: other spreadsheets (for student spreadsheet only)
-undef %sheet_values;   # Holds the (computed, final) values for the sheet
-    # This is only written to by &calc, the spreadsheet computation routine.
-    # It is read by many functions
-undef %t; # Holds the values of the spreadsheet temporarily. Set in &sett, 
-    # which does the translation of strings like C5 into the value in C5.
-    # Used in &calc - %t holds the values that are actually eval'd.
+undef %t; # Holds the forumlas of the spreadsheet to be computed. Set in
+    # &sett, which does the translation of strings like C5 into the value
+    # in C5. Used in &calc - %t holds the values that are actually eval'd.
 undef %f;    # Holds the formulas for each cell.  This is the users
     # (spreadsheet authors) data for each cell.
 undef %c; # Holds the constants for a sheet.  In the assessment
@@ -729,7 +730,6 @@
 }
 
 sub calc {
-    %sheet_values = %t;
     my $notfinished = 1;
     my $lastcalc = '';
     my $depth = 0;
@@ -869,6 +869,7 @@
 sub sett {
     my $self = shift;
     my %t=();
+    undef(%Apache::Spreadsheet::sheet_values);
     #
     # Deal with the template row
     foreach my $col ($self->template_cells()) {
@@ -901,8 +902,8 @@
         } elsif  ( $col  =~ /^[A-Z]$/  ) {
             if ($formula !~ /^\!/ && exists($self->{'constants'}->{$cell})
 		&& $self->{'constants'}->{$cell} ne '') {
-                my $data = $self->{'constants'}->{$cell};
-                $t{$cell} = $data;
+		$Apache::Spreadsheet::sheet_values{$cell}=
+		    eval($self->{'constants'}->{$cell});
             }
         } else { # $row > 1 and $col =~ /[a-z]
             $t{$cell}=$formula;
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.39 loncom/interface/spreadsheet/assesscalc.pm:1.40
--- loncom/interface/spreadsheet/assesscalc.pm:1.39	Thu Apr  7 02:56:23 2005
+++ loncom/interface/spreadsheet/assesscalc.pm	Fri May 13 17:14:46 2005
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.39 2005/04/07 06:56:23 albertel Exp $
+# $Id: assesscalc.pm,v 1.40 2005/05/13 21:14:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -814,6 +814,7 @@
 sub sett {
     my $self = shift;
     my %t=();
+    undef(%Apache::Spreadsheet::sheet_values);
     #
     # Deal with the template row by copying the template formulas into each
     # row.
@@ -840,7 +841,8 @@
 	next if ($cell =~ /template_/);
         if ($cell =~ /^A/ && $cell ne 'A0') {
             if ($formula !~ /^\!/) {
-                $t{$cell}=$self->{'constants'}->{$formula};
+		$Apache::Spreadsheet::sheet_values{$cell}=
+		    eval($self->{'constants'}->{$formula});
             }
         } else {
             $t{$cell}=$formula;