version 1.164, 2003/01/29 16:26:08
|
version 1.165, 2003/01/30 16:20:08
|
Line 487 use GDBM_File;
|
Line 487 use GDBM_File;
|
use HTML::Entities(); |
use HTML::Entities(); |
use HTML::TokeParser; |
use HTML::TokeParser; |
use Spreadsheet::WriteExcel; |
use Spreadsheet::WriteExcel; |
|
use Time::HiRes; |
|
|
# |
# |
# These global hashes are dependent on user, course and resource, |
# These global hashes are dependent on user, course and resource, |
# and need to be initialized every time when a sheet is calculated |
# and need to be initialized every time when a sheet is calculated |
Line 756 sub new {
|
Line 758 sub new {
|
chome => $ENV{'course.'.$ENV{'request.course.id'}.'.home'}, |
chome => $ENV{'course.'.$ENV{'request.course.id'}.'.home'}, |
coursefilename => $ENV{'request.course.fn'}, |
coursefilename => $ENV{'request.course.fn'}, |
coursedesc => $ENV{'course.'.$ENV{'request.course.id'}.'.description'}, |
coursedesc => $ENV{'course.'.$ENV{'request.course.id'}.'.description'}, |
A_column => [], |
rows => [], |
template_cells => [], |
template_cells => [], |
}; |
}; |
$self->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
$self->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
Line 1583 sub sett {
|
Line 1585 sub sett {
|
$pattern='[A-Z]'; |
$pattern='[A-Z]'; |
} |
} |
# Deal with the template row |
# Deal with the template row |
foreach ($self->template_cells()) { |
foreach my $col ($self->template_cells()) { |
my ($col) = ($_=~/template\_(\w)/); |
|
next if ($col=~/^$pattern/); |
next if ($col=~/^$pattern/); |
foreach ($self->A_column()) { |
foreach my $trow ($self->rows()) { |
my ($trow)=($_!~/A(\d+)/); |
next if ($trow eq '0'); |
next if (! $trow); |
|
# Get the name of this cell |
# Get the name of this cell |
my $lb=$col.$trow; |
my $lb=$col.$trow; |
# Grab the template declaration |
# Grab the template declaration |
Line 1745 sub calcsheet {
|
Line 1745 sub calcsheet {
|
$self->sett(); |
$self->sett(); |
my $result = $self->{'safe'}->reval('&calc();'); |
my $result = $self->{'safe'}->reval('&calc();'); |
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')}; |
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')}; |
# $self->logthis($self->get_errorlog()); |
|
# $self->logthis('number of values = '.(keys(%{$self->{'values'}}))); |
|
return $result; |
return $result; |
} |
} |
|
|
Line 1787 sub clear_errorlog {
|
Line 1785 sub clear_errorlog {
|
#### Spreadsheet content retrieval/setting methods ##### |
#### Spreadsheet content retrieval/setting methods ##### |
######################################################## |
######################################################## |
## |
## |
## contents: either set or get the constants. Cannot do both. It is just too |
## constants: either set or get the constants |
## clunky to swing around big hashes when we may not need to. |
## |
## |
## |
sub constants { |
sub constants { |
my $self=shift; |
my $self=shift; |
Line 1806 sub constants {
|
Line 1804 sub constants {
|
} |
} |
|
|
## |
## |
## formulas: either set or get the formulas. Cannot do both. It is just too |
## formulas: either set or get the formulas |
## clunky to swing around big hashes when we may not need to. |
## |
sub formulas { |
sub formulas { |
my $self=shift; |
my $self=shift; |
my ($formulas) = @_; |
my ($formulas) = @_; |
Line 1817 sub formulas {
|
Line 1815 sub formulas {
|
$formulas = \%tmp; |
$formulas = \%tmp; |
} |
} |
$self->{'formulas'} = $formulas; |
$self->{'formulas'} = $formulas; |
$self->{'A_column'} = []; |
$self->{'rows'} = []; |
$self->{'template_cells'} = []; |
$self->{'template_cells'} = []; |
return; |
return; |
} else { |
} else { |
Line 1831 sub formulas {
|
Line 1829 sub formulas {
|
sub formulas_keys { |
sub formulas_keys { |
my $self = shift; |
my $self = shift; |
my @keys = keys(%{$self->{'formulas'}}); |
my @keys = keys(%{$self->{'formulas'}}); |
# $self->logthis('formulas keys has '.@keys.' elements'); |
|
return keys(%{$self->{'formulas'}}); |
return keys(%{$self->{'formulas'}}); |
} |
} |
|
|
Line 1857 sub logthis {
|
Line 1854 sub logthis {
|
&Apache::lonnet::logthis($self->{'type'}.':'. |
&Apache::lonnet::logthis($self->{'type'}.':'. |
$self->{'uname'}.':'.$self->{'udom'}.':'. |
$self->{'uname'}.':'.$self->{'udom'}.':'. |
$message); |
$message); |
|
return; |
} |
} |
|
|
## |
## |
Line 1899 sub dump_values_to_log {
|
Line 1897 sub dump_values_to_log {
|
## Helper functions ## |
## Helper functions ## |
################################ |
################################ |
## |
## |
## rebuild_stats: rebuilds the A_column and template_cells arrays |
## rebuild_stats: rebuilds the rows and template_cells arrays |
## |
## |
sub rebuild_stats { |
sub rebuild_stats { |
my $self = shift; |
my $self = shift; |
$self->{'A_column'}=[]; |
$self->{'rows'}=[]; |
$self->{'template_cells'}=[]; |
$self->{'template_cells'}=[]; |
foreach my $cell($self->formulas_keys()) { |
foreach my $cell($self->formulas_keys()) { |
push(@{$self->{'A_column'}},$cell) if $cell =~ /^A\d+/; |
push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/); |
push(@{$self->{'template_cells'}},$cell) if ($cell =~ /^template_/); |
push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/); |
} |
} |
# $self->logthis('rebuilt A_column '.@{$self->{'A_column'}}); |
|
# $self->logthis('rebuilt tempate_cells '.@{$self->{'template_cells'}}); |
|
return; |
return; |
} |
} |
|
|
Line 1924 sub template_cells {
|
Line 1920 sub template_cells {
|
} |
} |
|
|
## |
## |
## A_column returns a list of the names of cells defined in the A column |
## rows returns a list of the names of cells defined in the A column |
## |
## |
sub A_column { |
sub rows { |
my $self = shift; |
my $self = shift; |
$self->rebuild_stats() if (!@{$self->{'A_column'}}); |
$self->rebuild_stats() if (!@{$self->{'rows'}}); |
return @{$self->{'A_column'}}; |
return @{$self->{'rows'}}; |
} |
} |
|
|
## |
## |
Line 2673 sub readsheet {
|
Line 2669 sub readsheet {
|
if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) { |
if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) { |
my %tmp = split(/___;___/,$fstring); |
my %tmp = split(/___;___/,$fstring); |
$self->formulas(\%tmp); |
$self->formulas(\%tmp); |
# $self->logthis('readsheet found cached '); |
|
# $self->dump_formulas_to_log(); |
|
} else { |
} else { |
# Not cached, need to read |
# Not cached, need to read |
my %f=(); |
my %f=(); |
Line 2725 sub readsheet {
|
Line 2719 sub readsheet {
|
# Cache and set |
# Cache and set |
$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f); |
$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f); |
$self->formulas(\%f); |
$self->formulas(\%f); |
# $self->logthis('readsheet loaded '); |
|
# $self->dump_formulas_to_log(); |
|
} |
} |
} |
} |
|
|
Line 2950 sub updateclasssheet {
|
Line 2942 sub updateclasssheet {
|
my %existing=(); |
my %existing=(); |
# |
# |
# Now obsolete rows |
# Now obsolete rows |
foreach my $cell ($self->A_column()) { |
foreach my $rownum ($self->rows()) { |
$cell =~ /^A(\d+)/; |
my $cell = 'A'.$rownum; |
if ($1 > $self->{'maxrow'}) { |
if ($rownum > $self->{'maxrow'}) { |
$self->{'maxrow'}= $1; |
$self->{'maxrow'}= $rownum; |
} |
} |
$existing{$f{$cell}}=1; |
$existing{$f{$cell}}=1; |
unless ((defined($currentlist{$f{$cell}})) || (!$1) || |
unless ((defined($currentlist{$f{$cell}})) || ($rownum ne '0') || |
($f{$cell}=~/^(~~~|---)/)) { |
($f{$cell}=~/^(~~~|---)/)) { |
$f{$cell}='!!! Obsolete'; |
$f{$cell}='!!! Obsolete'; |
$changed=1; |
$changed=1; |
Line 3104 sub updatestudentassesssheet {
|
Line 3096 sub updatestudentassesssheet {
|
$self->{'maxrow'} = 0; |
$self->{'maxrow'} = 0; |
my %existing=(); |
my %existing=(); |
# Now obsolete rows |
# Now obsolete rows |
foreach my $cell ($self->A_column()) { |
foreach my $rownum ($self->rows()) { |
|
my $cell = 'A'.$rownum; |
my $formula = $f{$cell}; |
my $formula = $f{$cell}; |
my ($n)= ($cell =~ /A(\d+)/); |
next if ($rownum eq '0'); |
next if ($n eq '0'); |
$self->{'maxrow'} = $rownum if ($rownum > $self->{'maxrow'}); |
$self->{'maxrow'} = $n if ($n > $self->{'maxrow'}); |
|
my ($usy,$ufn)=split(/__&&&\__/,$formula); |
my ($usy,$ufn)=split(/__&&&\__/,$formula); |
$existing{$usy}=1; |
$existing{$usy}=1; |
if ( ! exists($self->{'rowlabel'}->{$usy}) || |
if ( ! exists($self->{'rowlabel'}->{$usy}) || |
Line 3116 sub updatestudentassesssheet {
|
Line 3108 sub updatestudentassesssheet {
|
($formula =~ /^(~~~|---)/) || |
($formula =~ /^(~~~|---)/) || |
($formula =~ /^\s*$/)) { |
($formula =~ /^\s*$/)) { |
$f{$cell}='!!! Obsolete'; |
$f{$cell}='!!! Obsolete'; |
# $self->logthis('obsoleted row '.$n); |
|
$changed=1; |
$changed=1; |
} |
} |
} |
} |
Line 3150 sub loadstudent{
|
Line 3141 sub loadstudent{
|
undef @tmp; |
undef @tmp; |
# |
# |
my @assessdata=(); |
my @assessdata=(); |
foreach my $cell ($self->A_column()) { |
foreach my $row ($self->rows()) { |
|
my $cell = 'A'.$row; |
my $value = $formulas{$cell}; |
my $value = $formulas{$cell}; |
if(defined($c) && ($c->aborted())) { |
if(defined($c) && ($c->aborted())) { |
last; |
last; |
} |
} |
my ($row)=($cell=~/A(\d+)/); |
|
next if (($value =~ /^[!~-]/) || ($row==0)); |
next if (($value =~ /^[!~-]/) || ($row==0)); |
my ($usy,$ufn)=split(/__&&&\__/,$value); |
my ($usy,$ufn)=split(/__&&&\__/,$value); |
@assessdata=$self->exportsheet($self->{'uname'}, |
@assessdata=$self->exportsheet($self->{'uname'}, |
Line 3191 sub loadcourse {
|
Line 3182 sub loadcourse {
|
my %formulas=$self->formulas(); |
my %formulas=$self->formulas(); |
# |
# |
my $total=0; |
my $total=0; |
foreach ($self->A_column()) { |
foreach ($self->rows()) { |
$total++ if ($formulas{$_} !~ /^[!~-]/); |
$total++ if ($formulas{'A'.$_} !~ /^[!~-]/); |
} |
} |
my $now=0; |
my $now=0; |
my $since=time; |
my $since=time; |
Line 3208 sub loadcourse {
|
Line 3199 sub loadcourse {
|
</script> |
</script> |
ENDPOP |
ENDPOP |
$r->rflush(); |
$r->rflush(); |
foreach ($self->A_column()) { |
foreach my $row ($self->rows()) { |
if(defined($c) && ($c->aborted())) { |
if(defined($c) && ($c->aborted())) { |
last; |
last; |
} |
} |
my ($row)=(/A(\d+)/); |
my $cell = 'A'.$row; |
next if (($formulas{$_}=~/^[\!\~\-]/) || ($row==0)); |
next if (($formulas{$cell}=~/^[\!\~\-]/) || ($row==0)); |
my ($sname,$sdom) = split(':',$formulas{$_}); |
my ($sname,$sdom) = split(':',$formulas{$cell}); |
my $started = time; |
my $started = time; |
my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc', |
my @studentdata=$self->exportsheet($sname,$sdom,'studentcalc', |
undef,undef,$r); |
undef,undef,$r); |
Line 3342 sub loadassessment {
|
Line 3333 sub loadassessment {
|
if (tie(%parmhash,'GDBM_File', |
if (tie(%parmhash,'GDBM_File', |
$self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) { |
$self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) { |
my %f=$self->formulas(); |
my %f=$self->formulas(); |
foreach my $cell ($self->A_column()) { |
foreach my $row ($self->rows()) { |
|
my $cell = 'A'.$row; |
my $formula = $self->formula($cell); |
my $formula = $self->formula($cell); |
next if ($formula =~/^[\!\~\-]/); |
next if ($formula =~/^[\!\~\-]/); |
if ($formula =~ /^parameter/) { |
if ($formula =~ /^parameter/) { |