--- loncom/interface/spreadsheet/studentcalc.pm 2003/05/29 13:39:38 1.8 +++ loncom/interface/spreadsheet/studentcalc.pm 2003/12/05 22:24:20 1.16.2.1 @@ -1,5 +1,5 @@ # -# $Id: studentcalc.pm,v 1.8 2003/05/29 13:39:38 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 # @@ -65,6 +65,7 @@ my %Exportrows = (); my $current_course; sub initialize { + &Apache::assesscalc::initialize(); &initialize_sequence_cache(); } @@ -143,9 +144,29 @@ sub parent_link { return $link; } +sub convenience_links { + my $self = shift; + my ($resource) = @_; + my $symb = &Apache::lonnet::escape($resource->{'symb'}); + my $result = <<"END"; + + + + + + + + + +END + return $result; +} + sub outsheet_html { my $self = shift; my ($r) = @_; + my $importcolor = '#FFFFAA'; + my $exportcolor = '#88FF88'; #################################### # Get the list of assessment files # #################################### @@ -153,6 +174,10 @@ sub outsheet_html { 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; @@ -162,7 +187,7 @@ sub outsheet_html { - @@ -171,7 +196,7 @@ END my $label_num = 0; foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader .=''. - $self->html_template_row($num_uneditable)."\n"); + $self->html_template_row($num_uneditable, + $importcolor)."\n"); } # # Print out summary/export row $r->print(''. - $self->html_export_row()."\n"); + $self->html_export_row($exportcolor)."\n"); } $r->print("
Student + Import Calculations'; + $tableheader .=''; } else { $tableheader .=''; } @@ -190,12 +215,13 @@ END # Print out template row if (exists($ENV{'request.role.adv'}) && $ENV{'request.role.adv'}) { $r->print('
Template 
Summary0
\n"); # @@ -204,7 +230,7 @@ END $tableheader =<<"END";

- + END } else { $tableheader =<<"END"; @@ -238,6 +264,7 @@ END my $row_output = ''; if ($editing_is_allowed) { $row_output .= ''; + $row_output .= ''; $row_output .= ''."\n"; } else { - $row_output .= $self->html_row($num_uneditable,$rownum). + $row_output .= $self->html_row($num_uneditable,$rownum, + $exportcolor,$importcolor). "\n"; } $r->print($row_output); @@ -332,7 +360,7 @@ sub csv_rows { # # Write a header row $self->csv_output_row($filehandle,undef, - ('Container','Assessment title')); + ('Sequence or Folder','Assessment title')); # # Write each assessments row if (scalar(@Sequences)< 1) { @@ -385,21 +413,8 @@ sub outsheet_recursive_excel { my ($r) = @_; } -sub set_row_sources { - my $self = shift; - while (my ($cell,$value) = each(%{$self->{'formulas'}})) { - next if ($cell !~ /^A(\d+)/ && $1 > 0); - my $row = $1; - (undef,$value) = split('__&&&__',$value); - $value = 'Default' if (! defined($value)); - $self->{'row_source'}->{$row} = $value; - } - return; -} - sub compute { my $self = shift; - $self->logthis('computing'); if (! defined($current_course) || $current_course ne $ENV{'request.course.id'}) { $current_course = $ENV{'request.course.id'}; @@ -441,6 +456,12 @@ sub compute { $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; @@ -474,6 +495,20 @@ sub compute { $Exportrows{$student}->{'data'} = \@exportarray; # save export row $self->save_export_data(); + # + $self->save() if ($self->need_to_save()); + return; +} + +sub set_row_sources { + my $self = shift; + while (my ($cell,$value) = each(%{$self->{'formulas'}})) { + next if ($cell !~ /^A(\d+)/ && $1 > 0); + my $row = $1; + (undef,$value) = split('__&&&__',$value); + $value = 'Default' if (! defined($value)); + $self->{'row_source'}->{$row} = $value; + } return; } @@ -485,6 +520,7 @@ sub set_row_numbers { next if ($row == 0); my ($symb,undef) = split('__&&&__',$formula); $self->{'row_numbers'}->{$symb} = $row; + $self->{'maxrow'} = $1 if ($1 > $self->{'maxrow'}); } } @@ -555,6 +591,11 @@ sub save_export_data { 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')).':'; @@ -562,7 +603,7 @@ sub save_export_data { my $newstore = join('___;___', @{$Exportrows{$student}->{'data'}}); $newstore = '___=___'.$newstore; - &Apache::lonnet::put('nohist_calculatedsheets', + my $result= &Apache::lonnet::put('nohist_calculatedsheets', { $key => $newstore, $timekey => $Exportrows{$student}->{'time'} }, $self->{'cdom'}, @@ -588,12 +629,24 @@ sub export_data { my $self = shift; my $student = $self->{'name'}.':'.$self->{'domain'}; if (! exists($Exportrows{$student}) || + ! defined($Exportrows{$student}) || + ! exists($Exportrows{$student}->{'data'}) || + ! defined($Exportrows{$student}->{'data'}) || + ! exists($Exportrows{$student}->{'time'}) || + ! defined($Exportrows{$student}->{'time'}) || ! $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; }
RowAssessment
Row Assessment
'.$rownum.''.$self->convenience_links($resource).''. 'Unavailable at this time