--- loncom/interface/spreadsheet/classcalc.pm 2003/05/27 14:52:45 1.5 +++ loncom/interface/spreadsheet/classcalc.pm 2003/09/10 14:47:42 1.13 @@ -1,5 +1,5 @@ # -# $Id: classcalc.pm,v 1.5 2003/05/27 14:52:45 matthew Exp $ +# $Id: classcalc.pm,v 1.13 2003/09/10 14:47:42 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,8 @@ classcalc package Apache::classcalc; use strict; +use warnings FATAL=>'all'; +no warnings 'uninitialized'; use Apache::Constants qw(:common :http); use Apache::loncoursedata(); use Apache::lonhtmlcommon(); @@ -59,6 +61,23 @@ use Time::HiRes; @Apache::classcalc::ISA = ('Apache::Spreadsheet'); +## +## Package variable +## + +my @Students; + +sub initialize { + &Apache::lonstatistics::clear_classlist_variables(); + @Students = &Apache::lonstatistics::get_students(); + return; +} + +sub clear_package { + undef(@Students); + &Apache::studentcalc::clear_package(); +} + sub html_header { my $self = shift; my ($toprow,$bottomrow); @@ -76,12 +95,6 @@ sub html_header { "\n

"; } -sub get_classlist { - my $self = shift; - # Retrieve the classlist and return it - return &Apache::lonstatistics::get_students(); -} - sub get_title { my $self = shift; # Section info should be included @@ -106,6 +119,8 @@ sub outsheet_html { ################################### # Determine table structure ################################### + my $importcolor = '#88FF88'; + my $exportcolor = '#BBBBFF'; my $num_uneditable = 26; my $num_left = 52-$num_uneditable; my $tableheader =<<"END"; @@ -113,7 +128,7 @@ sub outsheet_html { - @@ -122,7 +137,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"); # # Prepare to output rows $tableheader =<<"END"; @@ -151,7 +167,7 @@ END END foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){ if ($label_num<$num_uneditable) { - $tableheader.='
Course + Import Calculations'; + $tableheader.=''; } else { $tableheader.=''; } @@ -135,11 +150,12 @@ END # # Print out template row $r->print('
Template 
Summary0
'; + $tableheader.=''; } else { $tableheader.=''; } @@ -159,7 +175,7 @@ END } # my $num_output = 0; - foreach my $student ($self->get_classlist()) { + foreach my $student (@Students) { if ($num_output++ % 50 == 0) { $r->print("
\n".$tableheader); } @@ -169,12 +185,14 @@ END '&sdomain='.$student->{'domain'}.'">'; $student->{'section'} = 'none' if ($student->{'section'} eq '-1'); $r->print(''.''.$rownum.''. - ''.$link.$student->{'fullname'}.''. - ''.$student->{'username'}.''. + ''.$student->{'fullname'}.''. + ''.$link.$student->{'username'}.''. ''.$student->{'domain'} .''. ''.$student->{'section'} .''. ''.$student->{'status'} .''. - $self->html_row($num_uneditable,$rownum)."\n"); + $self->html_row($num_uneditable,$rownum,$exportcolor, + $importcolor). + "\n"); } $r->print("

\n"); return; @@ -184,17 +202,17 @@ 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) = @_; # # Write a header row $cols_output = 0; - foreach my $value ('fullname','username','domain','section','status') { + foreach my $value ('fullname','username','domain','section','status','id') { $worksheet->write($rows_output,$cols_output++,$value); } $rows_output++; # # Write each students row - foreach my $student ($self->get_classlist()) { + foreach my $student (@Students) { $cols_output = 0; my $rownum = $self->get_row_number_from_key ($student->{'username'}.':'.$student->{'domain'}); @@ -203,7 +221,8 @@ sub excel_rows { $student->{'username'}, $student->{'domain'}, $student->{'section'}, - $student->{'status'}); + $student->{'status'}, + $student->{'id'}); $self->excel_output_row($worksheet,$rownum,$rows_output++, @studentdata); } @@ -214,15 +233,15 @@ 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, - ('fullname','username','domain','section','status')); + ('fullname','username','domain','section','status','id')); # # Write each students row - foreach my $student ($self->get_classlist()) { + foreach my $student (@Students) { my $rownum = $self->get_row_number_from_key ($student->{'username'}.':'.$student->{'domain'}); $student->{'section'} = 'none' if ($student->{'section'} eq '-1'); @@ -230,7 +249,8 @@ sub csv_rows { $student->{'username'}, $student->{'domain'}, $student->{'section'}, - $student->{'status'}); + $student->{'status'}, + $student->{'id'}); $self->csv_output_row($filehandle,$rownum,@studentdata); } return; @@ -244,19 +264,27 @@ sub outsheet_recursive_excel { sub compute { my $self = shift; my ($r) = @_; + my $connection = $r->connection(); + if ($connection->aborted()) { $self->cleanup(); return; } $self->initialize_safe_space(); my %c = $self->constants(); my %f = $self->formulas(); - my @Students = $self->get_classlist(); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin ($r,'Spreadsheet Computation Status', 'Spreadsheet Computation', scalar(@Students)); + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, + 'Processing course structure'); &Apache::studentcalc::initialize_package(); - foreach my $student ($self->get_classlist()) { + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, + 'Processing first student'); + foreach my $student (@Students) { + if ($connection->aborted()) { $self->cleanup(); return; } my $sname = $student->{'username'}.':'.$student->{'domain'}; my $studentsheet = Apache::studentcalc->new ($student->{'username'},$student->{'domain'},undef); - my @exportdata = $studentsheet->export_data(); + if ($connection->aborted()) { $self->cleanup(); return; } + my @exportdata = $studentsheet->export_data($r); + if ($connection->aborted()) { $self->cleanup(); return; } my $rownum = $self->get_row_number_from_key($sname); $f{'A'.$rownum} = $sname; $self->{'row_source'}->{$rownum} = $sname; @@ -277,6 +305,7 @@ sub compute { $self->constants(\%c); $self->formulas(\%f); $self->calcsheet(); + $self->save() if ($self->need_to_save()); } 1;