version 1.43, 2005/04/29 18:13:07
|
version 1.44, 2005/05/12 22:42:57
|
Line 328 sub initialize_safe_space {
|
Line 328 sub initialize_safe_space {
|
$safeeval->deny(":base_io"); |
$safeeval->deny(":base_io"); |
$safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&Apache::lonnet::EXT'); |
$safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&Apache::lonnet::EXT'); |
$safehole->wrap(\&mask,$safeeval,'&mask'); |
$safehole->wrap(\&mask,$safeeval,'&mask'); |
|
$safehole->wrap(\&Apache::lonnet::logthis,$safeeval,'&logthis'); |
$safeeval->share('$@'); |
$safeeval->share('$@'); |
my $code=<<'ENDDEFS'; |
my $code=<<'ENDDEFS'; |
# ---------------------------------------------------- Inside of the safe space |
# ---------------------------------------------------- Inside of the safe space |
Line 412 returns the number of items in the range
|
Line 413 returns the number of items in the range
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub NUM { |
sub NUM { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $num= $#{@{grep(eval("/$mask/"),keys(%sheet_values))}}+1; |
my $num= scalar(@$values); |
return $num; |
return $num; |
} |
} |
|
|
Line 428 sub NUM {
|
Line 429 sub NUM {
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub BIN { |
sub BIN { |
my ($low,$high,$lower,$upper)=@_; |
my ($low,$high,$lower,$upper)=@_; |
my $mask=&mask($lower,$upper); |
my $values=&get_values($lower,$upper); |
my $num=0; |
my $num=0; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
if (($sheet_values{$_}>=$low) && ($sheet_values{$_}<=$high)) { |
if (($_>=$low) && ($_<=$high)) { |
$num++; |
$num++; |
} |
} |
} |
} |
Line 450 returns the sum of items in the range.
|
Line 451 returns the sum of items in the range.
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub SUM { |
sub SUM { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $sum=0; |
my $sum=0; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
$sum+=$sheet_values{$_}; |
$sum+=$_; |
} |
} |
return $sum; |
return $sum; |
} |
} |
Line 470 compute the average of the items in the
|
Line 471 compute the average of the items in the
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub MEAN { |
sub MEAN { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $sum=0; |
my $sum=0; |
my $num=0; |
my $num=0; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
$sum+=$sheet_values{$_}; |
$sum+=$_; |
$num++; |
$num++; |
} |
} |
if ($num) { |
if ($num) { |
Line 496 compute the standard deviation of the it
|
Line 497 compute the standard deviation of the it
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub STDDEV { |
sub STDDEV { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $sum=0; my $num=0; |
my $sum=0; my $num=0; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
$sum+=$sheet_values{$_}; |
$sum+=$_; |
$num++; |
$num++; |
} |
} |
unless ($num>1) { return undef; } |
unless ($num>1) { return undef; } |
my $mean=$sum/$num; |
my $mean=$sum/$num; |
$sum=0; |
$sum=0; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
$sum+=($sheet_values{$_}-$mean)**2; |
$sum+=($_-$mean)**2; |
} |
} |
return sqrt($sum/($num-1)); |
return sqrt($sum/($num-1)); |
} |
} |
Line 523 compute the product of the items in the
|
Line 524 compute the product of the items in the
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub PROD { |
sub PROD { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $prod=1; |
my $prod=1; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
$prod*=$sheet_values{$_}; |
$prod*=$_; |
} |
} |
return $prod; |
return $prod; |
} |
} |
Line 543 compute the maximum of the items in the
|
Line 544 compute the maximum of the items in the
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub MAX { |
sub MAX { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $max='-'; |
my $max='-'; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
unless ($max) { $max=$sheet_values{$_}; } |
if (($_>$max) || ($max eq '-')) { |
if (($sheet_values{$_}>$max) || ($max eq '-')) { |
$max=$_; |
$max=$sheet_values{$_}; |
|
} |
} |
} |
} |
return $max; |
return $max; |
Line 566 compute the minimum of the items in the
|
Line 566 compute the minimum of the items in the
|
|
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub MIN { |
sub MIN { |
my $mask=&mask(@_); |
my $values=&get_values(@_); |
my $min='-'; |
my $min='-'; |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
foreach (@$values) { |
unless ($max) { $max=$sheet_values{$_}; } |
if (($_<$min) || ($min eq '-')) { |
if (($sheet_values{$_}<$min) || ($min eq '-')) { |
$min=$_; |
$min=$sheet_values{$_}; |
|
} |
} |
} |
} |
return $min; |
return $min; |
Line 591 compute the sum of the largest 'num' ite
|
Line 590 compute the sum of the largest 'num' ite
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub SUMMAX { |
sub SUMMAX { |
my ($num,$lower,$upper)=@_; |
my ($num,$lower,$upper)=@_; |
my $mask=&mask($lower,$upper); |
my $values=&get_values($lower,$upper); |
my @inside=(); |
my @inside=sort {$a <=> $b} (@$values); |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
|
push (@inside,$sheet_values{$_}); |
|
} |
|
@inside=sort {$a <=> $b} (@inside); |
|
my $sum=0; my $i; |
my $sum=0; my $i; |
for ($i=$#inside;(($i>$#inside-$num) && ($i>=0));$i--) { |
for ($i=$#inside;(($i>$#inside-$num) && ($i>=0));$i--) { |
$sum+=$inside[$i]; |
$sum+=$inside[$i]; |
Line 618 compute the sum of the smallest 'num' it
|
Line 613 compute the sum of the smallest 'num' it
|
#------------------------------------------------------- |
#------------------------------------------------------- |
sub SUMMIN { |
sub SUMMIN { |
my ($num,$lower,$upper)=@_; |
my ($num,$lower,$upper)=@_; |
my $mask=&mask($lower,$upper); |
my $values=&get_values($lower,$upper); |
my @inside=(); |
my @inside=sort {$a <=> $b} (@$values); |
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
|
$inside[$#inside+1]=$sheet_values{$_}; |
|
} |
|
@inside=sort {$a <=> $b} (@inside); |
|
my $sum=0; my $i; |
my $sum=0; my $i; |
for ($i=0;(($i<$num) && ($i<=$#inside));$i++) { |
for ($i=0;(($i<$num) && ($i<=$#inside));$i++) { |
$sum+=$inside[$i]; |
$sum+=$inside[$i]; |
Line 679 sub MAXPARM {
|
Line 670 sub MAXPARM {
|
return $max; |
return $max; |
} |
} |
|
|
|
sub get_values { |
|
my ($lower,$upper)=@_; |
|
my $mask=&mask(@_); |
|
my @values; |
|
foreach (grep eval("/$mask/"),keys(%sheet_values)) { |
|
push(@values,$sheet_values{$_}); |
|
} |
|
return \@values; |
|
if (0) { |
|
# perhaps creating a list of possible cells and looking if they exist |
|
# would be faster somtimes? |
|
&logthis("mask is ".$mask); |
|
my @alpha; |
|
if (($la eq '*') || ($ua eq '*')) { |
|
@alpha=('A'..'z'); |
|
} else { |
|
if ($la gt $ua) { |
|
my $tmp = $ua; |
|
$ua = $la; |
|
$la = $ua; |
|
} |
|
$alpha=($la..$ua); |
|
} |
|
} |
|
} |
|
|
sub calc { |
sub calc { |
%sheet_values = %t; |
%sheet_values = %t; |