--- loncom/interface/statistics/lonstudentassessment.pm 2003/03/06 21:12:54 1.36 +++ loncom/interface/statistics/lonstudentassessment.pm 2003/03/06 22:45:04 1.37 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentassessment.pm,v 1.36 2003/03/06 21:12:54 matthew Exp $ +# $Id: lonstudentassessment.pm,v 1.37 2003/03/06 22:45:04 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -851,18 +851,137 @@ sub excel_finish { ####################################################### { +my $outputfile; +my $filename; + +my %prog_state; # progress window state + sub csv_initialize{ my ($r) = @_; - $r->print("

Not implemented yet

"); + # + # 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; } sub csv_outputstudent { 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 { 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('
'. + 'Your csv file.'."\n"); + $r->rflush(); + return; + } }