--- loncom/interface/statistics/lonproblemstatistics.pm 2002/11/01 22:09:39 1.35
+++ loncom/interface/statistics/lonproblemstatistics.pm 2004/03/07 21:42:19 1.70
@@ -1,7 +1,6 @@
# The LearningOnline Network with CAPA
-# (Publication Handler
#
-# $Id: lonproblemstatistics.pm,v 1.35 2002/11/01 22:09:39 minaeibi Exp $
+# $Id: lonproblemstatistics.pm,v 1.70 2004/03/07 21:42:19 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,477 +25,846 @@
# http://www.lon-capa.org/
#
# (Navigate problems for statistical reports
-# YEAR=2001
-# 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
-# 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
-# YEAR=2002
-# 1/22,2/1,2/6,2/25,3/2,3/26,4/7,5/6 Behrouz Minaei
-# 5/12,5/26,7/16,7/29,8/5,10/31 Behrouz Minaei
#
-###
+###############################################
+###############################################
-package Apache::lonproblemstatistics;
-
-use strict;
-use Apache::lonnet();
-use Apache::lonhtmlcommon;
-use Apache::loncoursedata;
-use GDBM_File;
+=pod
+=head1 NAME
-sub InitializeProblemStatistics {
- my ($cacheDB, $students, $courseID, $c, $r)=@_;
- my %cache;
-
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database1.');
- return ('ERROR', undef);
- }
-
- # Remove students who don't have the proper section.
- my @sectionsSelected = split(':',$cache{'sectionsSelected'});
- for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
- $studentIndex--) {
- my $value = $cache{$students->[$studentIndex].':section'};
- my $found = 0;
- foreach (@sectionsSelected) {
- if($_ eq 'none') {
- if($value eq '' || !defined($value) || $value eq ' ') {
- $found = 1;
- last;
- }
- } else {
- if($value eq $_) {
- $found = 1;
- last;
- }
- }
- }
- if($found == 0) {
- splice(@$students, $studentIndex, 1);
- }
- }
+lonproblemstatistics
- my $isNotCached = 0;
- my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
- $cache{'StatisticsLastStatus'} : 'Nothing';
- my $whichStudents = join(':::',sort(@$students));
- if(!defined($cache{'StatisticsCached'}) ||
- $lastStatus ne $cache{'Status'} ||
- $whichStudents ne $cache{'StatisticsWhichStudents'}) {
- $isNotCached = 1;
- }
+=head1 SYNOPSIS
- untie(%cache);
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
- $r->print('Unable to tie database.2');
- return ('ERROR', undef);
- }
- if($isNotCached && defined($cache{'StatisticsCached'})) {
- my @statkeys = split(':::', $cache{'StatisticsKeys'});
- delete $cache{'StatisticsKeys'};
- delete $cache{'StatisticsCached'};
- foreach(@statkeys) {
- delete $cache{$_};
- }
- }
+Routines to present problem statistics to instructors via tables,
+Excel files, and plots.
- untie(%cache);
- if($isNotCached) {
- &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
- 'true',
- $cacheDB,
- 'true',
- 'true',
- $courseID,
- $r, $c);
- }
- if($c->aborted()) { return ('ERROR', undef); }
+=over 4
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.3');
- return ('ERROR', undef);
- }
- my $problemData;
- if($isNotCached) {
- ($problemData) = &ExtractStudentData(\%cache, $students);
- &CalculateStatistics($problemData, \%cache, $courseID);
- }
- untie(%cache);
+=cut
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
- $r->print('Unable to tie database.4');
- return ('ERROR', undef);
- }
- if($isNotCached) {
- foreach(keys(%$problemData)) {
- $cache{$_} = $problemData->{$_};
- }
- $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
- $cache{'StatisticsCached'} = 'true';
- $cache{'StatisticsLastStatus'} = $cache{'Status'};
- $cache{'StatisticsWhichStudents'} = $whichStudents;
- }
- untie(%cache);
+###############################################
+###############################################
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.5');
- return ('ERROR', undef);
- }
+package Apache::lonproblemstatistics;
- my $orderedProblems = &SortProblems(\%cache,
- $cache{'ProblemStatisticsSort'},
- $cache{'SortProblems'},
- $cache{'ProblemStatisticsAscend'});
- untie(%cache);
+use strict;
+use Apache::lonnet();
+use Apache::loncommon();
+use Apache::lonhtmlcommon;
+use Apache::loncoursedata;
+use Apache::lonstatistics;
+use Apache::lonlocal;
+use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
+
+##
+## 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 => 'Sequence or Folder',
+ align => 'left',
+ color => '#FFFFE6',
+ sortable => 'yes' },
+ { name => 'title',
+ title => 'Title',
+ align => 'left',
+ color => '#FFFFE6',
+ special => 'link',
+ sortable => 'yes', },
+ { name => 'part',
+ title => 'Part',
+ align => 'left',
+ color => '#FFFFE6',
+ },
+ { name => 'num_students',
+ title => '#Stdnts',
+ align => 'right',
+ color => '#EEFFCC',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Number of Students Attempting Problem' },
+ { name => 'tries',
+ title => 'Tries',
+ align => 'right',
+ color => '#EEFFCC',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Total Number of Tries' },
+ { name => 'max_tries',
+ title => 'Max Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Maximum Number of Tries' },
+ { name => 'mean_tries',
+ title => 'Mean Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Average Number of Tries' },
+ { name => 'std_tries',
+ title => 'S.D. tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Standard Deviation of Number of Tries' },
+ { name => 'skew_tries',
+ title => 'Skew Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Skew of Number of Tries' },
+ { name => 'deg_of_diff',
+ title => 'DoDiff',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Degree of Difficulty'.
+ '[ 1 - ((#YES+#yes) / Tries) ]'},
+ { name => 'num_solved',
+ title => '#YES',
+ align => 'right',
+ color => '#FFDDDD',
+ format => '%4.1f',# format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Number of Students able to Solve' },
+ { name => 'num_override',
+ title => '#yes',
+ align => 'right',
+ color => '#FFDDDD',
+ format => '%4.1f',# format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Number of Students given Override' },
+ { name => 'per_wrong',
+ title => '%Wrng',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.1f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Percent of students whose final answer is wrong' },
+);
+
+###############################################
+###############################################
+
+=pod
+
+=item &CreateInterface()
+
+Create the main intereface for the statistics page. Allows the user to
+select sections, maps, and output.
+
+=cut
+
+###############################################
+###############################################
+my @OutputOptions =
+ (
+ { name => 'grouped by sequence',
+ value => 'HTML problem statistics grouped',
+ description => 'Output statistics for the problem parts.',
+ mode => 'html',
+ show => 'grouped',
+ },
+ { name => 'ungrouped',
+ value => 'HTML problem statistics ungrouped',
+ description => 'Output statistics for the problem parts.',
+ mode => 'html',
+ show => 'ungrouped',
+ },
+ { name => 'Excel',
+ value => 'Excel problem statistics',
+ description => 'Output statistics for the problem parts '.
+ 'in an Excel workbook',
+ mode => 'excel',
+ show => 'all',
+ },
+ );
+
+sub CreateInterface {
+ my $Str = '';
+ $Str .= &Apache::lonhtmlcommon::breadcrumbs
+ (undef,'Overall Problem Statistics','Statistics_Overall_Key');
+ $Str .= '
'."\n";
+ $Str .= '';
+ $Str .= ''.&mt('Sections').' ';
+ $Str .= ''.&mt('Enrollment Status').' ';
+ $Str .= ''.&mt('Sequences and Folders').' ';
+ $Str .= ''.&mt('Output').' ';
+ $Str .= ''.
+ &Apache::lonstathelpers::limit_by_time_form().' ';
+ $Str .= ' '."\n";
+ #
+ $Str .= ''."\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";
+ my ($html,$outputmode,$show) =
+ &Apache::lonstatistics::CreateAndParseOutputSelector(
+ 'statsoutputmode',
+ 'HTML problem statistics grouped',
+ @OutputOptions);
+ $Str .= $html;
+ $Str .= ' '."\n";
+ $Str .= '
'."\n";
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ return ($Str,$outputmode,$show);
+}
+
+###############################################
+###############################################
+
+=pod
- return ('OK', $orderedProblems);
-}
+=item &BuildProblemStatisticsPage()
-sub BuildProblemStatisticsPage {
- my ($cacheDB, $students, $courseID, $c, $r)=@_;
+Main interface to problem statistics.
- my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
- "Mean","#YES","#yes","%Wrng","DoDiff",
- "S.D.","Skew.","D.F.1st","D.F.2nd");
- my $color=&setbgcolor(0);
- my %cache;
+=cut
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.6');
+###############################################
+###############################################
+sub BuildProblemStatisticsPage {
+ 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();
+ $r->print($interface);
+ $r->print(' ');
+ $r->print(' ');
+ $r->print(' ');
+ if (! exists($ENV{'form.statsfirstcall'})) {
return;
}
- my $Ptr = '';
- $Ptr .= '';
- $Ptr .= 'Select Map '."\n";
- $Ptr .= '';
- $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'Statistics',
- 'Statistics');
- $Ptr .= ' '."\n";
- $Ptr .= 'Sorting Type: '."\n";
- $Ptr .= ''."\n";
- $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
- $cache{'ProblemStatisticsAscend'},
- 'ProblemStatistics',
- 'Statistics');
- $Ptr .= ' '."\n";
- $Ptr .= 'Select Sections ';
- $Ptr .= ' '."\n";
- $Ptr .= ''."\n";
- my @sections = split(':',$cache{'sectionList'});
- my @sectionsSelected = split(':',$cache{'sectionsSelected'});
- $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
- \@sectionsSelected,
- 'Statistics');
- $Ptr .= ' '."\n";
- $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'},
- $cache{'DisplayLegend'},
- $cache{'SortProblems'});
- $Ptr .= '
';
- if($cache{'DisplayLegend'} eq 'Show Legend') {
- $Ptr .= &ProblemStatisticsLegend();
+ #
+ &Apache::lonstatistics::Gather_Student_Data($r);
+ #
+ #
+ if ($output_mode eq 'html') {
+ $r->print("".
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
+ " \n");
+ my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
+ if (defined($starttime) || defined($endtime)) {
+ # Inform the user what the time limits on the data are.
+ $r->print(''.&mt('Statistics on submissions from [_1] to [_2]',
+ &Apache::lonlocal::locallocaltime($starttime),
+ &Apache::lonlocal::locallocaltime($endtime)).
+ ' ');
+ }
+ $r->print("".&mt('Compiled on [_1]',
+ &Apache::lonlocal::locallocaltime(time))." ");
+ $r->rflush();
+ if ($show eq 'grouped') {
+ &output_html_grouped_by_sequence($r);
+ } elsif ($show eq 'ungrouped') {
+ &output_html_ungrouped($r);
+ }
+ } elsif ($output_mode eq 'excel') {
+ $r->print(''.&mt('Preparing Excel Spreadsheet').' ');
+ &output_excel($r);
+ } else {
+ $r->print(''.&mt('Not implemented').' ');
}
- $r->print($Ptr);
- $r->rflush();
- untie(%cache);
+ return;
+}
- my ($result, $orderedProblems) =
- &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
- if($result ne 'OK') {
- return;
- }
+###############################################
+###############################################
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.6');
- return;
- }
- &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
- $cache{'SortProblems'}, $orderedProblems,
- \@Header, $r, $color);
- untie(%cache);
+=pod
+
+=item &output_html_grouped_by_sequence()
+Presents the statistics data as an html table organized by the order
+the assessments appear in the course.
+
+=cut
+
+###############################################
+###############################################
+sub output_html_grouped_by_sequence {
+ my ($r) = @_;
+ my $problem_num = 0;
+ #$r->print(&ProblemStatisticsLegend());
+ foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
+ next if ($sequence->{'num_assess'}<1);
+ $r->print("".$sequence->{'title'}." ");
+ $r->print(''."\n");
+ $r->print(''."\n");
+ $r->print('');
+ my $Str = &statistics_table_header('no container no plots');
+ $r->print(' '.$Str." \n");
+ foreach my $resource (@{$sequence->{'contents'}}) {
+ next if ($resource->{'type'} ne 'assessment');
+ foreach my $part (@{$resource->{'parts'}}) {
+ $problem_num++;
+ my $data = &get_statistics($sequence,$resource,$part,
+ $problem_num);
+ my $option = '';
+ $r->print(''.&statistics_html_table_data($data,
+ 'no container').
+ " \n");
+ }
+ }
+ $r->print("
\n");
+ $r->print("
\n");
+ $r->rflush();
+ }
+ #
return;
}
-sub BuildGraphicChart {
- my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
- my %cache;
- my $max = 0;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- return 'Unable to tie database.7';
- }
+###############################################
+###############################################
+
+=pod
- my $title = '';
- if($graph eq 'DoDiffGraph') {
- $title = 'Degree-of-Difficulty';
+=item &output_html_ungrouped()
+
+Presents the statistics data in a single html table which can be sorted by
+different columns.
+
+=cut
+
+###############################################
+###############################################
+sub output_html_ungrouped {
+ my ($r,$option) = @_;
+ #
+ if (exists($ENV{'form.plot'}) && $ENV{'form.plot'} ne '') {
+ &plot_statistics($r,$ENV{'form.plot'});
+ }
+ #
+ my $problem_num = 0;
+ my $show_container = 0;
+ my $show_part = 0;
+ #$r->print(&ProblemStatisticsLegend());
+ my $sortby = undef;
+ foreach my $field (@Fields) {
+ if ($ENV{'form.sortby'} eq $field->{'name'}) {
+ $sortby = $field->{'name'};
+ }
+ }
+ if (! defined($sortby) || $sortby eq '' || $sortby eq 'problem_num') {
+ $sortby = 'container';
+ }
+ # If there is more than one sequence, list their titles
+ my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
+ if (@Sequences < 1) {
+ $option .= ' no container';
+ }
+ #
+ # Compile the data
+ my @Statsarray;
+ foreach my $sequence (@Sequences) {
+ next if ($sequence->{'num_assess'}<1);
+ foreach my $resource (@{$sequence->{'contents'}}) {
+ next if ($resource->{'type'} ne 'assessment');
+ foreach my $part (@{$resource->{'parts'}}) {
+ $problem_num++;
+ my $data = &get_statistics($sequence,$resource,$part,
+ $problem_num);
+ $show_part = 1 if ($part ne '0');
+ #
+ push (@Statsarray,$data);
+ }
+ }
+ }
+ #
+ # Sort the data
+ my @OutputOrder;
+ if ($sortby eq 'container') {
+ @OutputOrder = @Statsarray;
} else {
- $title = 'Wrong-Percentage';
+ # $sortby is already defined, so we can charge ahead
+ if ($sortby =~ /^(title|part)$/i) {
+ # Alpha comparison
+ @OutputOrder = sort {
+ lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
+ lc($a->{'title'}) cmp lc($b->{'title'}) ||
+ lc($a->{'part'}) cmp lc($b->{'part'});
+ } @Statsarray;
+ } else {
+ # Numerical comparison
+ @OutputOrder = sort {
+ my $retvalue = 0;
+ if ($b->{$sortby} eq 'nan') {
+ if ($a->{$sortby} ne 'nan') {
+ $retvalue = -1;
+ } else {
+ $retvalue = 0;
+ }
+ }
+ if ($a->{$sortby} eq 'nan') {
+ if ($b->{$sortby} ne 'nan') {
+ $retvalue = 1;
+ }
+ }
+ if ($retvalue eq '0') {
+ $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
+ lc($a->{'title'}) <=> lc($b->{'title'}) ||
+ lc($a->{'part'}) <=> lc($b->{'part'});
+ }
+ $retvalue;
+ } @Statsarray;
+ }
}
+ $option .= 'no part' if (! $show_part);
+ my $num_output = 0;
+ #
+ # output the headers
+ $r->print(''."\n");
+ $r->print(''."\n");
+ my $Str = &statistics_table_header($option.' sortable');
+ $r->print(''.$Str." \n");
+ #
+ foreach my $rowdata (@OutputOrder) {
+ $num_output++;
+ if ($num_output % 25 == 0) {
+ $r->print("
\n
\n");
+ #
+ $r->print(''."\n");
+ $r->print(''."\n");
+ my $Str = &statistics_table_header($option.' sortable');
+ $r->print(''.$Str." \n");
+ $r->rflush();
+ }
+ $r->print(''.&statistics_html_table_data($rowdata,$option).
+ " \n");
+ }
+ $r->print("
\n");
+ $r->print("
\n");
+ $r->rflush();
+ #
+ return;
+}
- my $currentSequence = -1;
- my $sortProblems = 'Sort Within Sequence';
+###############################################
+###############################################
- my ($result, $orderedProblems) =
- &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
- if($result ne 'OK') {
- return;
- }
+=pod
- my @values = ();
+=item &output_excel()
- foreach(@$orderedProblems) {
- my ($sequence,$problem,$part)=split(':', $_);
- if($cache{'StatisticsMaps'} ne 'All Maps' &&
- $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) {
- next;
- }
-
- if( $currentSequence == -1 ||
- ($sortProblems eq 'Sort Within Sequence' &&
- $currentSequence != $sequence)) {
- if($currentSequence != -1) {
- &DrawGraph(\@values,$courseDescription,$title,$max,$r);
- }
- if($sortProblems eq 'Sort Within Sequence') {
- $r->print(''.$cache{$sequence.':title'}.' ');
- }
+Presents the statistical data in an Excel 95 compatable spreadsheet file.
- $currentSequence = $sequence;
- @values = ();
+=cut
+
+###############################################
+###############################################
+sub output_excel {
+ my ($r) = @_;
+ my $filename = '/prtspool/'.
+ $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.xls';
+ #
+ my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
+ #
+ my $excel_workbook = undef;
+ my $excel_sheet = undef;
+ #
+ my $rows_output = 0;
+ my $cols_output = 0;
+ #
+ # Create sheet
+ $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
+ #
+ # Check for errors
+ if (! defined($excel_workbook)) {
+ $r->log_error("Error creating excel spreadsheet $filename: $!");
+ $r->print(&mt("Problems creating new Excel file. ".
+ "This error has been logged. ".
+ "Please alert your LON-CAPA administrator."));
+ return ;
+ }
+ #
+ # The excel spreadsheet stores temporary data in files, then put them
+ # together. If needed we should be able to disable this (memory only).
+ # The temporary directory must be specified before calling 'addworksheet'.
+ # File::Temp is used to determine the temporary directory.
+ $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
+ #
+ # Add a worksheet
+ my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+ if (length($sheetname) > 31) {
+ $sheetname = substr($sheetname,0,31);
+ }
+ $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++,
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
+ $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];
}
- my $data = 0;
- if($graph eq 'DoDiffGraph') {
- $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
+ }
+ $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
+ $cols_output += scalar(@Sections);
+ #
+ # Time restrictions
+ my $time_string;
+ if (defined($starttime)) {
+ # call localtime but not lonlocal:locallocaltime because excel probably
+ # cannot handle localized text. Probably.
+ $time_string .= 'Data collected from '.localtime($time_string);
+ if (defined($endtime)) {
+ $time_string .= ' to '.localtime($endtime);
+ }
+ $time_string .= '.';
+ } elsif (defined($endtime)) {
+ # See note above about lonlocal:locallocaltime
+ $time_string .= 'Data collected before '.localtime($endtime).'.';
+ }
+
+ #
+ # Put the date in there too
+ $excel_sheet->write($rows_output,$cols_output++,
+ 'Compiled on '.localtime(time));
+ #
+ $rows_output++;
+ $cols_output=0;
+ #
+ # 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 {
- $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
+ $excel_sheet->write($rows_output,$cols_output++,'');
}
- if($max < $data) {
- $max = $data;
+ }
+ $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++;
+ #
+ # Write the data
+ my $problem_num=0;
+ foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
+ next if ($sequence->{'num_assess'}<1);
+ foreach my $resource (@{$sequence->{'contents'}}) {
+ next if ($resource->{'type'} ne 'assessment');
+ foreach my $part (@{$resource->{'parts'}}) {
+ $cols_output=0;
+ $problem_num++;
+ my $data = &get_statistics($sequence,$resource,$part,
+ $problem_num);
+ #
+ if (!defined($part) || $part eq '') {
+ $part = ' ';
+ }
+ foreach my $field (@Fields) {
+ next if ($field->{'name'} eq 'problem_num');
+ $excel_sheet->write($rows_output,$cols_output++,
+ $data->{$field->{'name'}});
+ }
+ $rows_output++;
+ }
}
- push(@values, $data);
}
- untie(%cache);
-
- &DrawGraph(\@values,$courseDescription,$title,$max,$r);
-
+ #
+ # Write the excel file
+ $excel_workbook->close();
+ # Tell the user where to get their excel file
+ $r->print(' '.
+ ''.
+ &mt('Your Excel Spreadsheet').' '."\n");
+ $r->rflush();
return;
}
+###############################################
+###############################################
-sub DrawGraph {
- my ($values,$courseDescription,$title,$Max,$r)=@_;
- my $sendValues = join(',', @$values);
- my $sendCount = scalar(@$values);
-
- if ( $Max > 1 ) {
- if ($Max % 10) {
- $Max++;
- }
- #(10 - $Max % 10);
- $Max = int($Max);
- } else { $Max = 1; }
-
- my @GData = ($courseDescription, 'Problem_number',
- $title, $Max, $sendCount, $sendValues);
- $r->print(''."\n");
- $r->print(' ');
- $r->print('