--- loncom/interface/Attic/lonspreadsheet.pm 2001/01/20 01:07:03 1.34 +++ loncom/interface/Attic/lonspreadsheet.pm 2001/01/20 22:57:05 1.36 @@ -3,10 +3,10 @@ # # 11/11,11/15,11/27,12/04,12/05,12/06,12/07, # 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30, -# 01/01/01,02/01,03/01,19/01 Gerd Kortemeyer +# 01/01/01,02/01,03/01,19/01,20/01 Gerd Kortemeyer package Apache::lonspreadsheet; - + use strict; use Safe; use Safe::Hole; @@ -25,6 +25,7 @@ my %spreadsheets; my %courserdatas; my %userrdatas; my %defaultsheets; +my %updatedata; # # These global hashes are dependent on user, course and resource, @@ -39,11 +40,30 @@ my %parmhash; my $includedir; my $tmpdir; + +sub mdeb { + my $msg=shift; + my $mem=''; + { + my $mfh=Apache::File->new('/proc/'.$$.'/status'); + my $line; + while ($line=<$mfh>) { + my ($name,$value)=split(/\:/,$line); + if ($name eq 'VmSize') { $mem=$value; } + } + $mfh->close(); + } + print $msg.$mem."
\n"; +} + + + + # ============================================================================= # ===================================== Implements an instance of a spreadsheet sub initsheet { - my $safeeval = new Safe; + my $safeeval = new Safe(shift); my $safehole = new Safe::Hole; $safeeval->permit("entereval"); $safeeval->permit(":base_math"); @@ -60,11 +80,11 @@ sub initsheet { # c: preloaded constants (A-column) # rl: row label -%v=(); -%t=(); -%f=(); -%c=(); -%rl=(); +undef %v; +undef %t; +undef %f; +undef %c; +undef %rl; $maxrow=0; $sheettype=''; @@ -778,7 +798,7 @@ sub readsheet { sub makenewsheet { my ($uname,$udom,$stype,$usymb)=@_; - my $safeeval=initsheet(); + my $safeeval=initsheet($stype); $safeeval->reval( '$uname="'.$uname. '";$udom="'.$udom. @@ -1060,6 +1080,9 @@ sub updateclasssheet { sub updatestudentassesssheet { my $safeeval=shift; my %bighash; + my $stype=&gettype($safeeval); + my %current=(); + unless ($updatedata{$ENV{'request.course.fn'}.'_'.$stype}) { # -------------------------------------------------------------------- Tie hash if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db', &GDBM_READER,0640)) { @@ -1068,8 +1091,6 @@ sub updatestudentassesssheet { my %allkeys=(); my %allassess=(); - my $stype=&gettype($safeeval); - map { if ($_=~/^src\_(\d+)\.(\d+)$/) { my $mapid=$1; @@ -1106,17 +1127,26 @@ sub updatestudentassesssheet { # %allkeys has a list of storage and parameter displays by unikey # %allassess has a list of all resource displays by symb # -# -------------------- Find discrepancies between the course row table and this -# - my %f=&getformulas($safeeval); - my $changed=0; - my %current=(); if ($stype eq 'assesscalc') { %current=%allkeys; } elsif ($stype eq 'studentcalc') { %current=%allassess; } + $updatedata{$ENV{'request.course.fn'}.'_'.$stype}= + join('___;___',%current); + } else { + return 'Could not access course data'; + } +# ------------------------------------------------------ Get current from cache + } else { + %current=split(/\_\_\_\;\_\_\_/, + $updatedata{$ENV{'request.course.fn'}.'_'.$stype}); + } +# -------------------- Find discrepancies between the course row table and this +# + my %f=&getformulas($safeeval); + my $changed=0; my $maxrow=0; my %existing=(); @@ -1142,15 +1172,14 @@ sub updatestudentassesssheet { $f{'A'.$maxrow}=$_; } } keys %current; - + if ($changed) { &setformulas($safeeval,%f); } &setmaxrow($safeeval,$maxrow); &setrowlabels($safeeval,%current); - - } else { - return 'Could not access course data'; - } + + undef %current; + undef %existing; } # ------------------------------------------------ Load data for one assessment @@ -1159,13 +1188,14 @@ sub loadstudent { my $safeeval=shift; my %c=(); my %f=&getformulas($safeeval); + my @assessdata=(); map { if ($_=~/^A(\d+)/) { my $row=$1; unless ($f{$_}=~/^\!/) { - my @assessdata=&exportsheet(&getuname($safeeval), - &getudom($safeeval), - 'assesscalc',$f{$_}); + @assessdata=&exportsheet(&getuname($safeeval), + &getudom($safeeval), + 'assesscalc',$f{$_}); my $index=0; map { if ($assessdata[$index]) { @@ -1193,11 +1223,7 @@ sub loadcourse { map { if ($_=~/^A(\d+)/) { my $row=$1; - unless (($f{$_}=~/^\!/) - -|| ($row>200)) - - { + unless ($f{$_}=~/^\!/) { my @studentdata=&exportsheet(&getuname($safeeval), &getudom($safeeval), 'studentcalc'); @@ -1277,7 +1303,7 @@ sub loadassessment { my ($name,$value)=split(/\=/,$_); $courseopt{$userprefix.&Apache::lonnet::unescape($name)}= &Apache::lonnet::unescape($value); - } split(/\&/,$courserdatas{$ENV{'request.course.id'}}); + } split(/\&/,$courserdatas{$cid}); # --------------------------------------------------- Get userdata (if present) unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) { @@ -1384,15 +1410,14 @@ sub loadrows() { # sub exportsheet { + my ($uname,$udom,$stype,$usymb,$fn)=@_; my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb); &readsheet($thissheet,$fn); &updatesheet($thissheet); &loadrows($thissheet); &calcsheet($thissheet); - my @returnthis=&exportdata($thissheet); - undef $thissheet; - return @returnthis; + return &exportdata($thissheet); } # ================================================================ Main handler @@ -1566,9 +1591,18 @@ ENDSCRIPT # ----------------------------------------------------- Update sheet, load rows + $r->print("Loaded sheet, updating rows ...
\n"); + $r->rflush(); + &updatesheet($asheet); + + $r->print("Updated rows, loading row data ...
\n"); + $r->rflush(); + &loadrows($asheet); + $r->print("Loaded row data, calculating sheet ...
\n"); + $r->rflush(); my $calcoutput=&calcsheet($asheet); $r->print('

'.$calcoutput.'

');