version 1.57, 2003/08/29 21:11:25
|
version 1.69, 2004/03/01 16:39:19
|
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 138 my @Fields = (
|
Line 147 my @Fields = (
|
title => '#YES', |
title => '#YES', |
align => 'right', |
align => 'right', |
color => '#FFDDDD', |
color => '#FFDDDD', |
format => '%d', |
format => '%4.1f',# format => '%d', |
sortable => 'yes', |
sortable => 'yes', |
graphable => 'yes', |
graphable => 'yes', |
long_title => 'Number of Students able to Solve' }, |
long_title => 'Number of Students able to Solve' }, |
Line 146 my @Fields = (
|
Line 155 my @Fields = (
|
title => '#yes', |
title => '#yes', |
align => 'right', |
align => 'right', |
color => '#FFDDDD', |
color => '#FFDDDD', |
format => '%d', |
format => '%4.1f',# format => '%d', |
sortable => 'yes', |
sortable => 'yes', |
graphable => 'yes', |
graphable => 'yes', |
long_title => 'Number of Students given Override' }, |
long_title => 'Number of Students given Override' }, |
Line 199 my @OutputOptions =
|
Line 208 my @OutputOptions =
|
|
|
sub CreateInterface { |
sub CreateInterface { |
my $Str = ''; |
my $Str = ''; |
|
$Str .= &Apache::lonhtmlcommon::breadcrumbs |
|
(undef,'Overall Problem Statistics','Statistics_Overall_Key'); |
$Str .= '<table cellspacing="5">'."\n"; |
$Str .= '<table cellspacing="5">'."\n"; |
$Str .= '<tr>'; |
$Str .= '<tr>'; |
$Str .= '<td align="center"><b>Sections</b></td>'; |
$Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>'; |
$Str .= '<td align="center"><b>Enrollment Status</b></td>'; |
$Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>'; |
$Str .= '<td align="center"><b>Sequences and Folders</b></td>'; |
$Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>'; |
$Str .= '<td align="center"><b>Output</b></td>'; |
$Str .= '<td align="center"><b>'.&mt('Output').'</b></td>'; |
$Str .= '</tr>'."\n"; |
$Str .= '</tr>'."\n"; |
# |
# |
$Str .= '<tr><td align="center">'."\n"; |
$Str .= '<tr><td align="center">'."\n"; |
Line 232 sub CreateInterface {
|
Line 243 sub CreateInterface {
|
$Str .= $html; |
$Str .= $html; |
$Str .= '</td></tr>'."\n"; |
$Str .= '</td></tr>'."\n"; |
$Str .= '</table>'."\n"; |
$Str .= '</table>'."\n"; |
$Str .= '<input type="submit" value="Generate Statistics" />'; |
$Str .= '<input type="submit" name="GenerateStatistics" value="'. |
|
&mt('Generate Statistics').'" />'; |
$Str .= ' 'x5; |
$Str .= ' 'x5; |
$Str .= '<input type="submit" name="ClearCache" value="Clear Caches" />'; |
$Str .= '<input type="submit" name="ClearCache" value="'. |
|
&mt('Clear Caches').'" />'; |
$Str .= ' 'x5; |
$Str .= ' 'x5; |
return ($Str,$outputmode,$show); |
return ($Str,$outputmode,$show); |
} |
} |
Line 255 Main interface to problem statistics.
|
Line 268 Main interface to problem statistics.
|
sub BuildProblemStatisticsPage { |
sub BuildProblemStatisticsPage { |
my ($r,$c)=@_; |
my ($r,$c)=@_; |
# |
# |
|
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(); |
|
# |
my ($interface,$output_mode,$show) = &CreateInterface(); |
my ($interface,$output_mode,$show) = &CreateInterface(); |
$r->print($interface); |
$r->print($interface); |
$r->print('<input type="hidden" name="statsfirstcall" value="no" />'); |
$r->print('<input type="hidden" name="statsfirstcall" value="no" />'); |
Line 280 sub BuildProblemStatisticsPage {
|
Line 305 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 490 sub output_excel {
|
Line 515 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 507 sub output_excel {
|
Line 532 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 556 sub output_excel {
|
Line 583 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 589 sub output_excel {
|
Line 618 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 645 sub statistics_table_header {
|
Line 675 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 656 sub statistics_table_header {
|
Line 686 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 738 sub plot_statistics {
|
Line 768 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, # colors |
|
undef, # labels |
|
\@Data)."</p>\n"); |
# |
# |
# Print out the data |
# Print out the data |
$ENV{'form.sortby'} = 'Contents'; |
$ENV{'form.sortby'} = 'Contents'; |
Line 747 sub plot_statistics {
|
Line 782 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)); |
|
# |
|
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) = @_; |
# |
# |
my $symb = $resource->{'symb'}; |
my $symb = $resource->{'symb'}; |
my $courseid = $ENV{'request.course.id'}; |
my $courseid = $ENV{'request.course.id'}; |
# |
# |
my $students = \@Apache::lonstatistics::Students; |
|
if ($Apache::lonstatistics::SelectedSections[0] eq 'all') { |
|
$students = undef; |
|
} |
|
my $data = &Apache::loncoursedata::get_problem_statistics |
my $data = &Apache::loncoursedata::get_problem_statistics |
($students,$symb,$part,$courseid); |
(\@Apache::lonstatistics::SelectedSections, |
|
$Apache::lonstatistics::enrollment_status, |
|
$symb,$part,$courseid); |
$data->{'part'} = $part; |
$data->{'part'} = $part; |
$data->{'problem_num'} = $problem_num; |
$data->{'problem_num'} = $problem_num; |
$data->{'container'} = $sequence->{'title'}; |
$data->{'container'} = $sequence->{'title'}; |
Line 805 sub get_statistics {
|
Line 809 sub get_statistics {
|
|
|
=item &ProblemStatisticsLegend() |
=item &ProblemStatisticsLegend() |
|
|
|
HELP This needs to be localized, or at least generated automatically. |
|
|
=cut |
=cut |
|
|
############################################### |
############################################### |