--- loncom/interface/spreadsheet/assesscalc.pm 2003/11/11 15:36:28 1.28
+++ loncom/interface/spreadsheet/assesscalc.pm 2005/03/03 17:52:36 1.37
@@ -1,5 +1,5 @@
#
-# $Id: assesscalc.pm,v 1.28 2003/11/11 15:36:28 matthew Exp $
+# $Id: assesscalc.pm,v 1.37 2005/03/03 17:52:36 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -104,6 +104,7 @@ my %nice_parameter_name;
my %useropt;
my %userdata;
my %courseopt;
+my $navmap;
########################################################
########################################################
@@ -136,11 +137,11 @@ sub clear_package {
undef(%useropt);
undef(%userdata);
undef(%courseopt);
+ undef($navmap);
}
sub save_cached_export_rows {
my ($sname,$sdomain) = @_;
- my $start = Time::HiRes::time;
my $result = &Apache::lonnet::put
('nohist_calculatedsheets_'.$ENV{'request.course.id'},
$newExportrows{$sname.':'.$sdomain},
@@ -149,7 +150,15 @@ sub save_cached_export_rows {
}
sub initialize {
+ my ($in_navmap) = @_;
&clear_package();
+ $navmap = $in_navmap;
+ if (! defined($navmap)) {
+ $navmap = Apache::lonnavmaps::navmap->new();
+ }
+ if (!defined($navmap)) {
+ &Apache::lonnet::logthis('assesscalc:Can not open Coursemap');
+ }
&Apache::loncoursedata::clear_internal_caches();
}
@@ -165,9 +174,10 @@ sub initialize {
########################################################
########################################################
sub initialize_package {
- my ($sname,$sdomain) = @_;
+ my ($sname,$sdomain,$in_navmap) = @_;
$current_name = $sname;
$current_domain = $sdomain;
+ $navmap = $in_navmap;
undef(%useropt);
undef(%userdata);
if ($current_course ne $ENV{'request.course.id'}) {
@@ -337,18 +347,19 @@ sub parmval {
#
# check course
return $courseopt{$courselevelr} if (defined($courseopt{$courselevelr}));
- return $courseopt{$courselevelm} if (defined($courseopt{$courselevelm}));
- return $courseopt{$courselevel} if (defined($courseopt{$courselevel}));
# check map parms
my $thisparm = $parmhash{$symbparm};
return $thisparm if (defined($thisparm));
# check default
$thisparm = &Apache::lonnet::metadata($fn,$rwhat.'.default');
return $thisparm if (defined($thisparm));
- #
+ # check more course
+ return $courseopt{$courselevelm} if (defined($courseopt{$courselevelm}));
+ return $courseopt{$courselevel} if (defined($courseopt{$courselevel}));
+
# Cascade Up
my $space=$what;
- $space=~s/\.\w+$//;
+ $space=~s/\.[^._]+$//;
if ($space ne '0') {
my @parts=split(/_/,$space);
my $id=pop(@parts);
@@ -368,7 +379,7 @@ sub parmval {
sub get_html_title {
my $self = shift;
- my ($assess_title,$name,$time) = $self->get_title();
+ my ($assess_title,$name,$time) = $self->get_full_title();
my $title = '
'.$assess_title.'
'.
''.$name.', '.
&Apache::loncommon::aboutmewrapper
@@ -380,24 +391,25 @@ sub get_html_title {
sub get_title {
my $self = shift;
- my @title = ();
if (($self->{'symb'} eq '_feedback') ||
($self->{'symb'} eq '_evaluation') ||
($self->{'symb'} eq '_discussion') ||
($self->{'symb'} eq '_tutoring')) {
my $assess_title = ucfirst($self->{'symb'});
$assess_title =~ s/^_//;
- push(@title,$assess_title);
+ return $assess_title;
} else {
- push(@title,&Apache::lonnet::gettitle($self->{'symb'}));
+ return &Apache::lonnet::gettitle($self->{'symb'});
}
+}
+
+sub get_full_title {
+ my $self = shift;
+ my @title = ($self->get_title());
# Look up the users identifying information
# Get the users information
- my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'},
- $self->{'domain'});
- my $name =
- join(' ',@userenv{'firstname','middlename','lastname','generation'});
- $name =~ s/\s+$//;
+ my $name = &Apache::loncommon::plainname($self->{'name'},
+ $self->{'domain'});
push (@title,$name);
push (@title,&Apache::lonlocal::locallocaltime(time));
return @title;
@@ -415,6 +427,10 @@ sub parent_link {
sub outsheet_html {
my $self = shift;
my ($r) = @_;
+ ####################################
+ # Report any calculation errors #
+ ####################################
+ $r->print($self->html_report_error());
###################################
# Determine table structure
###################################
@@ -523,7 +539,7 @@ sub csv_rows {
# writes the meat of the spreadsheet to an excel worksheet. Called
# by Spreadsheet::outsheet_excel;
my $self = shift;
- my ($filehandle) = @_;
+ my ($connection,$filehandle) = @_;
#
# Write a header row
$self->csv_output_row($filehandle,undef,
@@ -546,12 +562,13 @@ sub excel_rows {
# writes the meat of the spreadsheet to an excel worksheet. Called
# by Spreadsheet::outsheet_excel;
my $self = shift;
- my ($worksheet,$cols_output,$rows_output) = @_;
+ my ($connection,$worksheet,$cols_output,$rows_output) = @_;
+ return if (! ref($worksheet));
#
# Write a header row
$cols_output = 0;
foreach my $value ('Parameter','Description','Value') {
- $worksheet->write($rows_output,$cols_output++,&mt($value));
+ $worksheet->write($rows_output,$cols_output++,$value);
}
$rows_output++;
#
@@ -772,7 +789,10 @@ sub compute {
while (my ($parm,$value) = each(%parameters)) {
my $cell = 'A'.$self->get_row_number_from_key($parm);
$f{$cell} = $parm;
- $value = '"'.$value.'"' if ($value =~/[^0-9.]/);
+ if ($parm =~ /_submission$/ && $value =~ /(\{|\})/) {
+ $value = 'witheld';
+ }
+ $value = 'q{'.$value.'}' if ($value =~/([^\d\.]|\.\.)/);
$c{$parm} = $value;
}
$self->formulas(\%f);
@@ -864,6 +884,10 @@ sub load_cached_export_rows {
# We only got one key, so we will access it directly.
while (my ($key,$sheetdata) = each(%tmp)) {
my ($sname,$sdom,$sheettype,$symb) = split(':',$key);
+ if (! defined($sname) || $sname eq '' ||
+ ! defined($sdom) || $sdom eq '' ) {
+ next;
+ }
if ($symb =~ /\.time$/) {
$symb =~ s/\.time$//;
$Exportrows{$symb}->{'time'} = $sheetdata;
@@ -907,13 +931,20 @@ sub export_data {
$self->compute($r);
}
if ($connection->aborted()) { $self->cleanup(); return; }
- my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}};
- if ($Data[0] =~ /^(.*)___=___/) {
- $self->{'sheetname'} = $1;
- $Data[0] =~ s/^(.*)___=___//;
- }
- for (my $i=0;$i<$#Data;$i++) {
- $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i]));
+ my @Data;
+ if ($self->badcalc()) {
+ @Data = ();
+ } else {
+ @Data = @{$Exportrows{$symb}->{$self->{'filename'}}};
+ if ($Data[0] =~ /^(.*)___=___/) {
+ $self->{'sheetname'} = $1;
+ $Data[0] =~ s/^(.*)___=___//;
+ }
+ for (my $i=0;$i<$#Data;$i++) {
+ if ($Data[$i]=~/\D/ && defined($Data[$i])) {
+ $Data[$i]="'".$Data[$i]."'";
+ }
+ }
}
return @Data;
}
@@ -936,6 +967,11 @@ sub save_export_data {
return if ($self->temporary());
my $student = $self->{'name'}.':'.$self->{'domain'};
my $symb = $self->{'symb'};
+ if ($self->badcalc()){
+ # do not save data away when calculations have not been done properly.
+ delete($Exportrows{$symb});
+ return;
+ }
if (! exists($Exportrows{$symb}) ||
! exists($Exportrows{$symb}->{$self->{'filename'}})) {
return;