[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm studentcalc.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 17 Nov 2003 19:55:41 -0000


This is a MIME encoded message

--matthew1069098941
Content-Type: text/plain

matthew		Mon Nov 17 14:55:41 2003 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm assesscalc.pm 
                                 	studentcalc.pm classcalc.pm 
  Log:
  Fix bug in error reporting where errors in computation of the spreadsheet
  were not reported and bad cache values were stored away.
  Added in Spreadsheet: &set_badcalc, &badcalc, &set_calcerror, &calcerror,
  and &html_report_error.  These are used to keep track of computation errors
  and to report them to the user.  The &save_export_data routines were all
  modified to not store data when an error has occured.
  
  
--matthew1069098941
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20031117145541.txt"

Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.29 loncom/interface/spreadsheet/Spreadsheet.pm:1.30
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.29	Tue Nov 11 09:17:20 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Mon Nov 17 14:55:41 2003
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.29 2003/11/11 14:17:20 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.30 2003/11/17 19:55:41 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -678,7 +678,7 @@
             return $lastcalc.': Maximum calculation depth exceeded';
         }
     }
-    return '';
+    return 'okay';
 }
 
 # ------------------------------------------- End of "Inside of the safe space"
@@ -1139,9 +1139,49 @@
 #    $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
@@ -1169,6 +1209,18 @@
 ############################################
 ##         HTML output routines           ##
 ############################################
+sub html_report_error {
+    my $self = shift();
+    my $Str = '';
+    if ($self->badcalc()) {
+        $Str = '<h3 style="color:red">'.
+            &mt('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) = @_;
@@ -1618,6 +1670,9 @@
 ##
 sub exportrow {
     my $self = shift;
+    if (exists($self->{'badcalc'}) && $self->{'badcalc'}) {
+        return ();
+    }
     my @exportarray;
     foreach my $column (@UC_Columns) {
         push(@exportarray,$self->value($column.'0'));
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.28 loncom/interface/spreadsheet/assesscalc.pm:1.29
--- loncom/interface/spreadsheet/assesscalc.pm:1.28	Tue Nov 11 10:36:28 2003
+++ loncom/interface/spreadsheet/assesscalc.pm	Mon Nov 17 14:55:41 2003
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.28 2003/11/11 15:36:28 matthew Exp $
+# $Id: assesscalc.pm,v 1.29 2003/11/17 19:55:41 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -368,7 +368,7 @@
 
 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 = '<h1>'.$assess_title.'</h1>'.
         '<h2>'.$name.', '.
         &Apache::loncommon::aboutmewrapper
@@ -380,17 +380,21 @@
 
 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'},
@@ -415,6 +419,10 @@
 sub outsheet_html {
     my $self = shift;
     my ($r) = @_;
+    ####################################
+    # Report any calculation errors    #
+    ####################################
+    $r->print($self->html_report_error());
     ###################################
     # Determine table structure
     ###################################
@@ -907,13 +915,20 @@
         $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 +951,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/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.23 loncom/interface/spreadsheet/studentcalc.pm:1.24
--- loncom/interface/spreadsheet/studentcalc.pm:1.23	Tue Oct 14 14:36:54 2003
+++ loncom/interface/spreadsheet/studentcalc.pm	Mon Nov 17 14:55:41 2003
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.23 2003/10/14 18:36:54 www Exp $
+# $Id: studentcalc.pm,v 1.24 2003/11/17 19:55:41 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;
@@ -527,11 +531,19 @@
             }
             $f{$cell} = $resource->{'symb'}.'__&&&__'.$assess_filename;
             if ($connection->aborted()) { $self->cleanup(); return; }
-            my $assessSheet = Apache::assesscalc->new($self->{'name'},
-                                                      $self->{'domain'},
-                                                      $assess_filename,
-                                                      $resource->{'symb'});
+            my $assessSheet;
+                $assessSheet = Apache::assesscalc->new($self->{'name'},
+                                                       $self->{'domain'},
+                                                       $assess_filename,
+                                                       $resource->{'symb'});
             my @exportdata = $assessSheet->export_data($r);
+            #
+            if ($assessSheet->badcalc()) {
+                $self->set_calcerror(
+            &mt('Error computing row for assessment "[_1]" (row [_2]):[_3]',
+                $assessSheet->get_title(),$rownum,$assessSheet->calcerror()));
+            }
+            #
             if ($connection->aborted()) { $self->cleanup(); return; }
             if ($assessSheet->blackout()) {
                 $self->blackout(1);
@@ -662,11 +674,16 @@
 #############################################
 sub save_export_data {
     my $self = shift;
-    &Apache::assesscalc::save_cached_export_rows($self->{'name'},
-                                                 $self->{'domain'});
-    return if ($self->temporary());
     my $student = $self->{'name'}.':'.$self->{'domain'};
+    return if ($self->temporary());
+    if ($self->badcalc()){
+        # do not save data away when calculations have not been done properly.
+        delete($Exportrows{$student});
+        return;
+    }
     return if (! exists($Exportrows{$student}));
+    &Apache::assesscalc::save_cached_export_rows($self->{'name'},
+                                                 $self->{'domain'});
     return if (! $self->is_default());
     my $key = join(':',($self->{'name'},$self->{'domain'},'studentcalc')).':';
     my $timekey = $key.'.time';
@@ -710,9 +727,16 @@
         $self->compute($r);
     }
     if ($connection->aborted()) { $self->cleanup(); return; }
-    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;
 }
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.14 loncom/interface/spreadsheet/classcalc.pm:1.15
--- loncom/interface/spreadsheet/classcalc.pm:1.14	Tue Oct 14 14:36:54 2003
+++ loncom/interface/spreadsheet/classcalc.pm	Mon Nov 17 14:55:41 2003
@@ -1,5 +1,5 @@
 #
-# $Id: classcalc.pm,v 1.14 2003/10/14 18:36:54 www Exp $
+# $Id: classcalc.pm,v 1.15 2003/11/17 19:55:41 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -117,6 +117,10 @@
 sub outsheet_html {
     my $self = shift;
     my ($r) = @_;
+    ####################################
+    # Report any calculation errors    #
+    ####################################
+    $r->print($self->html_report_error());
     ###################################
     # Determine table structure
     ###################################
@@ -247,7 +251,6 @@
     my ($connection,$filehandle) = @_;
     #
     # Write a header row
-
     $self->csv_output_row($filehandle,undef,
                    (&mt('Fullname'),&mt('Username'),&mt('Domain'),&mt('Section'),&mt('Status'),&mt('ID')));
     #
@@ -270,7 +273,7 @@
 sub outsheet_recursive_excel {
     my $self = shift;
     my ($r) = @_;
-} 
+}
 
 sub compute {
     my $self = shift;
@@ -295,6 +298,10 @@
 	    ($student->{'username'},$student->{'domain'},undef);
         if ($connection->aborted()) { $self->cleanup(); return; }
 	my @exportdata = $studentsheet->export_data($r);
+        if ($studentsheet->badcalc()) {
+            $self->set_calcerror($sname.' : '.
+                                 $studentsheet->calcerror());
+        }
         if ($connection->aborted()) { $self->cleanup(); return; }
 	my $rownum = $self->get_row_number_from_key($sname);
         $f{'A'.$rownum} = $sname;

--matthew1069098941--