--- loncom/interface/statistics/lonproblemstatistics.pm 2002/11/26 16:59:03 1.37
+++ loncom/interface/statistics/lonproblemstatistics.pm 2004/05/18 18:12:19 1.86
@@ -1,7 +1,6 @@
# The LearningOnline Network with CAPA
-# (Publication Handler
#
-# $Id: lonproblemstatistics.pm,v 1.37 2002/11/26 16:59:03 minaeibi Exp $
+# $Id: lonproblemstatistics.pm,v 1.86 2004/05/18 18:12:19 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,836 +25,1701 @@
# 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
#
-###
+###############################################
+###############################################
+
+=pod
+
+=head1 NAME
+
+lonproblemstatistics
+
+=head1 SYNOPSIS
+
+Routines to present problem statistics to instructors via tables,
+Excel files, and plots.
+
+=over 4
+
+=cut
+
+###############################################
+###############################################
package Apache::lonproblemstatistics;
use strict;
use Apache::lonnet();
+use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
-use GDBM_File;
-
-
-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;
- }
+use Apache::lonstatistics;
+use LONCAPA::lonmetadata();
+use Apache::lonlocal;
+use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
+use Time::HiRes;
+
+my @StatsArray;
+my %SeqStat; # keys are symbs, values are hash refs
+
+##
+## 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.
+##
+#
+#
+##
+## Description of Field attributes
+##
+## Attribute Required Value Meaning or Use
+##
+## name yes any scalar Used to uniquely identify field
+## title yes any scalar This is what the user sees to identify
+## the field. Passed through &mt().
+## long_title yes any scalar Used as graph heading and in excel
+## output. NOT translated
+## align no (left|right|center) HTML cell contents alignment
+## color yes html color HTML cell background color
+## used to visually group statistics
+## special no (link) Indicates a link, target is name.link
+## Currently set in &get_statistics()
+## graphable no (yes|no) Can a bar graph of the field be
+## produced?
+## sortable no (yes|no) Should a sort link be put in the
+## column header?
+## selectable yes (yes|no) Can the column be removed from the
+## statistics display?
+## selected yes (yes|no) Is the column selected by default?
+##
+## format no sprintf format string
+##
+## excel_format no excel format type
+## (see &Apache::loncommon::define_excel_formats
+my @Fields = (
+ { name => 'problem_num',
+ title => 'P#',
+ align => 'right',
+ color => '#FFFFE6',
+ selectable => 'no',
+ defaultselected => 'yes',
+ },
+ { name => 'container',
+ title => 'Sequence or Folder',
+ align => 'left',
+ color => '#FFFFE6',
+ sortable => 'yes',
+ selectable => 'no',
+ defaultselected => 'yes',
+ },
+ { name => 'title',
+ title => 'Title',
+ align => 'left',
+ color => '#FFFFE6',
+ special => 'link',
+ sortable => 'yes',
+ selectable => 'no',
+ defaultselected => 'yes',
+ },
+ { name => 'part',
+ title => 'Part',
+ align => 'left',
+ color => '#FFFFE6',
+ selectable => 'no',
+ defaultselected => 'yes',
+ },
+ { name => 'num_students',
+ title => '#Stdnts',
+ align => 'right',
+ color => '#EEFFCC',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Number of Students Attempting Problem',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'tries',
+ title => 'Tries',
+ align => 'right',
+ color => '#EEFFCC',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Total Number of Tries',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'max_tries',
+ title => 'Max Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Maximum Number of Tries',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'min_tries',
+ title => 'Min Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%d',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Minumum Number of Tries',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'mean_tries',
+ title => 'Mean Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Average Number of Tries',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { 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',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'skew_tries',
+ title => 'Skew Tries',
+ align => 'right',
+ color => '#DDFFFF',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Skew of Number of Tries',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { 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',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { 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',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'num_wrong',
+ title => '#Wrng',
+ align => 'right',
+ color => '#FFDDDD',
+ format => '%4.1f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Percent of students whose final answer is wrong',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'deg_of_diff',
+ title => 'DoDiff',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%5.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Degree of Difficulty'.
+ '[ 1 - ((#YES+#yes) / Tries) ]',
+ selectable => 'yes',
+ defaultselected => 'yes',
+ },
+ { name => 'deg_of_disc',
+ title => 'DoDisc',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.2f',
+ sortable => 'yes',
+ graphable => 'yes',
+ long_title => 'Degree of Discrimination',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+## duedate included for research purposes. Commented out most of the time.
+# { name => 'duedate',
+# title => 'Due Date',
+# align => 'left',
+# color => '#FFFFFF',
+# sortable => 'yes',
+# graphable => 'no',
+# long_title => 'Due date of resource for instructor',
+# selectable => 'no',
+# defaultselected => 'yes',
+# },
+## opendate included for research purposes. Commented out most of the time.
+# { name => 'opendate',
+# title => 'Open Date',
+# align => 'left',
+# color => '#FFFFFF',
+# sortable => 'yes',
+# graphable => 'no',
+# long_title => 'date resource became answerable',
+# selectable => 'no',
+# defaultselected => 'yes',
+# },
+## symb included for research purposes. Commented out most of the time.
+# { name => 'symb',
+# title => 'Symb',
+# align => 'left',
+# color => '#FFFFFF',
+# sortable => 'yes',
+# graphable => 'no',
+# long_title => 'Unique LON-CAPA identifier for problem',
+# selectable => 'no',
+# defaultselected => 'yes',
+# },
+## resptypes included for research purposes. Commented out most of the time.
+# { name => 'resptypes',
+# title => 'Response Types',
+# align => 'left',
+# color => '#FFFFFF',
+# sortable => 'no',
+# graphable => 'no',
+# long_title => 'Response Types used in this problem',
+# selectable => 'no',
+# defaultselected => 'yes',
+# },
+);
+
+my @SeqFields = (
+ { name => 'title',
+ title => 'Sequence',
+ align => 'left',
+ color => '#FFFFE6',
+ special => 'no',
+ sortable => 'no',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'items',
+ title => '#Items',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4d',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Number of Items in Sequence',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'scoremean',
+ title => 'Score Mean',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Mean Sequence Score',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'scorestd',
+ title => 'Score STD',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Standard Deviation of Sequence Scores',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'scoremax',
+ title => 'Score Max',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Maximum Sequence Score',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'scoremin',
+ title => 'Score Min',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Minumum Sequence Score',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'scorecount',
+ title => 'Score N',
+ align => 'right',
+ color => '#FFFFE6',
+ format => '%4d',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Number of Students in score computations',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'countmean',
+ title => 'Count Mean',
+ align => 'right',
+ color => '#FFFFFF',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Mean Sequence Score',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'countstd',
+ title => 'Count STD',
+ align => 'right',
+ color => '#FFFFFF',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Standard Deviation of Sequence Scores',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'countmax',
+ title => 'Count Max',
+ align => 'right',
+ color => '#FFFFFF',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Maximum Number of Correct Problems',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'countmin',
+ title => 'Count Min',
+ align => 'right',
+ color => '#FFFFFF',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Minumum Number of Correct Problems',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'count',
+ title => 'Count N',
+ align => 'right',
+ color => '#FFFFFF',
+ format => '%4d',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'Number of Students in score computations',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+ { name => 'KR-21',
+ title => 'KR-21',
+ align => 'right',
+ color => '#FFAAAA',
+ format => '%4.2f',
+ sortable => 'no',
+ graphable => 'no',
+ long_title => 'KR-21 reliability statistic',
+ selectable => 'yes',
+ defaultselected => 'no',
+ },
+);
+
+my %SelectedFields;
+
+sub parse_field_selection {
+ #
+ # Pull out the defaults
+ if (! defined($ENV{'form.fieldselections'})) {
+ $ENV{'form.fieldselections'} = [];
+ foreach my $field (@Fields) {
+ next if ($field->{'selectable'} ne 'yes');
+ if ($field->{'defaultselected'} eq 'yes') {
+ push(@{$ENV{'form.fieldselections'}},$field->{'name'});
}
}
- if($found == 0) {
- splice(@$students, $studentIndex, 1);
- }
}
-
- 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;
- }
-
- 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{$_};
+ #
+ # Make sure the data we are plotting is there
+ my %NeededFields;
+ if (exists($ENV{'form.plot'}) && $ENV{'form.plot'} ne '' &&
+ $ENV{'form.plot'} ne 'none') {
+ if ($ENV{'form.plot'} eq 'degrees') {
+ $NeededFields{'deg_of_diff'}++;
+ $NeededFields{'deg_of_disc'}++;
+ } elsif ($ENV{'form.plot'} eq 'tries statistics') {
+ $NeededFields{'mean_tries'}++;
+ $NeededFields{'std_tries'}++;
+ $NeededFields{'problem_num'}++;
+ } else {
+ $NeededFields{$ENV{'form.plot'}}++;
}
}
-
- untie(%cache);
- if($isNotCached) {
- &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
- 'true',
- $cacheDB,
- 'true',
- 'true',
- $courseID,
- $r, $c);
- }
- if($c->aborted()) { return ('ERROR', undef); }
-
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.3');
- return ('ERROR', undef);
+ #
+ # This should not happen, but in case it does...
+ if (ref($ENV{'form.fieldselections'}) ne 'ARRAY') {
+ $ENV{'form.fieldselections'} = [$ENV{'form.fieldselections'}];
+ }
+ #
+ # Set the field data and the selected fields (for easier checking)
+ undef(%SelectedFields);
+ foreach my $field (@Fields) {
+ if ($field->{'selectable'} ne 'yes') {
+ $field->{'selected'} = 'yes';
+ } else {
+ $field->{'selected'} = 'no';
+ }
+ if (exists($NeededFields{$field->{'name'}})) {
+ $field->{'selected'} = 'yes';
+ $SelectedFields{$field->{'name'}}++;
+ }
+ foreach my $selection (@{$ENV{'form.fieldselections'}}) {
+ if ($selection eq $field->{'name'} || $selection eq 'all') {
+ $field->{'selected'} = 'yes';
+ $SelectedFields{$field->{'name'}}++;
+ }
+ }
}
- my $problemData;
- if($isNotCached) {
- ($problemData) = &ExtractStudentData(\%cache, $students);
- &CalculateStatistics($problemData, \%cache, $courseID);
+ #
+ # Always show all the sequence statistics (for now)
+ foreach my $field (@SeqFields) {
+ $field->{'selected'} = 'yes';
}
- untie(%cache);
+ return;
+}
- 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->{$_};
+sub field_selection_input {
+ my $Str = ''."\n";
+ $Str .= 'all '."\n";
+ foreach my $field (@Fields) {
+ next if ($field->{'selectable'} ne 'yes');
+ $Str .= ' {'selected'} eq 'yes') {
+ $Str .= 'selected ';
}
- $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
- $cache{'StatisticsCached'} = 'true';
- $cache{'StatisticsLastStatus'} = $cache{'Status'};
- $cache{'StatisticsWhichStudents'} = $whichStudents;
+ $Str .= '>'.$field->{'title'}.' '."\n";
}
- untie(%cache);
+ $Str .= " \n";
+}
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.5');
- return ('ERROR', undef);
- }
+###############################################
+###############################################
- my $orderedProblems = &SortProblems(\%cache,
- $cache{'ProblemStatisticsSort'},
- $cache{'SortProblems'},
- $cache{'ProblemStatisticsAscend'});
- untie(%cache);
+=pod
- return ('OK', $orderedProblems);
+=item &CreateInterface()
+
+Create the main intereface for the statistics page. Allows the user to
+select sections, maps, and output.
+
+=cut
+
+###############################################
+###############################################
+sub CreateInterface {
+ #
+ &parse_field_selection();
+ #
+ 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('Statistics').' ';
+ $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 .= ' '.&field_selection_input();
+ $Str .= ' '."\n";
+ $Str .= '
'."\n";
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ $Str .= 'Plot '.&plot_dropdown().(' 'x10);
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ $Str .= ' ';
+ $Str .= ' 'x5;
+ return $Str;
}
-sub BuildProblemStatisticsPage {
- my ($cacheDB, $students, $courseID, $c, $r)=@_;
+###############################################
+###############################################
+
+=pod
+
+=item &BuildProblemStatisticsPage()
- 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;
+Main interface to problem statistics.
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.6');
+=cut
+
+###############################################
+###############################################
+sub BuildProblemStatisticsPage {
+ my ($r,$c)=@_;
+ #
+ my %Saveable_Parameters = ('Status' => 'scalar',
+ 'statsoutputmode' => 'scalar',
+ 'Section' => 'array',
+ 'StudentData' => 'array',
+ 'Maps' => 'array',
+ 'fieldselections'=> 'array');
+ &Apache::loncommon::store_course_settings('statistics',
+ \%Saveable_Parameters);
+ &Apache::loncommon::restore_course_settings('statistics',
+ \%Saveable_Parameters);
+ #
+ &Apache::lonstatistics::PrepareClasslist();
+ #
+ # Clear the package variables
+ undef(@StatsArray);
+ undef(%SeqStat);
+ #
+ # Finally let the user know we are here
+ my $interface = &CreateInterface();
+ $r->print($interface);
+ $r->print(' ');
+ #
+ if (! exists($ENV{'form.statsfirstcall'})) {
+ $r->print(' ');
+ $r->print(''.
+ &mt('Press "Generate Statistics" when you are ready.').
+ ' '.
+ &mt('It may take some time to update the student data '.
+ 'for the first analysis. Future analysis this session '.
+ ' will not have this delay.').
+ '
');
return;
+ } elsif ($ENV{'form.statsfirstcall'} eq 'yes' ||
+ exists($ENV{'form.UpdateCache'}) ||
+ exists($ENV{'form.ClearCache'}) ) {
+ $r->print(' ');
+ &Apache::lonstatistics::Gather_Student_Data($r);
+ } else {
+ $r->print(' ');
}
- 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();
- }
- $r->print($Ptr);
$r->rflush();
- untie(%cache);
-
- my ($result, $orderedProblems) =
- &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
- if($result ne 'OK') {
- return;
+ #
+ # This probably does not need to be done each time we are called, but
+ # it does not slow things down noticably.
+ &Apache::loncoursedata::populate_weight_table();
+ #
+ if (exists($ENV{'form.Excel'})) {
+ &Excel_output($r);
+ } else {
+ my $count = 0;
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ $count += $seq->{'num_assess_parts'};
+ }
+ if ($count > 10) {
+ $r->print(''.
+ &mt('Compiling statistics for [_1] problems',$count).
+ ' ');
+ if ($count > 30) {
+ $r->print(''.&mt('This will take some time.').' ');
+ }
+ $r->rflush();
+ }
+ #
+ my $sortby = $ENV{'form.sortby'};
+ $sortby = 'container' if (! defined($sortby) || $sortby =~ /^\s*$/);
+ my $plot = $ENV{'form.plot'};
+ if ($plot eq '' || $plot eq 'none') {
+ undef($plot);
+ }
+ if ($sortby eq 'container' && ! defined($plot)) {
+ &output_sequence_statistics($r);
+ &output_html_by_sequence($r);
+ } else {
+ if (defined($plot)) {
+ &make_plot($r,$plot);
+ }
+ &output_html_stats($r);
+ &output_sequence_statistics($r);
+ }
}
+ return;
+}
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.6');
- return;
+sub output_sequence_statistics {
+ my ($r) = @_;
+ my $c=$r->connection();
+ $r->print(''.&mt('Sequence Statistics').' ');
+ $r->print(''."\n".
+ ''."\n".
+ '');
+ $r->print(&sequence_html_header());
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ last if ($c->aborted);
+ next if ($seq->{'num_assess'} < 1);
+ &compute_sequence_statistics($seq);
+ $r->print(&sequence_html_output($seq));
}
- &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},
- $cache{'SortProblems'}, $orderedProblems,
- \@Header, $r, $color);
- untie(%cache);
-
+ $r->print('
');
+ $r->print('
');
+ $r->rflush();
return;
}
-sub BuildGraphicChart {
- my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
- my %cache;
- my $max;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- return 'Unable to tie database.7';
- }
- my $title = '';
- if($graph eq 'DoDiffGraph') {
- $title = 'Degree-of-Difficulty';
- } else {
- $title = 'Wrong-Percentage';
+##########################################################
+##########################################################
+##
+## HTML output routines
+##
+##########################################################
+##########################################################
+sub output_html_by_sequence {
+ my ($r) = @_;
+ my $c = $r->connection();
+ $r->print(&html_preamble());
+ #
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ last if ($c->aborted);
+ next if ($seq->{'num_assess'} < 1);
+ $r->print("".$seq->{'title'}." ".
+ ''."\n".
+ ''."\n".
+ ''.
+ &statistics_table_header('no container')." \n");
+ my @Data = &compute_statistics_on_sequence($seq);
+ foreach my $data (@Data) {
+ $r->print(''.&statistics_html_table_data($data,
+ 'no container').
+ " \n");
+ }
+ $r->print('
'."\n".'
'."\n");
+ $r->rflush();
}
+ return;
+}
- my $currentSequence = -1;
- my $sortProblems = 'Sort Within Sequence';
+sub output_html_stats {
+ my ($r)=@_;
+ &compute_all_statistics($r);
+ $r->print(&html_preamble());
+ &sort_data($ENV{'form.sortby'});
+ #
+ my $count=0;
+ foreach my $data (@StatsArray) {
+ if ($count++ % 50 == 0) {
+ $r->print("\n\n");
+ $r->print(''."\n".
+ ''."\n".
+ ''.
+ ' '.
+ &statistics_table_header().
+ " \n");
+ }
+ $r->print(''.&statistics_html_table_data($data)." \n");
+ }
+ $r->print("
\n
\n");
+ return;
+}
- my ($result, $orderedProblems) =
- &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
- if($result ne 'OK') {
- return;
+sub html_preamble {
+ my $Str='';
+ $Str .= "".
+ $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.
+ $Str .= ''.&mt('Statistics on submissions from [_1] to [_2]',
+ &Apache::lonlocal::locallocaltime($starttime),
+ &Apache::lonlocal::locallocaltime($endtime)
+ ).' ';
}
+ $Str .= "".&mt('Compiled on [_1]',
+ &Apache::lonlocal::locallocaltime(time))." ";
+ return $Str;
+}
- my @values = ();
- 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'}.' '."\n");
+###############################################
+###############################################
+##
+## Misc HTML output routines
+##
+###############################################
+###############################################
+sub statistics_html_table_data {
+ my ($data,$options) = @_;
+ my $row = '';
+ foreach my $field (@Fields) {
+ next if ($options =~ /no $field->{'name'}/);
+ next if ($field->{'selected'} ne 'yes');
+ $row .= '{'align'})) {
+ $row .= ' align="'.$field->{'align'}.'"';
}
-
- $currentSequence = $sequence;
- @values = ();
- $max=0;
- }
- my $data = 0;
- if($graph eq 'DoDiffGraph') {
- $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
+ $row .= '>';
+ if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
+ $row .= '';
+ }
+ if (exists($field->{'format'})) {
+ $row .= sprintf($field->{'format'},$data->{$field->{'name'}});
} else {
- $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
+ $row .= $data->{$field->{'name'}};
}
- if($max < $data) {
- $max = $data;
+ if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
+ $row.= ' ';
}
- push(@values, $data);
+ $row .= ' ';
}
- untie(%cache);
-
- &DrawGraph(\@values,$courseDescription,$title,$max,$r);
-
- return;
+ return $row;
}
+sub statistics_table_header {
+ my ($options) = @_;
+ my $header_row;
+ foreach my $field (@Fields) {
+ next if ($options =~ /no $field->{'name'}/);
+ next if ($field->{'selected'} ne 'yes');
+ $header_row .= '';
+ if (exists($field->{'sortable'}) && $field->{'sortable'} eq 'yes') {
+ $header_row .= '{'name'}."'".
+ ';document.Statistics.submit();">';
+ }
+ $header_row .= &mt($field->{'title'});
+ if ($options =~ /sortable/) {
+ $header_row.= ' ';
+ }
+ if ($options !~ /no plots/ &&
+ exists($field->{'graphable'}) &&
+ $field->{'graphable'} eq 'yes') {
+ $header_row.=' (';
+ $header_row .= '';
+ $header_row .= &mt('plot').' )';
+ }
+ $header_row .= ' ';
+ }
+ return $header_row;
+}
-sub DrawGraph {
- my ($values,$courseDescription,$title,$Max,$r)=@_;
- my $sendValues = join(',', @$values);
- my $sendCount = scalar(@$values);
- $r->print(" The Maximum Value is: $Max");
- if ( $Max > 1 ) {
- if ($Max % 10) {
- if ( int($Max) < $Max ) {
- $Max++;
- $Max = int($Max);
- }
- }
- #(10 - $Max % 10);
- } else { $Max = 1; }
+sub sequence_html_header {
+ my $Str .= '';
+ foreach my $field (@SeqFields) {
+# next if ($field->{'selected'} ne 'yes');
+ $Str .= '{'title'}.' ';
+ }
+ $Str .= ' ';
+ return $Str;
+}
- my @GData = ('','Problem_number',$title,$Max,$sendCount,$sendValues);
-# $r->print(''."\n");
- $r->print(' '."\n");
- $r->print(' ');
-# $r->print('