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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 30 Jan 2003 16:20:08 -0000


This is a MIME encoded message

--matthew1043943608
Content-Type: text/plain

matthew		Thu Jan 30 11:20:08 2003 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Changed A_column() to rows() since that is what it was used for anyway.
  
  
--matthew1043943608
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030130112008.txt"

Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.164 loncom/interface/lonspreadsheet.pm:1.165
--- loncom/interface/lonspreadsheet.pm:1.164	Wed Jan 29 11:26:08 2003
+++ loncom/interface/lonspreadsheet.pm	Thu Jan 30 11:20:08 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.164 2003/01/29 16:26:08 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.165 2003/01/30 16:20:08 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -487,6 +487,8 @@
 use HTML::Entities();
 use HTML::TokeParser;
 use Spreadsheet::WriteExcel;
+use Time::HiRes;
+
 #
 # These global hashes are dependent on user, course and resource, 
 # and need to be initialized every time when a sheet is calculated
@@ -756,7 +758,7 @@
         chome => $ENV{'course.'.$ENV{'request.course.id'}.'.home'},
         coursefilename => $ENV{'request.course.fn'},
         coursedesc => $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
-        A_column       => [],
+        rows       => [],
         template_cells => [],
         };
     $self->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom);
@@ -1583,12 +1585,10 @@
         $pattern='[A-Z]';
     }
     # Deal with the template row
-    foreach ($self->template_cells()) {
-        my ($col) = ($_=~/template\_(\w)/);
+    foreach my $col ($self->template_cells()) {
         next if ($col=~/^$pattern/);
-        foreach ($self->A_column()) {
-            my ($trow)=($_!~/A(\d+)/);
-            next if (! $trow);
+        foreach my $trow ($self->rows()) {
+            next if ($trow eq '0');
             # Get the name of this cell
             my $lb=$col.$trow;
             # Grab the template declaration
@@ -1745,8 +1745,6 @@
     $self->sett();
     my $result =  $self->{'safe'}->reval('&calc();');
     %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
-#    $self->logthis($self->get_errorlog());
-#    $self->logthis('number of values = '.(keys(%{$self->{'values'}})));
     return $result;
 }
 
@@ -1787,8 +1785,8 @@
 #### Spreadsheet content retrieval/setting methods #####
 ########################################################
 ##
-## contents:  either set or get the constants.  Cannot do both.  It is just too
-## clunky to swing around big hashes when we may not need to.
+## constants:  either set or get the constants
+##
 ##
 sub constants {
     my $self=shift;
@@ -1806,8 +1804,8 @@
 }
     
 ##
-## formulas: either set or get the formulas.  Cannot do both.  It is just too
-## clunky to swing around big hashes when we may not need to.
+## formulas: either set or get the formulas
+##
 sub formulas {
     my $self=shift;
     my ($formulas) = @_;
@@ -1817,7 +1815,7 @@
             $formulas = \%tmp;
         }
         $self->{'formulas'} = $formulas;
-        $self->{'A_column'} = [];
+        $self->{'rows'} = [];
         $self->{'template_cells'} = [];
         return;
     } else {
@@ -1831,7 +1829,6 @@
 sub formulas_keys {
     my $self = shift;
     my @keys = keys(%{$self->{'formulas'}});
-#    $self->logthis('formulas keys has '.@keys.' elements');
     return keys(%{$self->{'formulas'}});
 }
 
@@ -1857,6 +1854,7 @@
     &Apache::lonnet::logthis($self->{'type'}.':'.
                              $self->{'uname'}.':'.$self->{'udom'}.':'.
                              $message);
+    return;
 }
 
 ##
@@ -1899,18 +1897,16 @@
 ##      Helper functions      ##
 ################################
 ##
-## rebuild_stats: rebuilds the A_column and template_cells arrays
+## rebuild_stats: rebuilds the rows and template_cells arrays
 ##
 sub rebuild_stats {
     my $self = shift;
-    $self->{'A_column'}=[];
+    $self->{'rows'}=[];
     $self->{'template_cells'}=[];
     foreach my $cell($self->formulas_keys()) {
-        push(@{$self->{'A_column'}},$cell) if $cell =~ /^A\d+/;
-        push(@{$self->{'template_cells'}},$cell) if ($cell =~ /^template_/);
+        push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/);
+        push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
     }
-    # $self->logthis('rebuilt A_column '.@{$self->{'A_column'}});
-    # $self->logthis('rebuilt tempate_cells '.@{$self->{'template_cells'}});
     return;
 }
 
@@ -1924,12 +1920,12 @@
 }
 
 ##
-## A_column returns a list of the names of cells defined in the A column
+## rows returns a list of the names of cells defined in the A column
 ##
-sub A_column {
+sub rows {
     my $self = shift;
-    $self->rebuild_stats() if (!@{$self->{'A_column'}});
-    return @{$self->{'A_column'}};
+    $self->rebuild_stats() if (!@{$self->{'rows'}});
+    return @{$self->{'rows'}};
 }
 
 ##
@@ -2673,8 +2669,6 @@
     if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
         my %tmp = split(/___;___/,$fstring);
         $self->formulas(\%tmp);
-#        $self->logthis('readsheet found cached ');
-#        $self->dump_formulas_to_log();
     } else {
         # Not cached, need to read
         my %f=();
@@ -2725,8 +2719,6 @@
         # Cache and set
         $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);  
         $self->formulas(\%f);
-#        $self->logthis('readsheet loaded ');
-#        $self->dump_formulas_to_log();
     }
 }
 
@@ -2950,13 +2942,13 @@
     my %existing=();
     #
     # Now obsolete rows
-    foreach my $cell ($self->A_column()) {
-        $cell =~ /^A(\d+)/;
-        if ($1 > $self->{'maxrow'}) {
-            $self->{'maxrow'}= $1;
+    foreach my $rownum ($self->rows()) {
+        my $cell = 'A'.$rownum;
+        if ($rownum > $self->{'maxrow'}) {
+            $self->{'maxrow'}= $rownum;
         }
         $existing{$f{$cell}}=1;
-        unless ((defined($currentlist{$f{$cell}})) || (!$1) ||
+        unless ((defined($currentlist{$f{$cell}})) || ($rownum ne '0') ||
                 ($f{$cell}=~/^(~~~|---)/)) {
             $f{$cell}='!!! Obsolete';
             $changed=1;
@@ -3104,11 +3096,11 @@
     $self->{'maxrow'} = 0;
     my %existing=();
     # Now obsolete rows
-    foreach my $cell ($self->A_column()) {
+    foreach my $rownum ($self->rows()) {
+        my $cell = 'A'.$rownum;
         my $formula = $f{$cell};
-        my ($n)= ($cell =~ /A(\d+)/);
-        next if ($n eq '0');
-        $self->{'maxrow'} = $n if ($n > $self->{'maxrow'});
+        next if ($rownum eq '0');
+        $self->{'maxrow'} = $rownum if ($rownum > $self->{'maxrow'});
         my ($usy,$ufn)=split(/__&&&\__/,$formula);
         $existing{$usy}=1;
         if ( ! exists($self->{'rowlabel'}->{$usy})  ||
@@ -3116,7 +3108,6 @@
              ($formula =~ /^(~~~|---)/) ||
              ($formula =~ /^\s*$/)) {
             $f{$cell}='!!! Obsolete';
-#            $self->logthis('obsoleted row '.$n);
             $changed=1;
         }
     }
@@ -3150,12 +3141,12 @@
     undef @tmp;
     # 
     my @assessdata=();
-    foreach my $cell ($self->A_column()) {
+    foreach my $row ($self->rows()) {
+        my $cell = 'A'.$row;
         my $value = $formulas{$cell};
         if(defined($c) && ($c->aborted())) {
             last;
         }
-        my ($row)=($cell=~/A(\d+)/);
         next if (($value =~ /^[!~-]/) || ($row==0));
         my ($usy,$ufn)=split(/__&&&\__/,$value);
         @assessdata=$self->exportsheet($self->{'uname'},
@@ -3191,8 +3182,8 @@
     my %formulas=$self->formulas();
     #
     my $total=0;
-    foreach ($self->A_column()) {
-        $total++ if ($formulas{$_} !~ /^[!~-]/);
+    foreach ($self->rows()) {
+        $total++ if ($formulas{'A'.$_} !~ /^[!~-]/);
     }
     my $now=0;
     my $since=time;
@@ -3208,13 +3199,13 @@
 </script>
 ENDPOP
     $r->rflush();
-    foreach ($self->A_column()) {
+    foreach my $row ($self->rows()) {
         if(defined($c) && ($c->aborted())) {
             last;
         }
-        my ($row)=(/A(\d+)/);
-        next if (($formulas{$_}=~/^[\!\~\-]/)  || ($row==0));
-        my ($sname,$sdom) = split(':',$formulas{$_});
+        my $cell = 'A'.$row;
+        next if (($formulas{$cell}=~/^[\!\~\-]/)  || ($row==0));
+        my ($sname,$sdom) = split(':',$formulas{$cell});
         my $started = time;
         my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc',
                                      undef,undef,$r);
@@ -3342,7 +3333,8 @@
     if (tie(%parmhash,'GDBM_File',
             $self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
         my %f=$self->formulas();
-        foreach my $cell ($self->A_column())  {
+        foreach my $row ($self->rows())  {
+            my $cell = 'A'.$row;
             my $formula = $self->formula($cell);
             next if ($formula =~/^[\!\~\-]/);
             if ($formula =~ /^parameter/) {

--matthew1043943608--