version 1.55.2.1, 2003/10/28 20:08:23
|
version 1.62, 2003/12/08 19:37:44
|
Line 51 package Apache::lonproblemstatistics;
|
Line 51 package Apache::lonproblemstatistics;
|
|
|
use strict; |
use strict; |
use Apache::lonnet(); |
use Apache::lonnet(); |
|
use Apache::loncommon(); |
use Apache::lonhtmlcommon; |
use Apache::lonhtmlcommon; |
use Apache::loncoursedata; |
use Apache::loncoursedata; |
use Apache::lonstatistics; |
use Apache::lonstatistics; |
|
use Apache::lonlocal; |
use Spreadsheet::WriteExcel; |
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 = ( |
my @Fields = ( |
{ name => 'problem_num', |
{ name => 'problem_num', |
title => 'P#', |
title => 'P#', |
Line 174 select sections, maps, and output.
|
Line 183 select sections, maps, and output.
|
|
|
############################################### |
############################################### |
############################################### |
############################################### |
sub CreateInterface { |
|
my $Str = ''; |
|
$Str .= '<table cellspacing="5">'."\n"; |
|
$Str .= '<tr>'; |
|
$Str .= '<td align="center"><b>Sections</b></td>'; |
|
$Str .= '<td align="center"><b>Enrollment Status</b></td>'; |
|
$Str .= '<td align="center"><b>Sequences and Folders</b></td>'; |
|
$Str .= '<td align="center"><b>Output</b></td>'; |
|
$Str .= '</tr>'."\n"; |
|
# |
|
$Str .= '<tr><td align="center">'."\n"; |
|
$Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); |
|
$Str .= '</td><td align="center">'; |
|
$Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); |
|
$Str .= '</td><td align="center">'; |
|
# |
|
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 .= '</td><td>'."\n"; |
|
$Str .= &CreateAndParseOutputSelector(); |
|
$Str .= '</td></tr>'."\n"; |
|
$Str .= '</table>'."\n"; |
|
$Str .= '<input type="submit" value="Generate Statistics" />'; |
|
$Str .= ' 'x5; |
|
$Str .= '<input type="submit" name="ClearCache" value="Clear Caches" />'; |
|
$Str .= ' 'x5; |
|
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 = |
my @OutputOptions = |
( |
( |
{ name => 'problem statistics grouped by sequence', |
{ name => 'problem statistics grouped by sequence', |
Line 255 my @OutputOptions =
|
Line 206 my @OutputOptions =
|
}, |
}, |
); |
); |
|
|
sub OutputDescriptions { |
sub CreateInterface { |
my $Str = ''; |
|
$Str .= "<h2>Output Modes</h2>\n"; |
|
$Str .= "<dl>\n"; |
|
foreach my $outputmode (@OutputOptions) { |
|
$Str .=" <dt>".$outputmode->{'name'}."</dt>\n"; |
|
$Str .=" <dd>".$outputmode->{'description'}."</dd>\n"; |
|
} |
|
$Str .= "</dl>\n"; |
|
return $Str; |
|
} |
|
|
|
sub CreateAndParseOutputSelector { |
|
my $Str = ''; |
my $Str = ''; |
my $elementname = 'statsoutputmode'; |
$Str .= '<table cellspacing="5">'."\n"; |
# |
$Str .= '<tr>'; |
# Format for output options is 'mode, restrictions'; |
$Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>'; |
my $selected = 'HTML problem statistics grouped'; |
$Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>'; |
if (exists($ENV{'form.'.$elementname})) { |
$Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>'; |
if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) { |
$Str .= '<td align="center"><b>'.&mt('Output').'</b></td>'; |
$selected = $ENV{'form.'.$elementname}->[0]; |
$Str .= '</tr>'."\n"; |
} else { |
|
$selected = $ENV{'form.'.$elementname}; |
|
} |
|
} |
|
# |
# |
# Set package variables describing output mode |
$Str .= '<tr><td align="center">'."\n"; |
$output_mode = 'html'; |
$Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); |
$show = 'all'; |
$Str .= '</td><td align="center">'; |
foreach my $option (@OutputOptions) { |
$Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); |
next if ($option->{'value'} ne $selected); |
$Str .= '</td><td align="center">'; |
$output_mode = $option->{'mode'}; |
|
$show = $option->{'show'}; |
|
} |
|
# |
# |
# Build the form element |
my $only_seq_with_assessments = sub { |
$Str = qq/<select size="5" name="$elementname">/; |
my $s=shift; |
foreach my $option (@OutputOptions) { |
if ($s->{'num_assess'} < 1) { |
if (exists($option->{'special'}) && |
return 0; |
$option->{'special'} =~ /do not show/) { |
} else { |
next; |
return 1; |
} |
} |
$Str .= "\n".' <option value="'.$option->{'value'}.'"'; |
}; |
$Str .= " selected " if ($option->{'value'} eq $selected); |
$Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, |
$Str .= ">".$option->{'name'}."<\/option>"; |
$only_seq_with_assessments); |
} |
$Str .= '</td><td>'."\n"; |
$Str .= "\n</select>"; |
my ($html,$outputmode,$show) = |
return $Str; |
&Apache::lonstatistics::CreateAndParseOutputSelector( |
} |
'statsoutputmode', |
|
'HTML problem statistics grouped', |
############################################### |
@OutputOptions); |
############################################### |
$Str .= $html; |
|
$Str .= '</td></tr>'."\n"; |
=pod |
$Str .= '</table>'."\n"; |
|
$Str .= '<input type="submit" name="GenerateStatistics" value="'. |
=item &Gather_Student_Data() |
&mt('Generate Statistics').'" />'; |
|
$Str .= ' 'x5; |
Ensures all student data is up to date. |
$Str .= '<input type="submit" name="ClearCache" value="'. |
|
&mt('Clear Caches').'" />'; |
=cut |
$Str .= ' 'x5; |
|
return ($Str,$outputmode,$show); |
############################################### |
|
############################################### |
|
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(); |
|
} |
} |
|
|
############################################### |
############################################### |
Line 359 Main interface to problem statistics.
|
Line 266 Main interface to problem statistics.
|
sub BuildProblemStatisticsPage { |
sub BuildProblemStatisticsPage { |
my ($r,$c)=@_; |
my ($r,$c)=@_; |
# |
# |
$output_mode = 'html'; |
my %Saveable_Parameters = ('Status' => 'scalar', |
$show = 'grouped'; |
'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('<input type="hidden" name="statsfirstcall" value="no" />'); |
$r->print('<input type="hidden" name="statsfirstcall" value="no" />'); |
$r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}. |
$r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}. |
'" />'); |
'" />'); |
Line 371 sub BuildProblemStatisticsPage {
|
Line 288 sub BuildProblemStatisticsPage {
|
return; |
return; |
} |
} |
# |
# |
&Gather_Student_Data($r); |
&Apache::lonstatistics::Gather_Student_Data($r); |
# |
# |
# |
# |
if ($output_mode eq 'html') { |
if ($output_mode eq 'html') { |
Line 386 sub BuildProblemStatisticsPage {
|
Line 303 sub BuildProblemStatisticsPage {
|
&output_html_ungrouped($r); |
&output_html_ungrouped($r); |
} |
} |
} elsif ($output_mode eq 'excel') { |
} elsif ($output_mode eq 'excel') { |
$r->print("<h2>Preparing Excel Spreadsheet</h2>"); |
$r->print('<h2>'.&mt('Preparing Excel Spreadsheet').'</h2>'); |
&output_excel($r); |
&output_excel($r); |
} else { |
} else { |
$r->print("<h1>Not implemented</h1>"); |
$r->print('<h1>'.&mt('Not implemented').'</h1>'); |
} |
} |
return; |
return; |
} |
} |
Line 596 sub output_excel {
|
Line 513 sub output_excel {
|
# Check for errors |
# Check for errors |
if (! defined($excel_workbook)) { |
if (! defined($excel_workbook)) { |
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
$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. ". |
"This error has been logged. ". |
"Please alert your LON-CAPA administrator"); |
"Please alert your LON-CAPA administrator.")); |
return ; |
return ; |
} |
} |
# |
# |
Line 613 sub output_excel {
|
Line 530 sub output_excel {
|
if (length($sheetname) > 31) { |
if (length($sheetname) > 31) { |
$sheetname = substr($sheetname,0,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 |
# Put the course description in the header |
$excel_sheet->write($rows_output,$cols_output++, |
$excel_sheet->write($rows_output,$cols_output++, |
Line 662 sub output_excel {
|
Line 581 sub output_excel {
|
# Brief headers |
# Brief headers |
foreach my $field (@Fields) { |
foreach my $field (@Fields) { |
next if ($field->{'name'} eq 'problem_num'); |
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'}); |
$excel_sheet->write($rows_output,$cols_output++,$field->{'title'}); |
} |
} |
$rows_output++; |
$rows_output++; |
Line 695 sub output_excel {
|
Line 616 sub output_excel {
|
$excel_workbook->close(); |
$excel_workbook->close(); |
# Tell the user where to get their excel file |
# Tell the user where to get their excel file |
$r->print('<br />'. |
$r->print('<br />'. |
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
'<a href="'.$filename.'">'. |
|
&mt('Your Excel Spreadsheet').'</a>'."\n"); |
$r->rflush(); |
$r->rflush(); |
return; |
return; |
} |
} |
Line 751 sub statistics_table_header {
|
Line 673 sub statistics_table_header {
|
'document.Statistics.sortby.value='."'".$field->{'name'}."'". |
'document.Statistics.sortby.value='."'".$field->{'name'}."'". |
';document.Statistics.submit();">'; |
';document.Statistics.submit();">'; |
} |
} |
$header_row .= $field->{'title'}; |
$header_row .= &mt($field->{'title'}); |
if ($options =~ /sortable/) { |
if ($options =~ /sortable/) { |
$header_row.= '</a>'; |
$header_row.= '</a>'; |
} |
} |
Line 762 sub statistics_table_header {
|
Line 684 sub statistics_table_header {
|
$header_row .= '<a href="javascript:'. |
$header_row .= '<a href="javascript:'. |
"document.Statistics.plot.value='$field->{'name'}'". |
"document.Statistics.plot.value='$field->{'name'}'". |
';document.Statistics.submit();">'; |
';document.Statistics.submit();">'; |
$header_row .= 'plot</a>)'; |
$header_row .= &mt('plot').'</a>)'; |
} |
} |
$header_row .= '</th>'; |
$header_row .= '</th>'; |
} |
} |
Line 844 sub plot_statistics {
|
Line 766 sub plot_statistics {
|
} |
} |
} |
} |
|
|
$r->print("<p>".&DrawGraph(\@Data,$title,'Problem Number',$yaxis, |
$r->print("<p>".&Apache::loncommon::DrawBarGraph($title, |
$Max)."</p>\n"); |
'Problem Number', |
|
$yaxis, |
|
$Max, |
|
undef, |
|
\@Data)."</p>\n"); |
# |
# |
# Print out the data |
# Print out the data |
$ENV{'form.sortby'} = 'Contents'; |
$ENV{'form.sortby'} = 'Contents'; |
Line 853 sub plot_statistics {
|
Line 779 sub plot_statistics {
|
return; |
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)); |
|
$title = &Apache::lonnet::escape($title); |
|
$xaxis = &Apache::lonnet::escape($xaxis); |
|
$yaxis = &Apache::lonnet::escape($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 '<IMG src="/cgi-bin/graph.png?'. |
|
(join('&', @GData)).'" border="1" />'; |
|
} |
|
|
|
sub get_statistics { |
sub get_statistics { |
my ($sequence,$resource,$part,$problem_num) = @_; |
my ($sequence,$resource,$part,$problem_num) = @_; |
# |
# |
Line 914 sub get_statistics {
|
Line 808 sub get_statistics {
|
|
|
=item &ProblemStatisticsLegend() |
=item &ProblemStatisticsLegend() |
|
|
|
HELP This needs to be localized, or at least generated automatically. |
|
|
=cut |
=cut |
|
|
############################################### |
############################################### |