--- loncom/interface/statistics/lonproblemstatistics.pm 2003/05/12 22:07:17 1.50 +++ loncom/interface/statistics/lonproblemstatistics.pm 2004/01/28 14:38:40 1.64 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemstatistics.pm,v 1.50 2003/05/12 22:07:17 matthew Exp $ +# $Id: lonproblemstatistics.pm,v 1.64 2004/01/28 14:38:40 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,18 +51,27 @@ package Apache::lonproblemstatistics; use strict; use Apache::lonnet(); +use Apache::loncommon(); use Apache::lonhtmlcommon; use Apache::loncoursedata; use Apache::lonstatistics; +use Apache::lonlocal; use Spreadsheet::WriteExcel; +## +## Localization notes: +## +## in @Fields[0]->{'long_title'} is placed in Excel files and is used as the +## header for plots created with Graph.pm, both of which more than likely do +## not support localization. +## my @Fields = ( { name => 'problem_num', title => 'P#', align => 'right', color => '#FFFFE6' }, { name => 'container', - title => 'Container', + title => 'Sequence or Folder', align => 'left', color => '#FFFFE6', sortable => 'yes' }, @@ -75,7 +84,8 @@ my @Fields = ( { name => 'part', title => 'Part', align => 'left', - color => '#FFFFE6' }, + color => '#FFFFE6', + }, { name => 'num_students', title => '#Stdnts', align => 'right', @@ -131,12 +141,13 @@ my @Fields = ( format => '%5.2f', sortable => 'yes', graphable => 'yes', - long_title => 'Degree of Difficulty' }, + long_title => 'Degree of Difficulty'. + '[ 1 - ((#YES+#yes) / Tries) ]'}, { name => 'num_solved', title => '#YES', align => 'right', color => '#FFDDDD', - format => '%d', + format => '%4.1f',# format => '%d', sortable => 'yes', graphable => 'yes', long_title => 'Number of Students able to Solve' }, @@ -144,7 +155,7 @@ my @Fields = ( title => '#yes', align => 'right', color => '#FFDDDD', - format => '%d', + format => '%4.1f',# format => '%d', sortable => 'yes', graphable => 'yes', long_title => 'Number of Students given Override' }, @@ -155,7 +166,7 @@ my @Fields = ( format => '%4.1f', sortable => 'yes', graphable => 'yes', - long_title => 'Percent Wrong' }, + long_title => 'Percent of students whose final answer is wrong' }, ); ############################################### @@ -172,60 +183,6 @@ select sections, maps, and output. ############################################### ############################################### -sub CreateInterface { - my $Str = ''; - $Str .= ''."\n"; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''."\n"; - # - $Str .= ''."\n"; - $Str .= '
SectionsEnrollment StatusSequences and FoldersOutput
'."\n"; - $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); - $Str .= ''; - $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); - $Str .= ''; - # - my $only_seq_with_assessments = sub { - my $s=shift; - if ($s->{'num_assess'} < 1) { - return 0; - } else { - return 1; - } - }; - $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, - $only_seq_with_assessments); - $Str .= ''."\n"; - $Str .= &CreateAndParseOutputSelector(); - $Str .= '
'."\n"; - return $Str; -} - -####################################################### -####################################################### - -=pod - -=item &CreateAndParseOutputSelector() - -Construct a selection list of options for output and parse output selections. -The current output selected is indicated by the values of the two package -variables $output_mode and $show. @OutputOptions holds the descriptions of -the output options and the values for $output_mode and $show. - -Based on code from lonstudentassessment.pm. - -=cut - -####################################################### -####################################################### -my $output_mode; -my $show; - my @OutputOptions = ( { name => 'problem statistics grouped by sequence', @@ -249,92 +206,51 @@ my @OutputOptions = }, ); -sub OutputDescriptions { - my $Str = ''; - $Str .= "

Output Modes

\n"; - $Str .= "
\n"; - foreach my $outputmode (@OutputOptions) { - $Str .="
".$outputmode->{'name'}."
\n"; - $Str .="
".$outputmode->{'description'}."
\n"; - } - $Str .= "
\n"; - return $Str; -} - -sub CreateAndParseOutputSelector { +sub CreateInterface { my $Str = ''; - my $elementname = 'statsoutputmode'; - # - # Format for output options is 'mode, restrictions'; - my $selected = 'HTML problem statistics grouped'; - if (exists($ENV{'form.'.$elementname})) { - if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { - $selected = $ENV{'form.'.$elementname}->[0]; - } else { - $selected = $ENV{'form.'.$elementname}; - } - } + $Str .= '

Overall Problem Statistics'. + &Apache::loncommon::help_open_topic('Statistics_Overall_Key'). + '

'."\n"; + $Str .= ''."\n"; + $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= ''."\n"; # - # Set package variables describing output mode - $output_mode = 'html'; - $show = 'all'; - foreach my $option (@OutputOptions) { - next if ($option->{'value'} ne $selected); - $output_mode = $option->{'mode'}; - $show = $option->{'show'}; - } + $Str .= ''."\n"; + $Str .= '
'.&mt('Sections').''.&mt('Enrollment Status').''.&mt('Sequences and Folders').''.&mt('Output').'
'."\n"; + $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); + $Str .= ''; + $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); + $Str .= ''; # - # Build the form element - $Str = qq/"; - return $Str; -} - -############################################### -############################################### - -=pod - -=item &Gather_Student_Data() - -Ensures all student data is up to date. - -=cut - -############################################### -############################################### -sub Gather_Student_Data { - my ($r) = @_; - my $c = $r->connection(); - # - my @Sequences = &Apache::lonstatistics::Sequences_with_Assess(); - # - my @Students = @Apache::lonstatistics::Students; - # - # Open the progress window - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin - ($r,'Statistics Compilation Status', - 'Statistics Compilation Progress', scalar(@Students)); - # - while (my $student = shift @Students) { - return if ($c->aborted()); - my ($status,undef) = &Apache::loncoursedata::ensure_current_data - ($student->{'username'},$student->{'domain'}, - $ENV{'request.course.id'}); - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, - 'last student'); - } - &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - $r->rflush(); + }; + $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, + $only_seq_with_assessments); + $Str .= ''."\n"; + my ($html,$outputmode,$show) = + &Apache::lonstatistics::CreateAndParseOutputSelector( + 'statsoutputmode', + 'HTML problem statistics grouped', + @OutputOptions); + $Str .= $html; + $Str .= '
'."\n"; + $Str .= ''; + $Str .= ' 'x5; + $Str .= ''; + $Str .= ' 'x5; + return ($Str,$outputmode,$show); } ############################################### @@ -353,27 +269,29 @@ Main interface to problem statistics. sub BuildProblemStatisticsPage { my ($r,$c)=@_; # - $output_mode = 'html'; - $show = 'grouped'; + my %Saveable_Parameters = ('Status' => 'scalar', + 'statsoutputmode' => 'scalar', + 'Section' => 'array', + 'StudentData' => 'array', + 'Maps' => 'array'); + &Apache::loncommon::store_course_settings('statistics', + \%Saveable_Parameters); + &Apache::loncommon::restore_course_settings('statistics', + \%Saveable_Parameters); + # + &Apache::lonstatistics::PrepareClasslist(); # - $r->print(&CreateInterface()); + my ($interface,$output_mode,$show) = &CreateInterface(); + $r->print($interface); $r->print(''); $r->print(''); $r->print(''); if (! exists($ENV{'form.statsfirstcall'})) { - $r->print(< - -Please make your selections in the boxes above and hit -the button marked "Update Display". - -

-ENDMSG return; } # - &Gather_Student_Data($r); + &Apache::lonstatistics::Gather_Student_Data($r); # # if ($output_mode eq 'html') { @@ -388,10 +306,10 @@ ENDMSG &output_html_ungrouped($r); } } elsif ($output_mode eq 'excel') { - $r->print("

Preparing Excel Spreadsheet

"); + $r->print('

'.&mt('Preparing Excel Spreadsheet').'

'); &output_excel($r); } else { - $r->print("

Not implemented

"); + $r->print('

'.&mt('Not implemented').'

'); } return; } @@ -598,9 +516,9 @@ sub output_excel { # Check for errors if (! defined($excel_workbook)) { $r->log_error("Error creating excel spreadsheet $filename: $!"); - $r->print("Problems creating new Excel file. ". + $r->print(&mt("Problems creating new Excel file. ". "This error has been logged. ". - "Please alert your LON-CAPA administrator"); + "Please alert your LON-CAPA administrator.")); return ; } # @@ -615,7 +533,9 @@ sub output_excel { if (length($sheetname) > 31) { $sheetname = substr($sheetname,0,31); } - $excel_sheet = $excel_workbook->addworksheet($sheetname); + $excel_sheet = $excel_workbook->addworksheet( + &Apache::loncommon::clean_excel_name($sheetname) + ); # # Put the course description in the header $excel_sheet->write($rows_output,$cols_output++, @@ -649,9 +569,23 @@ sub output_excel { $rows_output++; $cols_output=0; # - # Add the headers + # Long Headersheaders + foreach my $field (@Fields) { + next if ($field->{'name'} eq 'problem_num'); + if (exists($field->{'long_title'})) { + $excel_sheet->write($rows_output,$cols_output++, + $field->{'long_title'}); + } else { + $excel_sheet->write($rows_output,$cols_output++,''); + } + } + $rows_output++; + $cols_output=0; + # Brief headers foreach my $field (@Fields) { next if ($field->{'name'} eq 'problem_num'); + # Use english for excel as I am not sure how well excel handles + # other character sets.... $excel_sheet->write($rows_output,$cols_output++,$field->{'title'}); } $rows_output++; @@ -685,7 +619,8 @@ sub output_excel { $excel_workbook->close(); # Tell the user where to get their excel file $r->print('
'. - 'Your Excel spreadsheet.'."\n"); + ''. + &mt('Your Excel Spreadsheet').''."\n"); $r->rflush(); return; } @@ -714,8 +649,7 @@ sub statistics_html_table_data { } $row .= '>'; if (exists($field->{'special'}) && $field->{'special'} eq 'link') { - $row .= ''; + $row .= ''; } if (exists($field->{'format'})) { $row .= sprintf($field->{'format'},$data->{$field->{'name'}}); @@ -742,7 +676,7 @@ sub statistics_table_header { 'document.Statistics.sortby.value='."'".$field->{'name'}."'". ';document.Statistics.submit();">'; } - $header_row .= $field->{'title'}; + $header_row .= &mt($field->{'title'}); if ($options =~ /sortable/) { $header_row.= ''; } @@ -753,7 +687,7 @@ sub statistics_table_header { $header_row .= ''; - $header_row .= 'plot)'; + $header_row .= &mt('plot').')'; } $header_row .= ''; } @@ -786,7 +720,6 @@ sub plot_statistics { } } return if (! defined($sortfield) || $sortfield eq ''); - &Apache::lonnet::logthis('data field = '.$datafield); # my $Max = 0; my $problem_num = 0; @@ -836,8 +769,12 @@ sub plot_statistics { } } - $r->print("

".&DrawGraph(\@Data,$title,'Problem Number',$yaxis, - $Max)."

\n"); + $r->print("

".&Apache::loncommon::DrawBarGraph($title, + 'Problem Number', + $yaxis, + $Max, + undef, + \@Data)."

\n"); # # Print out the data $ENV{'form.sortby'} = 'Contents'; @@ -845,35 +782,6 @@ sub plot_statistics { return; } -############################################### -############################################### - -=pod - -=item &DrawGraph() - -=cut - -############################################### -############################################### -sub DrawGraph { - my ($values,$title,$xaxis,$yaxis,$Max)=@_; - $title = '' if (! defined($title)); - $xaxis = '' if (! defined($xaxis)); - $yaxis = '' if (! defined($yaxis)); - # - my $sendValues = join(',', @$values); - my $sendCount = scalar(@$values); - $Max =1 if ($Max < 1); - if ( int($Max) < $Max ) { - $Max++; - $Max = int($Max); - } - my @GData = ($title,$xaxis,$yaxis,$Max,$sendCount,$sendValues); - return ''; -} - sub get_statistics { my ($sequence,$resource,$part,$problem_num) = @_; # @@ -890,7 +798,8 @@ sub get_statistics { $data->{'problem_num'} = $problem_num; $data->{'container'} = $sequence->{'title'}; $data->{'title'} = $resource->{'title'}; - $data->{'title.link'} = $resource->{'src'}; + $data->{'title.link'} = $resource->{'src'}.'?symb='. + &Apache::lonnet::escape($resource->{'symb'}); # return $data; } @@ -902,6 +811,8 @@ sub get_statistics { =item &ProblemStatisticsLegend() +HELP This needs to be localized, or at least generated automatically. + =cut ###############################################