version 1.35, 2003/03/05 20:31:13
|
version 1.37, 2003/03/06 22:45:04
|
Line 656 my $filename;
|
Line 656 my $filename;
|
my $rows_output; |
my $rows_output; |
my $cols_output; |
my $cols_output; |
|
|
my $num_students; |
my %prog_state; # progress window state |
my $start_time; |
|
|
|
sub excel_initialize { |
sub excel_initialize { |
my ($r) = @_; |
my ($r) = @_; |
Line 672 sub excel_initialize {
|
Line 671 sub excel_initialize {
|
$rows_output = 0; |
$rows_output = 0; |
$cols_output = 0; |
$cols_output = 0; |
# |
# |
$num_students = 0; |
|
$start_time = time; |
|
# |
|
# Create sheet |
# Create sheet |
$excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
$excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
# |
# |
Line 764 sub excel_initialize {
|
Line 760 sub excel_initialize {
|
$r->print("</h1>\n"); |
$r->print("</h1>\n"); |
$r->rflush(); |
$r->rflush(); |
# |
# |
|
# Initialize progress window |
|
%prog_state=&Apache::lonhtmlcommon::Create_PrgWin |
|
($r,'Excel File Compilation Status', |
|
'Excel File Compilation Progress', $studentcount); |
|
# |
return; |
return; |
} |
} |
|
|
Line 805 sub excel_outputstudent {
|
Line 806 sub excel_outputstudent {
|
$rows_output++; |
$rows_output++; |
$cols_output=0; |
$cols_output=0; |
# |
# |
# Time estimate |
# Update the progress window |
$num_students++; |
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student'); |
if ($num_students % 10 == 0) { |
|
my $time_est = (time - $start_time)/$num_students * |
|
(scalar(@Apache::lonstatistics::Students)-$num_students); |
|
$time_est = int($time_est); |
|
if (int ($time_est/60) > 0) { |
|
my $min = int($time_est/60); |
|
my $sec = $time_est % 60; |
|
$time_est = $min.' minutes'; |
|
if ($sec > 1) { |
|
$time_est.= ', '.$sec.' seconds'; |
|
} elsif ($sec > 0) { |
|
$time_est.= ', '.$sec.' second'; |
|
} |
|
} else { |
|
$time_est .= ' seconds'; |
|
} |
|
$r->print($num_students.' out of '. |
|
(scalar(@Apache::lonstatistics::Students)). |
|
" students processed. ". |
|
$time_est." remain. Elapsed: ".(time - $start_time). |
|
"<br />\n"); |
|
$r->rflush(); |
|
} |
|
return; |
return; |
} |
} |
|
|
Line 843 sub excel_finish {
|
Line 821 sub excel_finish {
|
# |
# |
return if($c->aborted()); |
return if($c->aborted()); |
# |
# |
|
# Close the progress window |
|
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); |
|
# |
# Tell the user where to get their excel file |
# Tell the user where to get their excel file |
$r->print('<br /><br />'. |
$r->print('<br />'. |
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
my $total_time = time - $start_time; |
|
if (int ($total_time / 60) > 0) { |
|
$total_time = int($total_time/60).' minutes, '.($total_time % 60); |
|
} |
|
$r->print('<br />'.$total_time.' seconds total'); |
|
$r->rflush(); |
$r->rflush(); |
return; |
return; |
} |
} |
Line 875 sub excel_finish {
|
Line 851 sub excel_finish {
|
####################################################### |
####################################################### |
{ |
{ |
|
|
|
my $outputfile; |
|
my $filename; |
|
|
|
my %prog_state; # progress window state |
|
|
sub csv_initialize{ |
sub csv_initialize{ |
my ($r) = @_; |
my ($r) = @_; |
$r->print("<h1>Not implemented yet</h1>"); |
# |
|
# Clean up |
|
$filename = undef; |
|
$outputfile = undef; |
|
undef(%prog_state); |
|
# |
|
# Open a file |
|
$filename = '/prtspool/'. |
|
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
|
time.'_'.rand(1000000000).'.csv'; |
|
unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) { |
|
$r->log_error("Couldn't open $filename for output $!"); |
|
$r->print("Problems occured in writing the csv file. ". |
|
"This error has been logged. ". |
|
"Please alert your LON-CAPA administrator."); |
|
$outputfile = undef; |
|
} |
|
# |
|
# Print out the headings |
|
my $Str = ''; |
|
my $Str2 = undef; |
|
foreach my $field (&get_student_fields_to_show()) { |
|
if ($show eq 'scores') { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($field).'",'; |
|
} elsif ($show eq 'totals') { |
|
$Str .= '"",'; # first row empty on the student fields |
|
$Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",'; |
|
} elsif ($show eq 'all') { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($field).'",'; |
|
} |
|
} |
|
foreach my $seq (&get_sequences_to_show) { |
|
if ($show eq 'scores') { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}). |
|
'",'; |
|
} elsif ($show eq 'totals') { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}). |
|
'","",'; |
|
$Str2 .= '"score","total possible",'; |
|
} elsif ($show eq 'all') { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}). |
|
'",'; |
|
$Str .= '"",'x($seq->{'num_assess_parts'}-1); |
|
$Str .= '"score","total possible",'; |
|
} |
|
} |
|
chop($Str); |
|
$Str .= "\n"; |
|
print $outputfile $Str; |
|
if (defined($Str2)) { |
|
chop($Str2); |
|
$Str2 .= "\n"; |
|
print $outputfile $Str2; |
|
} |
|
# |
|
# Initialize progress window |
|
my $studentcount = scalar(@Apache::lonstatistics::Students); |
|
%prog_state=&Apache::lonhtmlcommon::Create_PrgWin |
|
($r,'CSV File Compilation Status', |
|
'CSV File Compilation Progress', $studentcount); |
return; |
return; |
} |
} |
|
|
sub csv_outputstudent { |
sub csv_outputstudent { |
my ($r,$student) = @_; |
my ($r,$student) = @_; |
|
return if (! defined($outputfile)); |
|
my $Str = ''; |
|
# |
|
# Output student fields |
|
my @to_show = &get_student_fields_to_show(); |
|
foreach my $field (@to_show) { |
|
$Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",'; |
|
} |
|
# |
|
# Get student assessment data |
|
my %StudentsData; |
|
my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'}, |
|
$student->{'domain'}, |
|
undef, |
|
$ENV{'request.course.id'}); |
|
if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) { |
|
%StudentsData = @tmp; |
|
} |
|
# |
|
# Output performance data |
|
foreach my $seq (&get_sequences_to_show) { |
|
my ($performance,$score,$seq_max) = |
|
&StudentPerformanceOnSequence($student,\%StudentsData, |
|
$seq,'no'); |
|
if ($show eq 'scores') { |
|
$Str .= '"'.$score.'",'; |
|
} elsif ($show eq 'totals') { |
|
$Str .= '"'.$score.'","'.$seq_max.'",'; |
|
} elsif ($show eq 'all') { |
|
$Str .= '"'.join('","',(split(//,$performance),$score,$seq_max)). |
|
'",'; |
|
} |
|
} |
|
chop($Str); |
|
$Str .= "\n"; |
|
print $outputfile $Str; |
|
# |
|
# Update the progress window |
|
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student'); |
|
return; |
} |
} |
|
|
sub csv_finish { |
sub csv_finish { |
my ($r) = @_; |
my ($r) = @_; |
|
return if (! defined($outputfile)); |
|
close($outputfile); |
|
# |
|
my $c = $r->connection(); |
|
return if ($c->aborted()); |
|
# |
|
# Close the progress window |
|
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); |
|
# |
|
# Tell the user where to get their csv file |
|
$r->print('<br />'. |
|
'<a href="'.$filename.'">Your csv file.</a>'."\n"); |
|
$r->rflush(); |
|
return; |
|
|
} |
} |
|
|
} |
} |