--- loncom/interface/Attic/lonspreadsheet.pm 2001/03/10 16:46:52 1.41 +++ loncom/interface/Attic/lonspreadsheet.pm 2001/03/13 15:50:47 1.44 @@ -4,7 +4,7 @@ # 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,20/01,22/01, -# 03/05,03/08,03/10 Gerd Kortemeyer +# 03/05,03/08,03/10,03/12,03/13 Gerd Kortemeyer package Apache::lonspreadsheet; @@ -18,6 +18,12 @@ use GDBM_File; use HTML::TokeParser; # +# Caches for previously calculated spreadsheets +# + +my %oldsheets; + +# # Cache for stores of an individual user # @@ -326,7 +332,8 @@ sub sett { } keys %f; map { if (($f{$_}) && ($_!~/template\_/)) { - if ($_=~/^$pattern/) { + my $matches=($_=~/^$pattern(\d+)/); + if (($matches) && ($1)) { unless ($f{$_}=~/^\!/) { $t{$_}=$c{$_}; } @@ -1200,7 +1207,7 @@ sub loadstudent { map { if ($_=~/^A(\d+)/) { my $row=$1; - unless ($f{$_}=~/^\!/) { + unless (($f{$_}=~/^\!/) || ($row==0)) { @assessdata=&exportsheet(&getuname($safeeval), &getudom($safeeval), 'assesscalc',$f{$_}); @@ -1251,14 +1258,14 @@ sub loadcourse { '
'+ '
'+ ''); - popwin.document.close; + popwin.document.close(); ENDPOP $r->rflush(); map { if ($_=~/^A(\d+)/) { my $row=$1; - unless ($f{$_}=~/^\!/) { + unless (($f{$_}=~/^\!/) || ($row==0)) { my @studentdata=&exportsheet(split(/\:/,$f{$_}), 'studentcalc'); undef %userrdatas; @@ -1289,7 +1296,7 @@ ENDPOP } keys %f; &setformulas($safeeval,%f); &setconstants($safeeval,%c); - $r->print(''); + $r->print(''); $r->rflush(); } @@ -1481,14 +1488,94 @@ sub loadrows { # sub exportsheet { - - my ($uname,$udom,$stype,$usymb,$fn)=@_; + my ($uname,$udom,$stype,$usymb,$fn)=@_; + my @exportarr=(); +# +# Check if cached +# + my $key=$uname.':'.$udom.':'.$stype.':'.$usymb; + my $found=''; + + if ($oldsheets{$key}) { + map { + my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_); + if ($name eq $fn) { + $found=$value; + } + } split(/\_\_\_\&\_\_\_/,$oldsheets{$key}); + } + + if ($found) { +# +# Return what was cached +# + @exportarr=split(/\_\_\_\;\_\_\_/,$found); + + } else { +# +# Not cached +# my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb); &readsheet($thissheet,$fn); &updatesheet($thissheet); &loadrows($thissheet); - &calcsheet($thissheet); - return &exportdata($thissheet); + &calcsheet($thissheet); + @exportarr=&exportdata($thissheet); +# +# Store now +# + my $cid=$ENV{'request.course.id'}; + my $current=&Apache::lonnet::reply('get:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets:'. + &Apache::lonnet::escape($key), + $ENV{'course.'.$cid.'.home'}); + my %currentlystored=(); + unless ($current=~/^error\:/) { + map { + my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_); + $currentlystored{$name}=$value; + } split(/\_\_\_\&\_\_\_/,&Apache::lonnet::unescape($current)); + } + $currentlystored{$fn}=join('___;___',@exportarr); + + my $newstore=''; + map { + if ($newstore) { $newstore.='___&___'; } + $newstore.=$_.'___=___'.$currentlystored{$_}; + } keys %currentlystored; + &Apache::lonnet::reply('put:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets:'. + &Apache::lonnet::escape($key).'='. + &Apache::lonnet::escape($newstore), + $ENV{'course.'.$cid.'.home'}); + } + return @exportarr; +} + +# ===================================================== Calculated sheets cache +# +# Load all previously cached spreadsheets for this course +# + +sub cachedsheets { + my $cid=$ENV{'request.course.id'}; + my $reply=&Apache::lonnet::reply('dump:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets', + $ENV{'course.'.$cid.'.home'}); + undef %oldsheets; + unless ($reply=~/^error\:/) { + map { + my ($name,$value)=split(/\=/,$_); + $oldsheets{&Apache::lonnet::unescape($name)} + =&Apache::lonnet::unescape($value); + } split(/\&/,$reply); + } } # ================================================================ Main handler @@ -1659,10 +1746,13 @@ ENDSCRIPT $r->print(&hiddenfield('ufn',&getfilename($asheet))); +# ----------------------------------------------------------- Get cached sheets + + &cachedsheets(); # ----------------------------------------------------- Update sheet, load rows - $r->print("Loaded sheet, updating rows ...
\n"); + $r->print("Loaded sheet(s), updating rows ...
\n"); $r->rflush(); &updatesheet($asheet); @@ -1694,19 +1784,3 @@ ENDSCRIPT 1; __END__ - - - - - - - - - - - - - - - -