--- loncom/interface/Attic/lonspreadsheet.pm 2002/04/09 18:41:11 1.82
+++ loncom/interface/Attic/lonspreadsheet.pm 2002/04/11 13:35:23 1.84
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.82 2002/04/09 18:41:11 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.84 2002/04/11 13:35:23 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -508,6 +508,15 @@ sub HASH {
return $Values[-1];
}
+#-------------------------------------------------------
+
+=item NUM(range)
+
+returns the number of items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub NUM {
my $mask=mask(@_);
my $num= $#{@{grep(/$mask/,keys(%v))}}+1;
@@ -527,6 +536,15 @@ sub BIN {
}
+#-------------------------------------------------------
+
+=item SUM(range)
+
+returns the sum of items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub SUM {
my $mask=mask(@_);
my $sum=0;
@@ -536,6 +554,15 @@ sub SUM {
return $sum;
}
+#-------------------------------------------------------
+
+=item MEAN(range)
+
+compute the average of the items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub MEAN {
my $mask=mask(@_);
my $sum=0; my $num=0;
@@ -550,6 +577,15 @@ sub MEAN {
}
}
+#-------------------------------------------------------
+
+=item STDDEV(range)
+
+compute the standard deviation of the items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub STDDEV {
my $mask=mask(@_);
my $sum=0; my $num=0;
@@ -566,6 +602,15 @@ sub STDDEV {
return sqrt($sum/($num-1));
}
+#-------------------------------------------------------
+
+=item PROD(range)
+
+compute the product of the items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub PROD {
my $mask=mask(@_);
my $prod=1;
@@ -575,6 +620,15 @@ sub PROD {
return $prod;
}
+#-------------------------------------------------------
+
+=item MAX(range)
+
+compute the maximum of the items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub MAX {
my $mask=mask(@_);
my $max='-';
@@ -585,6 +639,15 @@ sub MAX {
return $max;
}
+#-------------------------------------------------------
+
+=item MIN(range)
+
+compute the minimum of the items in the range.
+
+=cut
+
+#-------------------------------------------------------
sub MIN {
my $mask=mask(@_);
my $min='-';
@@ -595,12 +658,22 @@ sub 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 {
my ($num,$lower,$upper)=@_;
my $mask=mask($lower,$upper);
my @inside=();
foreach (grep /$mask/,keys(%v)) {
- $inside[$#inside+1]=$v{$_};
+ push (@inside,$v{$_});
}
@inside=sort(@inside);
my $sum=0; my $i;
@@ -610,6 +683,16 @@ sub SUMMAX {
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 {
my ($num,$lower,$upper)=@_;
my $mask=mask($lower,$upper);
@@ -774,7 +857,7 @@ sub outrowassess {
'n','o','p','q','r','s','t','u','v','w','x','y','z') {
my $fm=$f{$_.$n};
$fm=~s/[\'\"]/\&\#34;/g;
- $cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n};
+ push(@cols,"'$_$n','$fm'".'___eq___'.$v{$_.$n});
}
return @cols;
}
@@ -1189,7 +1272,7 @@ sub readsheet {
my $cdom=&getcdom($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
unless ($fn=$defaultsheets{$cnum.'_'.$cdom.'_'.$stype}) {
my %tmphash = &Apache::lonnet::get('environment',
@@ -1203,19 +1286,6 @@ sub readsheet {
}
$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
@@ -1242,26 +1312,21 @@ sub readsheet {
} else {
$sheetxml='
$sheetxml"; + if ($sheetxml == -1) { $sheetxml='
"; + foreach (sort( keys(%f))) { + print "$_ = $f{$_}\n"; + } + print ""; } else { my $sheet=''; my %tmphash = &Apache::lonnet::dump($fn,$cdom,$cnum);