--- loncom/interface/statistics/lonproblemstatistics.pm 2003/03/26 15:19:16 1.42 +++ loncom/interface/statistics/lonproblemstatistics.pm 2003/03/26 16:26:35 1.43 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemstatistics.pm,v 1.42 2003/03/26 15:19:16 matthew Exp $ +# $Id: lonproblemstatistics.pm,v 1.43 2003/03/26 16:26:35 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -243,6 +243,7 @@ sub output_html_grouped_by_sequence { "S.D.","Skew.");#,"D.F.1st","D.F.2nd"); # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) { + my $show_part = 0; next if ($sequence->{'num_assess'}<1); $r->print("

".$sequence->{'title'}."

"); $r->print(''.&statistics_html_table_data ($resource,$part,$num,$tries,$mod,$mean,$Solved, - $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW). + $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW, + $show_part). "\n"); } } @@ -287,10 +290,11 @@ sub output_html_ungrouped { my ($r) = @_; # my $show_container = 0; + my $show_part = 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"); + "S.D.","Skew");#,"D.F.1st","D.F.2nd"); # my $sortby = undef; foreach (@Header) { @@ -309,23 +313,9 @@ sub output_html_ungrouped { } # $r->print('
'."\n"); @@ -252,20 +253,22 @@ sub output_html_grouped_by_sequence { foreach my $resource (@{$sequence->{'contents'}}) { next if ($resource->{'type'} ne 'assessment'); foreach my $part (@{$resource->{'parts'}}) { - if ($part == 0) { - $part = ' '; - } my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD, $SKEW) = &Apache::loncoursedata::get_problem_statistics (undef,$resource->{'symb'},$part, $ENV{'request.course.id'}); + # + $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; } $r->print('
'."\n"); - $r->print(''."\n"); - my $Str = ''; - foreach (@Header) { - 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); @@ -336,14 +326,16 @@ sub output_html_ungrouped { $SKEW) = &Apache::loncoursedata::get_problem_statistics (undef,$resource->{'symb'},$part, $ENV{'request.course.id'}); + # + $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; } - my $key = $resource->{'symb'}.':'.$part; - $Statshash{$key} = - { - 'sequence' => $sequence, + push (@Statsarray, + { 'sequence' => $sequence, 'resource' => $resource, 'Title' => $resource->{'title'}, 'Part' => $part, @@ -357,39 +349,40 @@ sub output_html_ungrouped { 'DoDiff' => $DegOfDiff, 'S.D.' => $STD, 'Skew' => $SKEW, - }; - push (@Statsarray,$Statshash{$key}); + }); } } } # + # 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') { - 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(''); - } - $r->print(&stats_row_from_hash($Statshash{$key})); - $r->print("\n"); - } - } - } + @OutputOrder = @Statsarray; } 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'}; + 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 @@ -409,21 +402,21 @@ sub output_html_ungrouped { } if ($retvalue eq '0') { $retvalue = $b->{$sortby} <=> $a->{$sortby} || - $b->{'Title'} <=> $a->{'Title'} || - $b->{'Part'} <=> $a->{'Part'}; + 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(''); - } - $r->print(&stats_row_from_hash($row)); - $r->print("\n"); + } + foreach my $row (@OutputOrder) { + $r->print(''); + if ($show_container) { + $r->print(''); } + $r->print(&stats_row_from_hash($row,$show_part)); + $r->print("\n"); } $r->print("
'.$_.''. + ''. + $_.'
' - .$sequence->{'title'}.'
' - .$row->{'sequence'}->{'title'}.'
' + .$row->{'sequence'}->{'title'}.'
\n"); $r->print("
\n"); @@ -433,17 +426,14 @@ sub output_html_ungrouped { } sub stats_row_from_hash { - my ($data) = @_; - if (ref($data) ne 'HASH') { - my %Tmp = @_; - $data = \%Tmp; - } + 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'}); + $data->{'S.D.'}, $data->{'Skew'}, + $show_part); } ############################################### @@ -453,13 +443,13 @@ sub stats_row_from_hash { ############################################### 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 .= ''.$_.''; }