[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 28 Aug 2002 19:50:29 -0000
This is a MIME encoded message
--matthew1030564229
Content-Type: text/plain
matthew Wed Aug 28 15:50:29 2002 EDT
Modified files:
/loncom/interface lonspreadsheet.pm
Log:
Replaced %rl with %rowlabel... Many attempts to get a grip on the code.
Rewrote &updateclasssheet to call lonnet::dump instead of lonnet::reply.
This pretty much precipitated a complete rewrite of the function.
Expect more of the same.
--matthew1030564229
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020828155029.txt"
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.101 loncom/interface/lonspreadsheet.pm:1.102
--- loncom/interface/lonspreadsheet.pm:1.101 Wed Aug 21 13:18:08 2002
+++ loncom/interface/lonspreadsheet.pm Wed Aug 28 15:50:29 2002
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.101 2002/08/21 17:18:08 www Exp $
+# $Id: lonspreadsheet.pm,v 1.102 2002/08/28 19:50:29 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -146,7 +146,7 @@
undef %t;
undef %f;
undef %c;
-undef %rl;
+undef %rowlabel;
undef @os;
$maxrow=0;
@@ -904,8 +904,8 @@
my @cols=();
if ($n) {
my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{'A'.$n});
- if ($rl{$usy}) {
- $cols[0]=$rl{$usy}.'<br>'.
+ if ($rowlabel{$usy}) {
+ $cols[0]=$rowlabel{$usy}.'<br>'.
'<select name="sel_'.$n.'" onChange="changesheet('.$n.
')"><option name="default">Default</option>';
} else { $cols[0]=''; }
@@ -935,7 +935,7 @@
my $n=shift;
my @cols=();
if ($n) {
- $cols[0]=$rl{$f{'A'.$n}};
+ $cols[0]=$rowlabel{$f{'A'.$n}};
} else {
$cols[0]='<b><font size=+1>Export</font></b>';
}
@@ -989,8 +989,8 @@
# ------------------------------------------------ Add or change formula values
sub setrowlabels {
- my ($safeeval,%rl)=@_;
- %{$safeeval->varglob('rl')}=%rl;
+ my ($safeeval,%rowlabel)=@_;
+ %{$safeeval->varglob('rowlabel')}=%rowlabel;
}
# ------------------------------------------------------- Calculate spreadsheet
@@ -1231,20 +1231,20 @@
'><b><font size=+1>Import</font></b></td>'.
'<td colspan='.$maxyellow.
'><b><font size=+1>Calculations</font></b></td></tr><tr>';
- my $showf=0;
- 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',
- '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') {
- $showf++;
- if ($showf<=$maxred) {
- $tabledata.='<td bgcolor="#FFDDDD">';
- } else {
- $tabledata.='<td>';
- }
- $tabledata.="<b><font size=+1>$_</font></b></td>";
- }
- $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);
+ my $showf=0;
+ 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',
+ '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') {
+ $showf++;
+ if ($showf<=$maxred) {
+ $tabledata.='<td bgcolor="#FFDDDD">';
+ } else {
+ $tabledata.='<td>';
+ }
+ $tabledata.="<b><font size=+1>$_</font></b></td>";
+ }
+ $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);
} else { $tabledata='<pre>'; }
$r->print($tabledata);
@@ -1259,7 +1259,6 @@
$sortidx[$row-1]=$row-1;
}
@sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx;
-
my $what='Student';
if (&gettype($safeeval) eq 'assesscalc') {
$what='Item';
@@ -1269,23 +1268,20 @@
my $n=0;
for ($row=0;$row<$maxrow;$row++) {
- my $thisrow=&rown($safeeval,$sortidx[$row]+1);
- if ($thisrow) {
- if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
- $r->print("</table>\n<br>\n");
- $r->rflush();
- $r->print('<table border=2><tr><td> <td>'.$what.'</td>');
- 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',
- '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') {
- $r->print('<td>'.$_.'</td>');
+ my $thisrow=&rown($safeeval,$sortidx[$row]+1);
+ if ($thisrow) {
+ if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
+ $r->print("</table>\n<br>\n");
+ $r->rflush();
+ $r->print('<table border=2><tr><td> <td>'.$what.'</td>');
+ $r->print('<td>'.join('</td><td>',
+ (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
+ 'abcdefghijklmnopqrstuvwxyz'))).
+ "</td></tr>\n");
+ }
+ $n++;
+ $r->print($thisrow);
}
- $r->print('</tr>');
- }
- $n++;
- $r->print($thisrow);
- }
}
$r->print($ENV{'form.showcsv'}?'</pre>':'</table>');
}
@@ -1647,101 +1643,101 @@
my $cdom=&getcdom($safeeval);
my $cid=&getcid($safeeval);
my $chome=&getchome($safeeval);
-
-# ---------------------------------------------- Read class list and row labels
-
- my $classlst=&Apache::lonnet::reply
- ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
+ #
+ # Read class list and row labels
+ my %classlist;
+ my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);
+ if ($tmp[0] !~ /^error/) {
+ %classlist = @tmp;
+ } else {
+ return 'Could not access course data';
+ }
+ undef @tmp;
+ #
my %currentlist=();
my $now=time;
- unless ($classlst=~/^error\:/) {
- foreach (split(/\&/,$classlst)) {
- my ($name,$value)=split(/\=/,$_);
- my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- $active = 1 if ($ENV{'form.Status'} eq 'Any');
- $active = !$active if ($ENV{'form.Status'} eq 'Expired');
- if ($active) {
- my $rowlabel='';
- $name=&Apache::lonnet::unescape($name);
- my ($sname,$sdom)=split(/\:/,$name);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- if ($ssec==-1) {
- unless ($ENV{'form.showcsv'}) {
- $rowlabel='<font color=red>Data not available: '.$name.
- '</font>';
- } else {
- $rowlabel='ERROR","'.$name.
- '","Data not available","","","';
- }
+ foreach my $student (keys(%classlist)) {
+ my ($end,$start)=split(/\:/,$classlist{$student});
+ my $active=1;
+ $active = 0 if (($end) && ($now>$end));
+ $active = 1 if ($ENV{'form.Status'} eq 'Any');
+ $active = !$active if ($ENV{'form.Status'} eq 'Expired');
+ if ($active) {
+ my $rowlabel='';
+ my ($studentName,$studentDomain)=split(/\:/,$student);
+ my $studentSection=&Apache::lonnet::usection($studentDomain,
+ $studentName,$cid);
+ if ($studentSection==-1) {
+ unless ($ENV{'form.showcsv'}) {
+ $rowlabel='<font color=red>Data not available: '.
+ $studentName.'</font>';
} else {
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
- ':environment:firstname&middlename&lastname&generation',
- &Apache::lonnet::homeserver($sname,$sdom));
- unless ($ENV{'form.showcsv'}) {
- $rowlabel='<a href="/adm/studentcalc?uname='.$sname.
- '&udom='.$sdom.'">'.
- $ssec.' '.$reply{$sname}.'<br>';
- foreach ( split(/\&/,$reply)) {
- $rowlabel.=&Apache::lonnet::unescape($_).' ';
+ $rowlabel='ERROR","'.$studentName.
+ '","Data not available","","","';
+ }
+ } else {
+ my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
+ my %studentInformation=&Apache::lonnet::get
+ ('environment',
+ ['lastname','generation','firstname','middlename','id'],
+ $studentDomain,$studentName);
+ if (! $ENV{'form.showcsv'}) {
+ $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
+ '&udom='.$studentDomain.'">'.
+ $studentSection.' ';
+ foreach ('id','firstname','middlename',
+ 'lastname','generation'){
+ $rowlabel.=$studentInformation{$_}." ";
}
$rowlabel.='</a>';
- } else {
- $rowlabel=$ssec.'","'.$reply{$sname}.'"';
- my $ncount=0;
- foreach (split(/\&/,$reply)) {
- $rowlabel.=',"'.&Apache::lonnet::unescape($_).'"';
- $ncount++;
- }
- unless ($ncount==4) { $rowlabel.=',""'; }
- $rowlabel=~s/\"$//;
- }
+ } else {
+ $rowlabel= '"'.join('","',
+ ($studentSection,
+ $studentInformation{'id'},
+ $studentInformation{'firstname'},
+ $studentInformation{'middlename'},
+ $studentInformation{'lastname'},
+ $studentInformation{'generation'})
+ ).'"';
}
- $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel;
}
- } # end of foreach (split(/\&/,$classlst))
-#
-# -------------------- Find discrepancies between the course row table and this
-#
- my %f=&getformulas($safeeval);
- my $changed=0;
-
- my $maxrow=0;
- my %existing=();
-
-# ----------------------------------------------------------- Now obsolete rows
- foreach (keys(%f)) {
- if ($_=~/^A(\d+)/) {
- $maxrow=($1>$maxrow)?$1:$maxrow;
- $existing{$f{$_}}=1;
- unless ((defined($currentlist{$f{$_}})) || (!$1) ||
- ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
- $f{$_}='!!! Obsolete';
- $changed=1;
- }
+ $currentlist{$student}=$rowlabel;
+ } # end of if ($active)
+ } # end of foreach my $student (keys(%classlist))
+ #
+ # Find discrepancies between the course row table and this
+ #
+ my %f=&getformulas($safeeval);
+ my $changed=0;
+ #
+ my $maxrow=0;
+ my %existing=();
+ #
+ # Now obsolete rows
+ foreach (keys(%f)) {
+ if ($_=~/^A(\d+)/) {
+ $maxrow=($1>$maxrow)?$1:$maxrow;
+ $existing{$f{$_}}=1;
+ unless ((defined($currentlist{$f{$_}})) || (!$1) ||
+ ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
+ $f{$_}='!!! Obsolete';
+ $changed=1;
}
}
-
-# -------------------------------------------------------- New and unknown keys
-
- foreach (sort keys(%currentlist)) {
- unless ($existing{$_}) {
- $changed=1;
- $maxrow++;
- $f{'A'.$maxrow}=$_;
- }
+ }
+ #
+ # New and unknown keys
+ foreach (sort keys(%currentlist)) {
+ unless ($existing{$_}) {
+ $changed=1;
+ $maxrow++;
+ $f{'A'.$maxrow}=$_;
}
-
- if ($changed) { &setformulas($safeeval,%f); }
-
- &setmaxrow($safeeval,$maxrow);
- &setrowlabels($safeeval,%currentlist);
-
- } else {
- return 'Could not access course data';
}
+ if ($changed) { &setformulas($safeeval,%f); }
+ #
+ &setmaxrow($safeeval,$maxrow);
+ &setrowlabels($safeeval,%currentlist);
}
# ----------------------------------- Update rows for student and assess sheets
@@ -1893,26 +1889,22 @@
my %c=();
my %f=&getformulas($safeeval);
$cachedassess=&getuname($safeeval).':'.&getudom($safeeval);
- %cachedstores=();
- {
- my $reply=&Apache::lonnet::reply('dump:'.&getudom($safeeval).':'.
- &getuname($safeeval).':'.
- &getcid($safeeval),
- &getuhome($safeeval));
- unless ($reply=~/^error\:/) {
- foreach ( split(/\&/,$reply)) {
- my ($name,$value)=split(/\=/,$_);
- $cachedstores{&Apache::lonnet::unescape($name)}=
- &Apache::lonnet::unescape($value);
- }
- }
+ # Get ALL the student preformance data
+ my @tmp = &Apache::lonnet::dump(&getcid($safeeval),
+ &getudom($safeeval),
+ &getuname($safeeval),
+ undef);
+ if ($tmp[0] !~ /^error:/) {
+ %cachedstores = @tmp;
}
+ undef @tmp;
+ #
my @assessdata=();
foreach (keys(%f)) {
if ($_=~/^A(\d+)/) {
my $row=$1;
unless (($f{$_}=~/^[\!\~\-]/) || ($row==0)) {
- my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});
+ my ($usy,$ufn)=split(/__&&&\__/,$f{$_});
@assessdata=&exportsheet(&getuname($safeeval),
&getudom($safeeval),
'assesscalc',$usy,$ufn);
@@ -1981,18 +1973,18 @@
$r->rflush();
my $index=0;
- 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') {
+ 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') {
if ($studentdata[$index]) {
- my $col=$_;
- if ($studentdata[$index]=~/\D/) {
- $c{$col.$row}="'".$studentdata[$index]."'";
- } else {
- $c{$col.$row}=$studentdata[$index];
- }
- unless ($col eq 'A') {
- $f{$col.$row}='import';
- }
+ my $col=$_;
+ if ($studentdata[$index]=~/\D/) {
+ $c{$col.$row}="'".$studentdata[$index]."'";
+ } else {
+ $c{$col.$row}=$studentdata[$index];
+ }
+ unless ($col eq 'A') {
+ $f{$col.$row}='import';
+ }
}
$index++;
}
--matthew1030564229--