'."\n";
$Str .= ''."\n";
$Str .= '';
$Str .= ' 'x5;
+ $Str .= 'Plot '.&plot_dropdown().(' 'x10);
$Str .= '';
$Str .= ' 'x5;
- return ($Str,$outputmode,$show);
+ $Str .= '';
+ $Str .= ' 'x5;
+ $Str .= '';
+ $Str .= ' 'x5;
+ return $Str;
}
###############################################
@@ -292,250 +278,418 @@ sub BuildProblemStatisticsPage {
#
&Apache::lonstatistics::PrepareClasslist();
#
- &Apache::loncoursedata::populate_weight_table();
+ # Clear the package variables
+ undef(@StatsArray);
#
- my ($interface,$output_mode,$show) = &CreateInterface();
+ # Finally let the user know we are here
+ my $interface = &CreateInterface();
$r->print($interface);
- $r->print('');
$r->print('');
- $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('');
}
+ $r->rflush();
#
- &Apache::lonstatistics::Gather_Student_Data($r);
- #
+ # 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 $sortby = $ENV{'form.sortby'};
+ $sortby = 'container' if (! defined($sortby) || $sortby =~ /^\s*$/);
+ my $plot = $ENV{'form.plot'};
+ &Apache::lonnet::logthis('form.plot = '.$plot);
+ if ($sortby eq 'container' && ! defined($plot)) {
+ &output_html_by_sequence($r);
+ } else {
+ if (defined($plot)) {
+ &Apache::lonnet::logthis('calling plot routine');
+ &make_plot($r,$plot);
+ }
+ &output_html_stats($r);
+ }
+ }
+ return;
+}
+
+##########################################################
+##########################################################
+##
+## HTML output routines
+##
+##########################################################
+##########################################################
+sub output_html_by_sequence {
+ my ($r) = @_;
+ my $c = $r->connection();
+ $r->print(&html_preamble());
#
- if ($output_mode eq 'html') {
- $r->print("
\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)).
- '
');
+ 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('
\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;
+}
-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('
\n");
#
- # Print out the data
- $ENV{'form.sortby'} = 'Contents';
-# &output_html_ungrouped($r);
+ # Renumber the data set
+ my $count;
+ foreach my $data (@StatsArray) {
+ $data->{'problem_num'} = ++$count;
+ }
return;
}
@@ -831,7 +907,8 @@ sub plot_statistics {
=item &get_statistics()
Wrapper routine from the call to loncoursedata::get_problem_statistics.
-Calls lonstathelpers::get_time_limits() to limit the data set by time.
+Calls lonstathelpers::get_time_limits() to limit the data set by time
+and &compute_discrimination_factor
Inputs: $sequence, $resource, $part, $problem_num
@@ -924,70 +1001,170 @@ sub compute_discrimination_factor {
=pod
-=item &ProblemStatisticsLegend()
+=item ProblemStatisticsLegend
+
+=over 4
+
+=item #Stdnts
+Total number of students attempted the problem.
+
+=item Tries
+Total number of tries for solving the problem.
-HELP This needs to be localized, or at least generated automatically.
+=item Max Tries
+Largest number of tries for solving the problem by a student.
+
+=item Mean
+Average number of tries. [ Tries / #Stdnts ]
+
+=item #YES
+Number of students solved the problem correctly.
+
+=item #yes
+Number of students solved the problem by override.
+
+=item %Wrong
+Percentage of students who tried to solve the problem
+but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]
+
+=item DoDiff
+Degree of Difficulty of the problem.
+[ 1 - ((#YES+#yes) / Tries) ]
+
+=item S.D.
+Standard Deviation of the tries.
+[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)
+where Xi denotes every student\'s tries ]
+
+=item Skew.
+Skewness of the students tries.
+[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]
+
+=item Dis.F.
+Discrimination Factor: A Standard for evaluating the
+problem according to a Criterion
+
+=item [Criterion to group students into %27 Upper Students -
+and %27 Lower Students]
+1st Criterion for Sorting the Students:
+Sum of Partial Credit Awarded / Total Number of Tries
+2nd Criterion for Sorting the Students:
+Total number of Correct Answers / Total Number of Tries
+
+=item Disc.
+Number of Students had at least one discussion.
+
+=back
=cut
-###############################################
-###############################################
-sub ProblemStatisticsLegend {
- my $Ptr = '';
- $Ptr = '
';
- $Ptr .= '
';
- $Ptr .= '#Stdnts
';
- $Ptr .= '
Total number of students attempted the problem.';
- $Ptr .= '
';
- $Ptr .= 'Tries
';
- $Ptr .= '
Total number of tries for solving the problem.';
- $Ptr .= '
';
- $Ptr .= 'Max Tries
';
- $Ptr .= '
Largest number of tries for solving the problem by a student.';
- $Ptr .= '
';
- $Ptr .= 'Mean
';
- $Ptr .= '
Average number of tries. [ Tries / #Stdnts ]';
- $Ptr .= '
';
- $Ptr .= '#YES
';
- $Ptr .= '
Number of students solved the problem correctly.';
- $Ptr .= '
';
- $Ptr .= '#yes
';
- $Ptr .= '
Number of students solved the problem by override.';
- $Ptr .= '
';
- $Ptr .= '%Wrong
';
- $Ptr .= '
Percentage of students who tried to solve the problem ';
- $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
- $Ptr .= '
';
- $Ptr .= 'DoDiff
';
- $Ptr .= '
Degree of Difficulty of the problem. ';
- $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
- $Ptr .= '
';
- $Ptr .= 'S.D.
';
- $Ptr .= '
Standard Deviation of the tries. ';
- $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
- $Ptr .= 'where Xi denotes every student\'s tries ]';
- $Ptr .= '
';
- $Ptr .= 'Skew.
';
- $Ptr .= '
Skewness of the students tries.';
- $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
- $Ptr .= '
';
- $Ptr .= 'Dis.F.
';
- $Ptr .= '
Discrimination Factor: A Standard for evaluating the ';
- $Ptr .= 'problem according to a Criterion ';
- $Ptr .= '[Criterion to group students into %27 Upper Students - ';
- $Ptr .= 'and %27 Lower Students] ';
- $Ptr .= '1st Criterion for Sorting the Students: ';
- $Ptr .= 'Sum of Partial Credit Awarded / Total Number of Tries ';
- $Ptr .= '2nd Criterion for Sorting the Students: ';
- $Ptr .= 'Total number of Correct Answers / Total Number of Tries';
- $Ptr .= '
';
- $Ptr .= '
Disc.
';
- $Ptr .= '
Number of Students had at least one discussion.';
- $Ptr .= '
';
- return $Ptr;
+
+############################################################
+############################################################
+##
+## How this all works:
+## Statistics are computed by calling &get_statistics with the sequence,
+## resource, and part id to run statistics on. At various places within
+## the loops which compute the statistics, as well as before and after
+## the entire process, subroutines can be called. The subroutines are
+## registered to the following hooks:
+##
+## hook subroutine inputs
+## ----------------------------------------------------------
+## pre $r,$count
+## pre_seq $r,$count,$seq
+## pre_res $r,$count,$seq,$res
+## calc $r,$count,$seq,$res,$data
+## post_res $r,$count,$seq,$res
+## post_seq $r,$count,$seq
+## post $r,$count
+##
+## abort $r
+##
+## subroutines will be called in the order in which they are registered.
+##
+############################################################
+############################################################
+{
+
+my %hooks;
+my $aborted = 0;
+
+sub abort_computation {
+ $aborted = 1;
+}
+
+sub clear_hooks {
+ $aborted = 0;
+ undef(%hooks);
+}
+
+sub register_hook {
+ my ($hookname,$subref)=@_;
+ if ($hookname !~ /^(pre|pre_seq|pre_res|post|post_seq|post_res|calc)$/){
+ return;
+ }
+ if (ref($subref) ne 'CODE') {
+ &Apache::lonnet::logthis('attempt to register hook to non-code: '.
+ $hookname,' = '.$subref);
+ } else {
+ if (exists($hooks{$hookname})) {
+ push(@{$hooks{$hookname}},$subref);
+ } else {
+ $hooks{$hookname} = [$subref];
+ }
+ }
+ return;
+}
+
+sub run_hooks {
+ my $context = shift();
+ foreach my $hook (@{$hooks{$context}}) {
+ if ($aborted && $context ne 'abort') {
+ last;
+ }
+ my $retvalue = $hook->(@_);
+ if (defined($retvalue) && $retvalue eq '0') {
+ $aborted = 1 if (! $aborted);
+ }
+ }
}
-#---- END Problem Statistics Web Page ----------------------------------------
+sub run_statistics {
+ my ($r) = @_;
+ my $count = 0;
+ &run_hooks('pre',$r,$count);
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ last if ($aborted);
+ next if ($seq->{'num_assess'}<1);
+ &run_hooks('pre_seq',$r,$count,$seq);
+ foreach my $res (@{$seq->{'contents'}}) {
+ last if ($aborted);
+ next if ($res->{'type'} ne 'assessment');
+ &run_hooks('pre_res',$r,$count,$seq,$res);
+ foreach my $part (@{$res->{'parts'}}) {
+ last if ($aborted);
+ #
+ # This is where all the work happens
+ my $data = &get_statistics($seq,$res,$part,++$count);
+ &run_hooks('calc',$r,$count,$seq,$res,$part,$data);
+ }
+ &run_hooks('post_res',$r,$count,$seq,$res);
+ }
+ &run_hooks('post_seq',$r,$count,$seq);
+ }
+ if ($aborted) {
+ &run_hooks('abort',$r);
+ } else {
+ &run_hooks('post',$r,$count);
+ }
+ return;
+}
+
+} # End of %hooks scope
+
+############################################################
+############################################################
1;
__END__