--- loncom/interface/statistics/lonstudentassessment.pm 2005/03/10 17:33:58 1.117 +++ loncom/interface/statistics/lonstudentassessment.pm 2005/04/07 07:34:52 1.122 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentassessment.pm,v 1.117 2005/03/10 17:33:58 matthew Exp $ +# $Id: lonstudentassessment.pm,v 1.122 2005/04/07 07:34:52 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -153,10 +153,10 @@ sub BuildStudentAssessmentPage { &Apache::lonstatistics::PrepareClasslist(); # $single_student_mode = 0; - $single_student_mode = 1 if ($ENV{'form.SelectedStudent'}); + $single_student_mode = 1 if ($env{'form.SelectedStudent'}); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['selectstudent']); - if ($ENV{'form.selectstudent'}) { + if ($env{'form.selectstudent'}) { &Apache::lonstatistics::DisplayClasslist($r); return; } @@ -167,17 +167,19 @@ sub BuildStudentAssessmentPage { $r->print(&CreateInterface()); $r->print(''); $r->print(''); + $env{'form.sort'}.'" />'); $r->rflush(); # - if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) { + if (! exists($env{'form.notfirstrun'}) && ! $single_student_mode) { return; } + $r->print('

'. + &Apache::lonstatistics::section_and_enrollment_description(). + '

'); # my $initialize = \&html_initialize; my $output_student = \&html_outputstudent; my $finish = \&html_finish; - &Apache::lonnet::logthis('got here! 1'); # if ($output_mode eq 'excel') { $initialize = \&excel_initialize; @@ -189,7 +191,6 @@ sub BuildStudentAssessmentPage { $finish = \&csv_finish; } # - &Apache::lonnet::logthis('got here! 2'); if($c->aborted()) { return ; } # # Determine which students we want to look at @@ -214,7 +215,6 @@ sub BuildStudentAssessmentPage { # # Call the initialize routine selected above $initialize->($r); - &Apache::lonnet::logthis('got here! 3'); foreach my $student (@Students) { if($c->aborted()) { $finish->($r); @@ -234,7 +234,7 @@ sub BuildStudentAssessmentPage { sub next_and_previous_buttons { my $Str = ''; $Str .= ''; + $env{'form.SelectedStudent'}.'" />'; # # Build the previous student link my $previous = &Apache::lonstatistics::previous_student(); @@ -353,7 +353,7 @@ sub CreateInterface { &mt('Clear Caches').'" />'; $Str .= ' 'x5; $Str .= - &mt('Status[_1]', + &mt('Status [_1]', ''); $Str .= '
'; return $Str; @@ -430,14 +430,9 @@ sub CreateAndParseOutputSelector { [$elementname]); # # Format for output options is 'mode, restrictions'; - my $selected = 'html, without links'; - if (exists($ENV{'form.'.$elementname})) { - if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { - $selected = $ENV{'form.'.$elementname}->[0]; - } else { - $selected = $ENV{'form.'.$elementname}; - } - } + my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0]; + $selected = 'html, without links' if (!$selected); + # # Set package variables describing output mode $show_links = 'no'; @@ -551,14 +546,9 @@ sub CreateAndParseOutputDataSelector { my $Str = ''; my $elementname = 'chartoutputdata'; # - my $selected = 'scores'; - if (exists($ENV{'form.'.$elementname})) { - if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { - $selected = $ENV{'form.'.$elementname}->[0]; - } else { - $selected = $ENV{'form.'.$elementname}; - } - } + my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0]; + $selected = 'scores' if (!$selected); + # $chosen_output = $OutputDataOptions[0]; foreach my $option (@OutputDataOptions) { @@ -652,7 +642,7 @@ sub html_initialize { ''); } # - $r->print("

".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}. + $r->print("

".$env{'course.'.$env{'request.course.id'}.'.description'}. "  ".localtime(time)."

"); # if ($chosen_output->{'base'} !~ /^final table/) { @@ -683,7 +673,7 @@ sub html_initialize { # Use 1 digit for a space $width{$symb}->{'width_sum'} += 1; } - $total_count += $width{$symb}->{'num_assess_parts'}; + $total_count += &count_parts($navmap,$seq); # Use 3 digits for the sum $width{$symb}->{'width_sum'} += 3; } @@ -747,7 +737,7 @@ sub html_outputstudent { my %StudentsData; my @tmp = &Apache::loncoursedata::get_current_state ($student->{'username'},$student->{'domain'},undef, - $ENV{'request.course.id'}); + $env{'request.course.id'}); if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) { %StudentsData = @tmp; } @@ -763,7 +753,7 @@ sub html_outputstudent { my $studentstats; my $PerformanceStr = ''; foreach my $seq (@sequences) { - &Apache::lonnet::logthis('computing student data for '.$seq->compTitle); + my $symb = $seq->symb; my ($performance,$performance_length,$score,$seq_max,$rawdata); if ($chosen_output->{'tries'}) { ($performance,$performance_length,$score,$seq_max,$rawdata) = @@ -775,7 +765,8 @@ sub html_outputstudent { $navmap,$seq,$show_links); } my $ratio=''; - if ($chosen_output->{'every_problem'}) { + if ($chosen_output->{'every_problem'} && + $chosen_output->{'sequence_sum'}) { $ratio .= ' '; } if ($chosen_output->{'sequence_sum'} && $score ne ' ') { @@ -795,15 +786,15 @@ sub html_outputstudent { $performance = ''; $performance_length=0; } - $performance .= ' 'x($width{$seq->symb}->{'width_total'} - + $performance .= ' 'x($width{$symb}->{'width_total'} - $performance_length - - $width{$seq->symb}->{'width_sum'}). + $width{$symb}->{'width_sum'}). $ratio; # $Str .= $performance.$padding; # - $studentstats->{$seq->symb}->{'score'}= $score; - $studentstats->{$seq->symb}->{'max'} = $seq_max; + $studentstats->{$symb}->{'score'}= $score; + $studentstats->{$symb}->{'max'} = $seq_max; } # # Total it up and store the statistics info. @@ -1038,36 +1029,22 @@ sub excel_initialize { return if (! defined($excel_workbook)); # # Add a worksheet - my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'}; $sheetname = &Apache::loncommon::clean_excel_name($sheetname); $excel_sheet = $excel_workbook->addworksheet($sheetname); # # Put the course description in the header $excel_sheet->write($header_row,$cols_output++, - $ENV{'course.'.$ENV{'request.course.id'}.'.description'}, + $env{'course.'.$env{'request.course.id'}.'.description'}, $format->{'h1'}); $cols_output += 3; # # Put a description of the sections listed my $sectionstring = ''; - my @Sections = @Apache::lonstatistics::SelectedSections; - if (scalar(@Sections) > 1) { - if (scalar(@Sections) > 2) { - my $last = pop(@Sections); - $sectionstring = "Sections ".join(', ',@Sections).', and '.$last; - } else { - $sectionstring = "Sections ".join(' and ',@Sections); - } - } else { - if ($Sections[0] eq 'all') { - $sectionstring = "All sections"; - } else { - $sectionstring = "Section ".$Sections[0]; - } - } - $excel_sheet->write($header_row,$cols_output++,$sectionstring, + my @Sections = &Apache::lonstatistics::get_selected_sections(); + $excel_sheet->write($header_row,$cols_output++, + &Apache::lonstatistics::section_and_enrollment_description('plain text'), $format->{'h3'}); - $cols_output += scalar(@Sections); # # Put the date in there too $excel_sheet->write($header_row,$cols_output++, @@ -1327,7 +1304,7 @@ sub excel_initialize { # # Let the user know what we are doing my $studentcount = scalar(@Apache::lonstatistics::Students); - if ($ENV{'form.SelectedStudent'}) { + if ($env{'form.SelectedStudent'}) { $studentcount = '1'; } if ($studentcount > 1) { @@ -1374,7 +1351,7 @@ sub excel_outputstudent { my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'}, $student->{'domain'}, undef, - $ENV{'request.course.id'}); + $env{'request.course.id'}); if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) { %StudentsData = @tmp; } @@ -1558,22 +1535,18 @@ END 'inline',undef,'Statistics','stats_status'); # # 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; - } + ($outputfile,$filename) = &Apache::loncommon::create_text_file($r,'csv'); + if (! defined($outputfile)) { return ''; } # # Datestamp - my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + my $description = $env{'course.'.$env{'request.course.id'}.'.description'}; print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'. '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'. "\n"; + print $outputfile '"'. + &Apache::loncommon::csv_translate + (&Apache::lonstatistics::section_and_enrollment_description()). + '"'."\n"; foreach my $item ('shortdesc','non_html_notes') { next if (! exists($chosen_output->{$item})); print $outputfile @@ -1656,7 +1629,7 @@ sub csv_outputstudent { my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'}, $student->{'domain'}, undef, - $ENV{'request.course.id'}); + $env{'request.course.id'}); if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) { %StudentsData = @tmp; }