Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.165 and 1.174

version 1.165, 2003/01/30 16:20:08 version 1.174, 2003/03/07 04:20:20
Line 262  ENDSCRIPT Line 262  ENDSCRIPT
     # Global directory configs      # Global directory configs
     #      #
     $sheet->includedir($r->dir_config('lonIncludes'));      $sheet->includedir($r->dir_config('lonIncludes'));
     $sheet->tmpdir($r->dir_config('lonDaemons').'/tmp/');  
     #      #
     # Check user permissions      # Check user permissions
     if (($sheet->{'type'}  eq 'classcalc'       ) ||       if (($sheet->{'type'}  eq 'classcalc'       ) || 
Line 524  my %numbertimes; Line 523  my %numbertimes;
 # Directories  # Directories
 #  #
 my $includedir;  my $includedir;
 my $tmpdir;  
   
 sub includedir {  sub includedir {
     my $self = shift;      my $self = shift;
     $includedir = shift;      $includedir = shift;
 }  }
   
 sub tmpdir {  
     my $self = shift;  
     $tmpdir = shift;  
 }  
   
 my %spreadsheets;  my %spreadsheets;
 my %loadedcaches;  #my %loadedcaches;
 my %courserdatas;  my %courserdatas;
 my %userrdatas;  my %userrdatas;
 my %defaultsheets;  my %defaultsheets;
 my %rowlabel_cache;  my %rowlabel_cache;
 my %oldsheets;  #my %oldsheets;
   
 sub complete_recalc {  sub complete_recalc {
     my $self = shift;      my $self = shift;
Line 609  sub cachedssheets { Line 602  sub cachedssheets {
     my ($uname,$udom) = @_;      my ($uname,$udom) = @_;
     $uname = $uname || $self->{'uname'};      $uname = $uname || $self->{'uname'};
     $udom  = $udom  || $self->{'udom'};      $udom  = $udom  || $self->{'udom'};
     if (! $Apache::lonspreadsheet::loadedcaches{$uname.'_'.$udom}) {      if (! exists($Apache::lonspreadsheet::loadedcaches{$uname.'_'.$udom})) {
         my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.          my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.
                                         $ENV{'request.course.id'},                                          $ENV{'request.course.id'},
                                         $self->{'udom'},                                          $self->{'udom'},
Line 729  sub parmval { Line 722  sub parmval {
     # second, check map parms      # second, check map parms
     my $thisparm = $parmhash{$symbparm};      my $thisparm = $parmhash{$symbparm};
     return $thisparm if (defined($thisparm));      return $thisparm if (defined($thisparm));
   
     # first, check default      # first, check default
     return &Apache::lonnet::metadata($fn,$rwhat.'.default');      $thisparm = &Apache::lonnet::metadata($fn,$rwhat.'.default');
       return $thisparm if (defined($thisparm));
   
       #Cascade Up
       my $space=$what;
       $space=~s/\.\w+$//;
       if ($space ne '0') {
    my @parts=split(/_/,$space);
    my $id=pop(@parts);
    my $part=join('_',@parts);
    if ($part eq '') { $part='0'; }
    my $newwhat=$rwhat;
    $newwhat=~s/\Q$space\E/$part/;
    my $partgeneral=&parmval($newwhat,$symb,$uname,$udom,$csec);
    if (defined($partgeneral)) { return $partgeneral; }
       }
   
       #nothing defined
       return '';
 }  }
   
 #  #
Line 1514  sub expandnamed { Line 1526  sub expandnamed {
  foreach my $varname ( @vars ) {   foreach my $varname ( @vars ) {
             if ($varname=~/\D/) {              if ($varname=~/\D/) {
                $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;                 $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;
                $varname=~s/$var/\(\\w\+\)/g;                 $varname=~s/$var/\([\\w:-]\+\)/g;
        foreach (keys(%{$self->{'constants'}})) {         foreach (keys(%{$self->{'constants'}})) {
   if ($_=~/$varname/) {    if ($_=~/$varname/) {
       $values{$1}=1;        $values{$1}=1;
Line 1588  sub sett { Line 1600  sub sett {
     foreach my $col ($self->template_cells()) {      foreach my $col ($self->template_cells()) {
         next if ($col=~/^$pattern/);          next if ($col=~/^$pattern/);
         foreach my $trow ($self->rows()) {          foreach my $trow ($self->rows()) {
             next if ($trow eq '0');  
             # Get the name of this cell              # Get the name of this cell
             my $lb=$col.$trow;              my $lb=$col.$trow;
             # Grab the template declaration              # Grab the template declaration
Line 1745  sub calcsheet { Line 1756  sub calcsheet {
     $self->sett();      $self->sett();
     my $result =  $self->{'safe'}->reval('&calc();');      my $result =  $self->{'safe'}->reval('&calc();');
     %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};      %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
   #    $self->logthis($self->get_errorlog());
     return $result;      return $result;
 }  }
   
Line 1893  sub dump_values_to_log { Line 1905  sub dump_values_to_log {
     }      }
     $self->logthis("--------------------------------------------------------");}      $self->logthis("--------------------------------------------------------");}
   
   ##
   ## Yet another debugging function
   ##
   sub dump_hash_to_log {
       my $self= shift();
       my %tmp = @_;
       if (@_<2) {
           %tmp = %{$_[0]};
       }
       $self->logthis('---------------------------- (entries end with ":"');
       while (my ($key,$val) = each (%tmp)) {
           $self->logthis($key.' = '.$val.':');
       }
       $self->logthis('---------------------------- (entries end with ":"');
   }
   
 ################################  ################################
 ##      Helper functions      ##  ##      Helper functions      ##
 ################################  ################################
Line 1904  sub rebuild_stats { Line 1932  sub rebuild_stats {
     $self->{'rows'}=[];      $self->{'rows'}=[];
     $self->{'template_cells'}=[];      $self->{'template_cells'}=[];
     foreach my $cell($self->formulas_keys()) {      foreach my $cell($self->formulas_keys()) {
         push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/);          push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);
         push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);          push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
     }      }
     return;      return;
Line 1951  sub rowlabels { Line 1979  sub rowlabels {
         $self->{'rowlabel'}=$rowlabel;          $self->{'rowlabel'}=$rowlabel;
         return;          return;
     } else {      } else {
         return %{$self->{'rowlabel'}} if (defined($self->{'rowlabels'}));          return %{$self->{'rowlabel'}} if (defined($self->{'rowlabel'}));
     }      }
 }  }
   
Line 2541  sub export_sheet_as_excel { Line 2569  sub export_sheet_as_excel {
             }              }
             next if ($row_is_empty);              next if ($row_is_empty);
         }          }
           $worksheet->write($rows_output,$cols_output++,$rownum);
         $worksheet->write($rows_output,$cols_output++,$label);          $worksheet->write($rows_output,$cols_output++,$label);
         if (ref($label)) {          if (ref($label)) {
             $cols_output = (scalar(@$label));              $cols_output = (scalar(@$label));
Line 2665  sub readsheet { Line 2694  sub readsheet {
     # $fn now has a value      # $fn now has a value
     $self->{'filename'} = $fn;      $self->{'filename'} = $fn;
     # see if sheet is cached      # see if sheet is cached
     my $fstring='';      if (exists($spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn})) {
     if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {          
         my %tmp = split(/___;___/,$fstring);          my %tmp = split(/___;___/,
                           $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn});
         $self->formulas(\%tmp);          $self->formulas(\%tmp);
     } else {      } else {
         # Not cached, need to read          # Not cached, need to read
Line 2776  sub tmpwrite { Line 2806  sub tmpwrite {
         $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.          $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
            $self->{'filename'};             $self->{'filename'};
     $fn=~s/\W/\_/g;      $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';      $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
     my $fh;      my $fh;
     if ($fh=Apache::File->new('>'.$fn)) {      if ($fh=Apache::File->new('>'.$fn)) {
         my %f = $self->formulas();          my %f = $self->formulas();
Line 2795  sub tmpread { Line 2825  sub tmpread {
            $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.             $ENV{'user.domain'}.'_spreadsheet_'.$self->{'usymb'}.'_'.
            $self->{'filename'};             $self->{'filename'};
     $fn=~s/\W/\_/g;      $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';      $fn=$Apache::lonnet::tmpdir.$fn.'.tmp';
     my $fh;      my $fh;
     my %fo=();      my %fo=();
     my $countrows=0;      my $countrows=0;
Line 2948  sub updateclasssheet { Line 2978  sub updateclasssheet {
             $self->{'maxrow'}= $rownum;              $self->{'maxrow'}= $rownum;
         }          }
         $existing{$f{$cell}}=1;          $existing{$f{$cell}}=1;
         unless ((defined($currentlist{$f{$cell}})) || ($rownum ne '0') ||          if (! defined($currentlist{$f{$cell}}) && ($f{$cell}=~/^(~~~|---)/)) {
                 ($f{$cell}=~/^(~~~|---)/)) {  
             $f{$cell}='!!! Obsolete';              $f{$cell}='!!! Obsolete';
             $changed=1;              $changed=1;
         }          }
Line 2980  sub get_student_rowlabels { Line 3009  sub get_student_rowlabels {
     $self->{'rowlabel'} = {};      $self->{'rowlabel'} = {};
     #      #
     my $identifier =$self->{'coursefilename'}.'_'.$stype;      my $identifier =$self->{'coursefilename'}.'_'.$stype;
     if  ($rowlabel_cache{$identifier}) {      if  (exists($rowlabel_cache{$identifier})) {
         %{$self->{'rowlabel'}}=split(/___;___/,$rowlabel_cache{$identifier});          my %tmp = split(/___;___/,$rowlabel_cache{$identifier});
           $self->rowlabels(\%tmp);
     } else {      } else {
         # Get the data and store it in the cache          # Get the data and store it in the cache
         # Tie hash          # Tie hash
Line 3033  sub get_assess_rowlabels { Line 3063  sub get_assess_rowlabels {
     $self->rowlabels({});      $self->rowlabels({});
     my $identifier =$self->{'coursefilename'}.'_'.$stype.'_'.$usymb;      my $identifier =$self->{'coursefilename'}.'_'.$stype.'_'.$usymb;
     #      #
     if  ($rowlabel_cache{$identifier}) {      if (exists($rowlabel_cache{$identifier})) {
         $self->rowlabels(split(/___;___/,$rowlabel_cache{$identifier}));          my %tmp = split('___;___',$rowlabel_cache{$identifier});
           $self->rowlabels(\%tmp);
     } else {      } else {
         # Get the data and store it in the cache          # Get the data and store it in the cache
         # Tie hash          # Tie hash
Line 3078  sub get_assess_rowlabels { Line 3109  sub get_assess_rowlabels {
         untie(%course_db);          untie(%course_db);
         # Store away the results          # Store away the results
         $self->rowlabels(\%parameter_labels);          $self->rowlabels(\%parameter_labels);
         $rowlabel_cache{$identifier}=join('___;___',$self->rowlabels());          $rowlabel_cache{$identifier}=join('___;___',%parameter_labels);
     }      }
           
 }  }
   
 sub updatestudentassesssheet {  sub updatestudentassesssheet {
Line 3099  sub updatestudentassesssheet { Line 3129  sub updatestudentassesssheet {
     foreach my $rownum ($self->rows()) {      foreach my $rownum ($self->rows()) {
         my $cell = 'A'.$rownum;          my $cell = 'A'.$rownum;
         my $formula = $f{$cell};          my $formula = $f{$cell};
         next if ($rownum eq '0');  
         $self->{'maxrow'} = $rownum if ($rownum > $self->{'maxrow'});          $self->{'maxrow'} = $rownum if ($rownum > $self->{'maxrow'});
         my ($usy,$ufn)=split(/__&&&\__/,$formula);          my ($usy,$ufn)=split(/__&&&\__/,$formula);
         $existing{$usy}=1;          $existing{$usy}=1;
Line 3132  sub loadstudent{ Line 3161  sub loadstudent{
     my %formulas  = $self->formulas();      my %formulas  = $self->formulas();
     $cachedassess = $self->{'uname'}.':'.$self->{'udom'};      $cachedassess = $self->{'uname'}.':'.$self->{'udom'};
     # Get ALL the student preformance data      # Get ALL the student preformance data
     my @tmp = &Apache::lonnet::currentdump($self->{'cid'},      my @tmp = &Apache::loncoursedata::get_current_state($self->{'uname'},
                                            $self->{'udom'},                                                          $self->{'udom'},
                                            $self->{'uname'});                                                          undef,
                                                           $self->{'cid'});
     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {      if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %cachedstores = @tmp;          %cachedstores = @tmp;
     }      }
     undef @tmp;      undef @tmp;
     #       # debugging code
       # $self->dump_hash_to_log(\%cachedstores);
       #
     my @assessdata=();      my @assessdata=();
     foreach my $row ($self->rows()) {      foreach my $row ($self->rows()) {
         my $cell = 'A'.$row;          my $cell = 'A'.$row;
Line 3147  sub loadstudent{ Line 3179  sub loadstudent{
         if(defined($c) && ($c->aborted())) {          if(defined($c) && ($c->aborted())) {
             last;              last;
         }          }
         next if (($value =~ /^[!~-]/) || ($row==0));          next if ($value =~ /^[!~-]/);
         my ($usy,$ufn)=split(/__&&&\__/,$value);          my ($usy,$ufn)=split(/__&&&\__/,$value);
         @assessdata=$self->exportsheet($self->{'uname'},          @assessdata=$self->exportsheet($self->{'uname'},
                                         $self->{'udom'},                                          $self->{'udom'},
Line 3172  sub loadstudent{ Line 3204  sub loadstudent{
     $self->constants(\%constants);      $self->constants(\%constants);
 }  }
   
 # --------------------------------------------------- Load data for one student  # --------------------------------------------------- Load Course Sheet
 #  #
 sub loadcourse {  sub loadcourse {
     my $self = shift;      my $self = shift;
Line 3185  sub loadcourse { Line 3217  sub loadcourse {
     foreach ($self->rows()) {      foreach ($self->rows()) {
         $total++ if ($formulas{'A'.$_} !~ /^[!~-]/);          $total++ if ($formulas{'A'.$_} !~ /^[!~-]/);
     }      }
     my $now=0;  
     my $since=time;      my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,
     $r->print(<<ENDPOP);        'Spreadsheet Status','Spreadsheet Calculation Progress', $total);
 <script>      &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
     popwin=open('','popwin','width=400,height=100');    'Processing Course Assessment Data');
     popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+  
       '<h3>Spreadsheet Calculation Progress</h3>'+      # It would be nice to load in the classlist and assessment info at this 
       '<form name=popremain>'+      # point, before attacking the student spreadsheets.
       '<input type=text size=45 name=remaining value=Starting></form>'+  
       '</body></html>');  
     popwin.document.close();  
 </script>  
 ENDPOP  
     $r->rflush();  
     foreach my $row ($self->rows()) {      foreach my $row ($self->rows()) {
         if(defined($c) && ($c->aborted())) {          if(defined($c) && ($c->aborted())) {
             last;              last;
         }          }
         my $cell = 'A'.$row;          my $cell = 'A'.$row;
         next if (($formulas{$cell}=~/^[\!\~\-]/)  || ($row==0));          next if ($formulas{$cell}=~/^[\!\~\-]/);
         my ($sname,$sdom) = split(':',$formulas{$cell});          my ($sname,$sdom) = split(':',$formulas{$cell});
         my $started = time;          my $started = time;
         my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc',          my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc',
                                      undef,undef,$r);                                       undef,undef,$r);
         undef %userrdatas;          undef %userrdatas;
         $now++;   &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
         $r->print('<script>popwin.document.popremain.remaining.value="'.   'last student');
                   $now.'/'.$total.': '.int((time-$since)/$now*($total-$now)).  
                   ' secs remaining '.(time-$started).' last";</script>');  
         $r->rflush();   
         #  
         my $index=0;          my $index=0;
         foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',          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') {                   'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
Line 3235  ENDPOP Line 3257  ENDPOP
     }      }
     $self->formulas(\%formulas);      $self->formulas(\%formulas);
     $self->constants(\%constants);      $self->constants(\%constants);
     $r->print('<script>popwin.close()</script>');      &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
     $r->rflush();   
 }  }
   
 # ------------------------------------------------ Load data for one assessment  # ------------------------------------------------ Load data for one assessment

Removed from v.1.165  
changed lines
  Added in v.1.174


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>