'."\n");
- $r->rflush();
+ my $title; my $yaxis;
+ foreach my $field (@Fields) {
+ next if ($field->{'name'} ne $datafield);
+ $title = $field->{'long_title'};
+ $yaxis = $field->{'title'};
+ last;
+ }
+ if ($title eq '' || $yaxis eq '') {
+ # datafield is something we do not know enough about to plot
+ $r->print(''.
+ &mt('Unable to plot the requested statistic.').
+ '');
+ return;
+ }
#
- # Compile the data
- my @Statsarray;
- 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 ($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;
- }
- 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,
- });
- }
+ # Build up the data sets to plot
+ my @Labels;
+ my @Data;
+ my $max = 1;
+ foreach my $data (@StatsArray) {
+ push(@Labels,$data->{'problem_num'});
+ push(@Data,$data->{$datafield});
+ if ($data->{$datafield}>$max) {
+ $max = $data->{$datafield};
}
}
+ foreach (1,2,3,4,5,10,15,20,25,40,50,75,100,150,200,250,300,500,600,750,
+ 1000,1500,2000,2500,3000,3500,4000,5000,7500,10000,15000,20000) {
+ if ($max <= $_) {
+ $max = $_;
+ last;
+ }
+ }
+ if ($max > 20000) {
+ $max = 10000*(int($max/10000)+1);
+ }
#
- # 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 .= ''.$_.' | ';
+ $r->print("".&Apache::loncommon::DrawBarGraph($title,
+ 'Problem Number',
+ $yaxis,
+ $max,
+ undef, # colors
+ \@Labels,
+ \@Data)." \n");
+ return;
+}
+
+sub degrees_plot {
+ my ($r)=@_;
+ my $count = scalar(@StatsArray);
+ my $width = 50 + 10*$count;
+ $width = 300 if ($width < 300);
+ my $height = 300;
+ my $plot = '';
+ my $ymax = 0;
+ my $ymin = 0;
+ my @Disc; my @Diff; my @Labels;
+ foreach my $data (@StatsArray) {
+ push(@Labels,$data->{'problem_num'});
+ my $disc = $data->{'deg_of_disc'};
+ my $diff = $data->{'deg_of_diff'};
+ push(@Disc,$disc);
+ push(@Diff,$diff);
+ #
+ $ymin = $disc if ($ymin > $disc);
+ $ymin = $diff if ($ymin > $diff);
+ $ymax = $disc if ($ymax < $disc);
+ $ymax = $diff if ($ymax < $diff);
+ }
+ #
+ # Make sure we show relevant information.
+ if ($ymin < 0) {
+ if (abs($ymin) < 0.05) {
+ $ymin = 0;
+ } else {
+ $ymin = -1;
+ }
+ }
+ if ($ymax > 0) {
+ if (abs($ymax) < 0.05) {
+ $ymax = 0;
} else {
- $Str .= ''.
- ''.
- $_.' | ';
+ $ymax = 1;
}
}
- $r->print(''.$Str." \n");
#
- # Sort the data
- my @OutputOrder;
- if ($sortby eq 'Container') {
- @OutputOrder = @Statsarray;
+ my $xmax = $Labels[-1];
+ if ($xmax > 50) {
+ if ($xmax % 10 != 0) {
+ $xmax = 10 * (int($xmax/10)+1);
+ }
} 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;
+ if ($xmax % 5 != 0) {
+ $xmax = 5 * (int($xmax/5)+1);
}
}
- foreach my $row (@OutputOrder) {
- $r->print('');
- if ($show_container) {
- $r->print(''
- .$row->{'sequence'}->{'title'}.' | ');
+ #
+ my $discdata .= ''.join(',',@Labels).''.$/.
+ ''.join(',',@Disc).''.$/;
+ #
+ my $diffdata .= ''.join(',',@Labels).''.$/.
+ ''.join(',',@Diff).''.$/;
+ #
+ my $title = 'Degree of Discrimination\nand Degree of Difficulty';
+ if ($xmax > 50) {
+ $title = 'Degree of Discrimination and Degree of Difficulty';
+ }
+ #
+ $plot=<<"END";
+
+
+ $title
+
+ Problem Number
+
+ $discdata
+
+
+ $diffdata
+
+
+END
+ my $plotresult =
+ ''.&Apache::lonxml::xmlparse($r,'web',$plot).' '.$/;
+ $r->print($plotresult);
+ return;
+}
+
+sub tries_data_plot {
+ my ($r)=@_;
+ my $count = scalar(@StatsArray);
+ my $width = 50 + 10*$count;
+ $width = 300 if ($width < 300);
+ my $height = 300;
+ my $plot = '';
+ my @STD; my @Mean; my @Max; my @Min;
+ my @Labels;
+ my $ymax = 5;
+ foreach my $data (@StatsArray) {
+ my $max = $data->{'mean_tries'} + $data->{'std_tries'};
+ $ymax = $max if ($ymax < $max);
+ $ymax = $max if ($ymax < $max);
+ push(@Labels,$data->{'problem_num'});
+ push(@STD,$data->{'std_tries'});
+ push(@Mean,$data->{'mean_tries'});
+ }
+ #
+ # Make sure we show relevant information.
+ my $xmax = $Labels[-1];
+ if ($xmax > 50) {
+ if ($xmax % 10 != 0) {
+ $xmax = 10 * (int($xmax/10)+1);
+ }
+ } else {
+ if ($xmax % 5 != 0) {
+ $xmax = 5 * (int($xmax/5)+1);
}
- $r->print(&stats_row_from_hash($row,$show_part));
- $r->print(" \n");
}
- $r->print(" \n");
- $r->print(" |