--- loncom/interface/statistics/lonproblemstatistics.pm 2003/03/25 23:00:40 1.41
+++ loncom/interface/statistics/lonproblemstatistics.pm 2003/03/26 15:19:16 1.42
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonproblemstatistics.pm,v 1.41 2003/03/25 23:00:40 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.42 2003/03/26 15:19:16 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -286,16 +286,21 @@ sub output_html_grouped_by_sequence {
sub output_html_ungrouped {
my ($r) = @_;
#
- my $sortby = $ENV{'form.sortby'};
- if (! defined($sortby) || $sortby eq '') {
- $sortby = 'sequence';
- }
- #
my $show_container = 0;
#$r->print(&ProblemStatisticsLegend());
my @Header = ("Title","Part","#Stdnts","Tries","Mod",
"Mean","#YES","#yes","%Wrng","DoDiff",
"S.D.","Skew.");#,"D.F.1st","D.F.2nd");
+ #
+ my $sortby = undef;
+ foreach (@Header) {
+ if ($ENV{'form.sortby'} eq $_) {
+ $sortby = $_;
+ }
+ }
+ if (! defined($sortby) || $sortby eq '') {
+ $sortby = 'Container';
+ }
# #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
if (@Sequences > 1) {
@@ -307,14 +312,21 @@ sub output_html_ungrouped {
$r->print('
'."\n");
my $Str = '';
foreach (@Header) {
- $Str .= ''.
+ if (/^(Part)$/) { # Do not allow sorting on this field
+ $Str .= ' | '.$_.' | ';
+ } else {
+ $Str .= ''.
''.
- $_.' | ';
+ $_.'';
+ }
}
$r->print(''.$Str."
\n");
$r->rflush();
#
+ # Compile the data
+ my %Statshash;
+ my @Statsarray;
foreach my $sequence (@Sequences) {
next if ($sequence->{'num_assess'}<1);
foreach my $resource (@{$sequence->{'contents'}}) {
@@ -324,28 +336,93 @@ sub output_html_ungrouped {
$SKEW) = &Apache::loncoursedata::get_problem_statistics
(undef,$resource->{'symb'},$part,
$ENV{'request.course.id'});
- if ($part == 0) {
- $part = ' ';
- }
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");
+ my $key = $resource->{'symb'}.':'.$part;
+ $Statshash{$key} =
+ {
+ '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,
+ };
+ push (@Statsarray,$Statshash{$key});
+ }
+ }
+ }
+ #
+ # Sort the data
+ if ($sortby eq 'Container') {
+ 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'}}) {
+ my $key = $resource->{'symb'}.':'.$part;
+ $r->print('');
+ if ($show_container) {
+ $r->print(''
+ .$sequence->{'title'}.' | ');
+ }
+ $r->print(&stats_row_from_hash($Statshash{$key}));
+ $r->print("
\n");
+ }
+ }
+ }
+ } else {
+ # $sortby is already defined, so we can charge ahead
+ my @OutputOrder;
+ if ($sortby =~ /^(title|part)$/i) {
+ # Alpha comparison
+ @OutputOrder = sort {
+ $b->{$sortby} cmp $a->{$sortby} ||
+ $b->{'Title'} cmp $a->{'Title'} ||
+ $b->{'Part'} cmp $a->{'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} ||
+ $b->{'Title'} <=> $a->{'Title'} ||
+ $b->{'Part'} <=> $a->{'Part'};
}
+ $retvalue;
+ } @Statsarray;
+ }
+ foreach my $row (@OutputOrder) {
+ $r->print('');
+ if ($show_container) {
+ $r->print(''
+ .$row->{'sequence'}->{'title'}.' | ');
}
+ $r->print(&stats_row_from_hash($row));
+ $r->print("
\n");
}
}
$r->print("
\n");
@@ -355,6 +432,20 @@ sub output_html_ungrouped {
return;
}
+sub stats_row_from_hash {
+ my ($data) = @_;
+ if (ref($data) ne 'HASH') {
+ my %Tmp = @_;
+ $data = \%Tmp;
+ }
+ 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'});
+}
+
###############################################
###############################################