[LON-CAPA-cvs] cvs: loncom(version_1_0_2) /interface/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm studentcalc.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 05 Dec 2003 22:24:20 -0000
This is a MIME encoded message
--matthew1070663060
Content-Type: text/plain
matthew Fri Dec 5 17:24:20 2003 EDT
Modified files: (Branch: version_1_0_2)
/loncom/interface/spreadsheet Spreadsheet.pm assesscalc.pm
classcalc.pm studentcalc.pm
Log:
Backport of changes to make spreadsheet report calculation errors and not
save bogus data.
--matthew1070663060
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20031205172420.txt"
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.21 loncom/interface/spreadsheet/Spreadsheet.pm:1.21.2.1
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.21 Tue Aug 26 15:14:06 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm Fri Dec 5 17:24:20 2003
@@ -1,5 +1,5 @@
#
-# $Id: Spreadsheet.pm,v 1.21 2003/08/26 19:14:06 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.21.2.1 2003/12/05 22:24:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -659,7 +659,7 @@
return $lastcalc.': Maximum calculation depth exceeded';
}
}
- return '';
+ return 'okay';
}
# ------------------------------------------- End of "Inside of the safe space"
@@ -1121,9 +1121,51 @@
# $self->logthis($self->get_errorlog());
%{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
# $self->logthis($self->get_errorlog());
+ if ($result ne 'okay') {
+ $self->set_calcerror($result);
+ }
return $result;
}
+
+sub set_badcalc {
+ my $self = shift();
+ $self->{'badcalc'} =1;
+ return;
+}
+
+sub badcalc {
+ my $self = shift;
+ if (exists($self->{'badcalc'}) && $self->{'badcalc'}) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub set_calcerror {
+ my $self = shift;
+ if (@_) {
+ $self->set_badcalc();
+ if (exists($self->{'calcerror'})) {
+ $self->{'calcerror'}.="\n".$_[0];
+ } else {
+ $self->{'calcerror'}.=$_[0];
+ }
+ }
+}
+
+sub calcerror {
+ my $self = shift;
+ if ($self->badcalc()) {
+ if (exists($self->{'calcerror'})) {
+ return $self->{'calcerror'};
+ }
+ }
+ return;
+}
+
+
###########################################################
##
## Output Helpers
@@ -1150,6 +1192,18 @@
############################################
## HTML output routines ##
############################################
+sub html_report_error {
+ my $self = shift();
+ my $Str = '';
+ if ($self->badcalc()) {
+ $Str = '<h3 style="color:red">'.
+ 'An error occurred while calculating this spreadsheet'.
+ "</h3>\n".
+ '<pre>'.$self->calcerror()."</pre>\n";
+ }
+ return $Str;
+}
+
sub html_export_row {
my $self = shift();
my ($color) = @_;
@@ -1365,6 +1419,7 @@
#
# Close the excel file
$workbook->close();
+ $r->print($self->html_report_error());
#
# Write a link to allow them to download it
$r->print('<br />'.
@@ -1405,6 +1460,7 @@
#
# Close the csv file
close($file);
+ $r->print($self->html_report_error());
$r->print('<br /><br />'.
'<a href="'.$filename.'">Your CSV spreadsheet.</a>'."\n");
#
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.17.2.2 loncom/interface/spreadsheet/assesscalc.pm:1.17.2.3
--- loncom/interface/spreadsheet/assesscalc.pm:1.17.2.2 Fri Oct 3 11:39:46 2003
+++ loncom/interface/spreadsheet/assesscalc.pm Fri Dec 5 17:24:20 2003
@@ -1,5 +1,5 @@
#
-# $Id: assesscalc.pm,v 1.17.2.2 2003/10/03 15:39:46 albertel Exp $
+# $Id: assesscalc.pm,v 1.17.2.3 2003/12/05 22:24:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -374,6 +374,10 @@
sub outsheet_html {
my $self = shift;
my ($r) = @_;
+ ####################################
+ # Report any calculation errors #
+ ####################################
+ $r->print($self->html_report_error());
###################################
# Determine table structure
###################################
@@ -744,13 +748,20 @@
! defined($Exportrows{$symb}->{$self->{'filename'}})) {
$self->compute();
}
- 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;
}
@@ -773,6 +784,11 @@
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;
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.10 loncom/interface/spreadsheet/classcalc.pm:1.10.2.1
--- loncom/interface/spreadsheet/classcalc.pm:1.10 Mon Jun 23 15:58:18 2003
+++ loncom/interface/spreadsheet/classcalc.pm Fri Dec 5 17:24:20 2003
@@ -1,5 +1,5 @@
#
-# $Id: classcalc.pm,v 1.10 2003/06/23 19:58:18 matthew Exp $
+# $Id: classcalc.pm,v 1.10.2.1 2003/12/05 22:24:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -109,6 +109,10 @@
sub outsheet_html {
my $self = shift;
my ($r) = @_;
+ ####################################
+ # Report any calculation errors #
+ ####################################
+ $r->print($self->html_report_error());
###################################
# Determine table structure
###################################
@@ -271,6 +275,10 @@
my $studentsheet = Apache::studentcalc->new
($student->{'username'},$student->{'domain'},undef);
my @exportdata = $studentsheet->export_data();
+ if ($studentsheet->badcalc()) {
+ $self->set_calcerror($sname.' : '.
+ $studentsheet->calcerror());
+ }
my $rownum = $self->get_row_number_from_key($sname);
$f{'A'.$rownum} = $sname;
$self->{'row_source'}->{$rownum} = $sname;
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.16 loncom/interface/spreadsheet/studentcalc.pm:1.16.2.1
--- loncom/interface/spreadsheet/studentcalc.pm:1.16 Fri Aug 1 09:33:41 2003
+++ loncom/interface/spreadsheet/studentcalc.pm Fri Dec 5 17:24:20 2003
@@ -1,5 +1,5 @@
#
-# $Id: studentcalc.pm,v 1.16 2003/08/01 13:33:41 matthew Exp $
+# $Id: studentcalc.pm,v 1.16.2.1 2003/12/05 22:24:20 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -174,6 +174,10 @@
my $editing_is_allowed = &Apache::lonnet::allowed('mgr',
$ENV{'request.course.id'});
####################################
+ # Report any calculation errors #
+ ####################################
+ $r->print($self->html_report_error());
+ ####################################
# Determine table structure #
####################################
my $num_uneditable = 26;
@@ -452,6 +456,12 @@
$assess_filename,
$resource->{'symb'});
my @exportdata = $assessSheet->export_data();
+ if ($assessSheet->badcalc()) {
+ $self->set_calcerror(
+ 'Error computing row for assessment '.
+ $assessSheet->get_title().'(row '.$rownum.'):'.
+ $assessSheet->calcerror());
+ }
if ($assessSheet->blackout()) {
$self->blackout(1);
$self->{'blackout_rows'}->{$rownum} = 1;
@@ -581,6 +591,11 @@
my $self = shift;
return if ($self->temporary());
my $student = $self->{'name'}.':'.$self->{'domain'};
+ if ($self->badcalc()){
+ # do not save data away when calculations have not been done properly.
+ delete($Exportrows{$student});
+ return;
+ }
return if (! exists($Exportrows{$student}));
return if (! $self->is_default());
my $key = join(':',($self->{'name'},$self->{'domain'},'studentcalc')).':';
@@ -622,9 +637,16 @@
! $self->check_expiration_time($Exportrows{$student}->{'time'})) {
$self->compute();
}
- my @Data = @{$Exportrows{$student}->{'data'}};
- 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{$student}->{'data'}};
+ for (my $i=0; $i<=$#Data;$i++) {
+ if ($Data[$i]=~/\D/ && defined($Data[$i])) {
+ $Data[$i]="'".$Data[$i]."'";
+ }
+ }
}
return @Data;
}
--matthew1070663060--