'."\n");
- $r->print(''."\n");
- my $Str = '';
- foreach (@Header) {
- $Str .= ''.
- ''.
- $_.' | ';
- }
- $r->print(''.$Str." \n");
$r->rflush();
#
+ # Compile the data
+ my @Statsarray;
foreach my $sequence (@Sequences) {
next if ($sequence->{'num_assess'}<1);
foreach my $resource (@{$sequence->{'contents'}}) {
@@ -324,30 +326,98 @@ sub output_html_ungrouped {
$SKEW) = &Apache::loncoursedata::get_problem_statistics
(undef,$resource->{'symb'},$part,
$ENV{'request.course.id'});
- if ($part == 0) {
- $part = ' ';
- }
+ #
+ $show_part = 1 if ($part ne '0');
+ $part = ' ' if ($part == 0);
+ #
my $wrongpercent = 0;
if (defined($num) && $num > 0) {
$wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
}
- if ($show_container) {
- $r->print(''.
- ''.$sequence->{'title'}.
- ' | '.
- &statistics_html_table_data
- ($resource,$part,$num,$tries,$mod,$mean,$Solved,
- $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW).
- " \n");
- } else {
- $r->print(''.&statistics_html_table_data
- ($resource,$part,$num,$tries,$mod,$mean,$Solved,
- $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW).
- " \n");
- }
+ push (@Statsarray,
+ { 'sequence' => $sequence,
+ 'resource' => $resource,
+ 'Title' => $resource->{'title'},
+ 'Part' => $part,
+ '#Stdnts' => $num,
+ 'Tries' => $tries,
+ 'Mod' => $mod,
+ 'Mean' => $mean,
+ '#YES' => $Solved,
+ '#yes' => $solved,
+ '%Wrng' => $wrongpercent,
+ 'DoDiff' => $DegOfDiff,
+ 'S.D.' => $STD,
+ 'Skew' => $SKEW,
+ });
}
}
}
+ #
+ # Table Headers
+ $r->print(''."\n");
+ my $Str = '';
+ foreach (@Header) {
+ next if ($_ eq 'Part' && !$show_part);
+ # Do not allow sorting on some fields
+ if ($_ eq $sortby || /^(Part)$/) {
+ $Str .= ''.$_.' | ';
+ } else {
+ $Str .= ''.
+ ''.
+ $_.' | ';
+ }
+ }
+ $r->print(''.$Str." \n");
+ #
+ # Sort the data
+ my @OutputOrder;
+ if ($sortby eq 'Container') {
+ @OutputOrder = @Statsarray;
+ } else {
+ # $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;
+ }
+ }
+ foreach my $row (@OutputOrder) {
+ $r->print('');
+ if ($show_container) {
+ $r->print(''
+ .$row->{'sequence'}->{'title'}.' | ');
+ }
+ $r->print(&stats_row_from_hash($row,$show_part));
+ $r->print(" \n");
+ }
$r->print(" \n");
$r->print(" \n");
$r->rflush();
@@ -355,6 +425,17 @@ sub output_html_ungrouped {
return;
}
+sub stats_row_from_hash {
+ my ($data,$show_part) = @_;
+ return &statistics_html_table_data($data->{'resource'},$data->{'Part'},
+ $data->{'#Stdnts'}, $data->{'Tries'},
+ $data->{'Mod'}, $data->{'Mean'},
+ $data->{'#YES'}, $data->{'#yes'},
+ $data->{"\%Wrng"}, $data->{'DoDiff'},
+ $data->{'S.D.'}, $data->{'Skew'},
+ $show_part);
+}
+
###############################################
###############################################
@@ -362,13 +443,13 @@ sub output_html_ungrouped {
###############################################
sub statistics_html_table_data {
my ($resource,$part,$num,$tries,$mod,$mean,$Solved,$solved,$wrongpercent,
- $DegOfDiff,$STD,$SKEW) = @_;
+ $DegOfDiff,$STD,$SKEW,$show_part) = @_;
my $row = '';
$row .= ' | '.
''.
$resource->{'title'}.''.
' | ';
- $row .= ''.$part.' | ' if (defined($part));
+ $row .= ''.$part.' | ' if ($show_part);
foreach ($num,$tries) {
$row .= ''.$_.' | ';
}