Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.82 and 1.84

version 1.82, 2002/04/09 18:41:11 version 1.84, 2002/04/11 13:35:23
Line 508  sub HASH { Line 508  sub HASH {
     return $Values[-1];      return $Values[-1];
 }  }
   
   #-------------------------------------------------------
   
   =item NUM(range)
   
   returns the number of items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub NUM {  sub NUM {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $num= $#{@{grep(/$mask/,keys(%v))}}+1;      my $num= $#{@{grep(/$mask/,keys(%v))}}+1;
Line 527  sub BIN { Line 536  sub BIN {
 }  }
   
   
   #-------------------------------------------------------
   
   =item SUM(range)
   
   returns the sum of items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub SUM {  sub SUM {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $sum=0;      my $sum=0;
Line 536  sub SUM { Line 554  sub SUM {
     return $sum;         return $sum;   
 }  }
   
   #-------------------------------------------------------
   
   =item MEAN(range)
   
   compute the average of the items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub MEAN {  sub MEAN {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $sum=0; my $num=0;      my $sum=0; my $num=0;
Line 550  sub MEAN { Line 577  sub MEAN {
     }         }   
 }  }
   
   #-------------------------------------------------------
   
   =item STDDEV(range)
   
   compute the standard deviation of the items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub STDDEV {  sub STDDEV {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $sum=0; my $num=0;      my $sum=0; my $num=0;
Line 566  sub STDDEV { Line 602  sub STDDEV {
     return sqrt($sum/($num-1));          return sqrt($sum/($num-1));    
 }  }
   
   #-------------------------------------------------------
   
   =item PROD(range)
   
   compute the product of the items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub PROD {  sub PROD {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $prod=1;      my $prod=1;
Line 575  sub PROD { Line 620  sub PROD {
     return $prod;         return $prod;   
 }  }
   
   #-------------------------------------------------------
   
   =item MAX(range)
   
   compute the maximum of the items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub MAX {  sub MAX {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $max='-';      my $max='-';
Line 585  sub MAX { Line 639  sub MAX {
     return $max;         return $max;   
 }  }
   
   #-------------------------------------------------------
   
   =item MIN(range)
   
   compute the minimum of the items in the range.
   
   =cut
   
   #-------------------------------------------------------
 sub MIN {  sub MIN {
     my $mask=mask(@_);      my $mask=mask(@_);
     my $min='-';      my $min='-';
Line 595  sub MIN { Line 658  sub MIN {
     return $min;         return $min;   
 }  }
   
   #-------------------------------------------------------
   
   =item SUMMAX(num,lower,upper)
   
   compute the sum of the largest 'num' items in the range from
   'lower' to 'upper'
   
   =cut
   
   #-------------------------------------------------------
 sub SUMMAX {  sub SUMMAX {
     my ($num,$lower,$upper)=@_;      my ($num,$lower,$upper)=@_;
     my $mask=mask($lower,$upper);      my $mask=mask($lower,$upper);
     my @inside=();      my @inside=();
     foreach (grep /$mask/,keys(%v)) {      foreach (grep /$mask/,keys(%v)) {
  $inside[$#inside+1]=$v{$_};   push (@inside,$v{$_});
     }      }
     @inside=sort(@inside);      @inside=sort(@inside);
     my $sum=0; my $i;      my $sum=0; my $i;
Line 610  sub SUMMAX { Line 683  sub SUMMAX {
     return $sum;         return $sum;   
 }  }
   
   #-------------------------------------------------------
   
   =item SUMMIN(num,lower,upper)
   
   compute the sum of the smallest 'num' items in the range from
   'lower' to 'upper'
   
   =cut
   
   #-------------------------------------------------------
 sub SUMMIN {  sub SUMMIN {
     my ($num,$lower,$upper)=@_;      my ($num,$lower,$upper)=@_;
     my $mask=mask($lower,$upper);      my $mask=mask($lower,$upper);
Line 774  sub outrowassess { Line 857  sub outrowassess {
      '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') {
         my $fm=$f{$_.$n};          my $fm=$f{$_.$n};
         $fm=~s/[\'\"]/\&\#34;/g;          $fm=~s/[\'\"]/\&\#34;/g;
         $cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n};          push(@cols,"'$_$n','$fm'".'___eq___'.$v{$_.$n});
     }      }
     return @cols;      return @cols;
 }  }
Line 1189  sub readsheet { Line 1272  sub readsheet {
   my $cdom=&getcdom($safeeval);    my $cdom=&getcdom($safeeval);
   my $chome=&getchome($safeeval);    my $chome=&getchome($safeeval);
   
   if (! defined($fn) || $fn eq '') {    if (! defined($fn)) {
       # There is no filename. Look for defaults in course and global, cache        # There is no filename. Look for defaults in course and global, cache
       unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {        unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
           my %tmphash = &Apache::lonnet::get('environment',            my %tmphash = &Apache::lonnet::get('environment',
Line 1203  sub readsheet { Line 1286  sub readsheet {
           }             } 
           $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn;             $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn; 
       }        }
   } else {  
       # We do have a filename, do a get on it.  
       my %tmphash = &Apache::lonnet::get('environment',  
                                          [$fn],  
                                          $cdom,$cnum);  
       my ($tmp) = keys(%tmphash);  
       if ($tmp =~ /^(con_lost|error|no_such_host)/i) {  
           # On error, grab the default filename  
           $fn = 'default_'.$stype;  
       } else {  
           $fn = $tmphash{$fn};  
       }  
       $defaultsheets{$cnum.'_'.$cdom.'_'.$stype}=$fn;   
   }    }
   
 # ---------------------------------------------------------- fn now has a value  # ---------------------------------------------------------- fn now has a value
Line 1242  sub readsheet { Line 1312  sub readsheet {
          } else {           } else {
              $sheetxml='<field row="0" col="A">"Error"</field>';               $sheetxml='<field row="0" col="A">"Error"</field>';
          }           }
          %f=&parse_sheet(\$sheetxml);           %f=%{&parse_sheet(\$sheetxml)};
      } elsif($fn=~/\/*\.spreadsheet$/) {       } elsif($fn=~/\/*\.spreadsheet$/) {
          my $sheetxml='';           my $sheetxml=&Apache::lonnet::getfile
          my $fh;               (&Apache::lonnet::filelocation('',$fn));
          my $dfn=$fn;           print "<pre>$sheetxml</pre>";
          $dfn=~s/\_/\./g;           if ($sheetxml == -1) {
   
          if ($fn !~ /^$Apache::lonnet::perlvar{'lonDocRoot'}\/res/) {  
              $fn = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'.$fn;  
          }  
          if ($fn !~ /^$Apache::lonnet::perlvar{'lonDocRoot'}/) {  
              $fn = $Apache::lonnet::perlvar{'lonDocRoot'}.$fn;  
          }  
          if ($fh=Apache::File->new($fn)) {  
              $sheetxml=join('',<$fh>);  
          } else {  
              $sheetxml='<field row="0" col="A">"Error loading spreadsheet '               $sheetxml='<field row="0" col="A">"Error loading spreadsheet '
                  .$fn.'"</field>';                   .$fn.'"</field>';
          }           }
          %f=&parse_sheet(\$sheetxml);           %f=%{&parse_sheet(\$sheetxml)};
            print "<pre>";
            foreach (sort( keys(%f))) {
                print "$_ = $f{$_}\n";
            }
            print "</pre>";
      } else {       } else {
          my $sheet='';           my $sheet='';
          my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);           my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);

Removed from v.1.82  
changed lines
  Added in v.1.84


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