'
+ .&mt('There are no students in the sections/groups selected.')
+ .'
'
+ );
}
#
my @CacheButtonHTML =
&Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
$r->rflush();
#
- # Support for numerical and radio response isn't complete enough to
- # include in 1.2 release.
- # my $problem_types = '(option|radiobutton|numerical)';
- my $problem_types = '.';#(option)';
- if (exists($ENV{'form.problemchoice'}) &&
- ! exists($ENV{'form.SelectAnother'})) {
+ my $problem_types = &analyzable_types();
+ if (exists($env{'form.problemchoice'}) &&
+ ! exists($env{'form.SelectAnother'})) {
foreach my $button (@SubmitButtons) {
if ($button->{'name'} eq 'break') {
$r->print(" \n");
@@ -102,82 +106,100 @@ sub BuildProblemAnalysisPage {
$r->print($html.(' 'x5));
}
#
+
+ # This is commented out pending actual implementation of
+ # CSV and Excel output.
+ #$r->print(&Apache::lonstathelpers::submission_report_form
+ # ('problem_analysis'));
+ #
$r->print('');
$r->rflush();
#
# Determine which problem we are to analyze
- my $current_problem = &Apache::lonstathelpers::get_target_from_id
- ($ENV{'form.problemchoice'});
- #
- my ($prev,$curr,$next) =
- &Apache::lonstathelpers::get_prev_curr_next($current_problem,
- $problem_types,
- 'response',
- );
- if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
- $current_problem = $prev;
- } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
- $current_problem = $next;
- } else {
- $current_problem = $curr;
- }
+ my ($navmap,$current_problem) = &get_current_problem(); # need to retrieve $navmap
+ # to support $resource->* calls
+ # for src and compTitle (below)
#
# Store the current problem choice and send it out in the form
- $ENV{'form.problemchoice'} =
+ $env{'form.problemchoice'} =
&Apache::lonstathelpers::make_target_id($current_problem);
$r->print('');
+ $env{'form.problemchoice'}.'" />');
#
if (! defined($current_problem->{'resource'})) {
$r->print('resource is undefined');
} else {
my $resource = $current_problem->{'resource'};
- $r->print('
';
+ $r->print($analysis_html);
#
- my $analysis_html;
- my $PerformanceData = &Apache::loncoursedata::get_response_data
- (\@Apache::lonstatistics::SelectedSections,
- $Apache::lonstatistics::enrollment_status,
- $resource->{'symb'},$respid);
- if (! defined($PerformanceData) ||
- ref($PerformanceData) ne 'ARRAY' ) {
- $analysis_html = '
'.
- &mt('There is no submission data for this resource').
- '
';
- $r->print($analysis_html);
- return;
+ return;
+}
+
+sub numerical_plot_percent {
+ my ($r,$responses,$stats) = @_;
+ #
+ my $total = $stats->{'submission_count'};
+ return '' if ($total == 0);
+ my $max_bins = 50;
+ my $lowest_percent = $stats->{'min_percent'};
+ my $highest_percent = $stats->{'max_percent'};
+ my $percent_spread = $highest_percent - $lowest_percent;
+ foreach (qw/20 30 40 50 100 200/) {
+ if ($percent_spread < $_) {
+ $highest_percent =$_/2;
+ last;
+ }
}
+ $percent_spread = $highest_percent - $lowest_percent;
+ my $bin_size = 1;
+ foreach (qw/0.01 0.05 0.1 0.5 1 2 5 10 20 25 50 100/) {
+ if ($lowest_percent/2 < $_){
+ $bin_size = $_;
+ if ( ($percent_spread/$bin_size) < $max_bins ) {
+ last;
+ }
+ }
+ }
+ my @bins;
+ for (my $bin = -$highest_percent;$bin<0;$bin+=$bin_size) {
+ push (@bins,$bin);
+ }
+ for (my $bin = 0; $bin<$highest_percent;$bin+=$bin_size) {
+ push (@bins,$bin);
+ }
+ push(@bins,$highest_percent);
#
- # This next call causes all the waiting around that people complain about
- &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students,
- 'Statistics',
- 'stats_status');
- return if ($c->aborted());
- #
- # Collate the data
- my %Data;
- foreach my $student (@$Students) {
- my $answer = $student->{'answer'};
- $Data{$answer}++;
- }
- my @Labels = sort {$a <=> $b } keys(%Data);
- my @PlotData = @Data{@Labels};
- #
- my $width = 500;
- my $height = 100;
- my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students),
- \@Labels,\@PlotData);
- $r->print($plot);
- return;
+ my @correct;
+ my @incorrect;
+ my @count;
+ while (my ($ans,$submissions) = each(%$responses)) {
+ while (my ($submission,$counts) = each(%$submissions)) {
+ my ($correct_count,$incorrect_count) = @$counts;
+ my $scaled_value =
+ ($ans) ? 100*($submission-$ans)/abs($ans)
+ : 0;
+ if ($scaled_value < $bins[0]) {
+ $bins[0]=$scaled_value -1;
+ }
+ my $bin;
+ for ($bin=0;$bin<$#bins;$bin++) {
+ last if ($bins[$bin]>$scaled_value);
+ }
+ $correct[$bin-1]+=$correct_count;
+ $incorrect[$bin-1]+=$incorrect_count;
+ $count[$bin-1]+=$correct_count+$incorrect_count;
+ }
+ }
+ #
+ my @plot_correct = @correct;
+ my @plot_incorrect = @incorrect;
+ my $max;
+ for (my $i=0;$i<$#bins;$i++) {
+ $plot_correct[$i] *= 100/$total;
+ $plot_incorrect[$i] *= 100/$total;
+ if (! defined($max) ||
+ $max < $plot_correct[$i]+$plot_incorrect[$i] ) {
+ $max = $plot_correct[$i]+$plot_incorrect[$i];
+ }
+ }
+ foreach (qw/1 5 10 15 20 25 30 40 50 75 100/) {
+ if ($max <$_) { $max = $_; last; }
+ }
+ #
+ my %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Percent Difference',
+ 'xlabel' => 'Percent Difference from Correct',
+ 'ylabel' => 'Percent of Answers');
+ my @labels = (1..scalar(@bins)-1);
+ my $graph = &Apache::loncommon::DrawBarGraph
+ ($lt{'title'},$lt{'xlabel'},$lt{'ylabel'},
+ $max,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
+ {xskip=>1});
+ #
+ my $table = $graph.$/.
+ &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
+ return $table;
}
-sub one_dimensional_plot {
- my ($r,$width,$height,$N,$Labels,$Data)=@_;
+sub numerical_plot_differences {
+ my ($r,$responses,$stats) = @_;
#
- # Compute data -> image scaling factors
- my $min = $Labels->[0];
- my $max = $Labels->[-1];
- if ($max == $min) {
- $max =$min+1;
+ my $total = $stats->{'submission_count'};
+ return '' if ($total == 0);
+ my $max_bins = 21;
+ my $min_bin_size = $stats->{'min_abs'};
+ my $low_bin = $stats->{'lowest_ans'}-$stats->{'max_bin_size'};
+ my $high_bin = $stats->{'highest_ans'}+$stats->{'max_bin_size'};
+ if ($high_bin > 0 && $low_bin > -$high_bin) {
+ $low_bin = -$high_bin;
+ } elsif ($low_bin < 0 && $high_bin < -$low_bin) {
+ $high_bin = -$low_bin;
+ }
+ if ($high_bin == $low_bin) {
+ $high_bin+=1;
+ $low_bin-=1;
+ }
+ if (!$min_bin_size ||
+ ($high_bin -$low_bin)/$min_bin_size * 2 > $max_bins) {
+ $min_bin_size = abs($high_bin - $low_bin) / $max_bins * 2;
+ }
+ my @bins;
+ for (my $num = $low_bin;$num <= $high_bin;$num+=($min_bin_size/2)) {
+ push(@bins,$num);
}
- my $h_scale = ($width-10)/($max-$min);
#
+ my @correct;
+ my @incorrect;
+ my @count;
+ while (my ($ans,$submissions) = each(%$responses)) {
+ while (my ($submission,$counts) = each(%$submissions)) {
+ my ($correct_count,$incorrect_count) = @$counts;
+ my $scaled_value = $submission-$ans;
+ if ($scaled_value < $bins[0]) {
+ $bins[0]=$scaled_value-1;
+ }
+ my $bin=0;
+ for ($bin=0;$bin<$#bins;$bin++) {
+ last if ($bins[$bin]>$scaled_value);
+ }
+ $correct[$bin-1]+=$correct_count;
+ $incorrect[$bin-1]+=$incorrect_count;
+ $count[$bin-1]+=$correct_count+$incorrect_count;
+ }
+ }
+ my @plot_correct = @correct;
+ my @plot_incorrect = @incorrect;
+ my $max;
+ for (my $i=0;$i<=$#bins;$i++) {
+ $plot_correct[$i] *= 100/$total;
+ $plot_incorrect[$i] *= 100/$total;
+ if (! defined($max) ||
+ $max < $plot_correct[$i]+$plot_incorrect[$i] ) {
+ $max = $plot_correct[$i]+$plot_incorrect[$i];
+ }
+ }
+ foreach (qw/1 5 10 15 20 25 30 40 50 75 100/) {
+ if ($max <$_) { $max = $_; last; }
+ }
+ #
+ my %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Difference between submission and correct',
+ 'xlabel' => 'Difference from Correct',
+ 'ylabel' => 'Percent of Answers');
+ my @labels = (1..scalar(@bins)-1);
+ my $graph = &Apache::loncommon::DrawBarGraph
+ ($lt{'title'},$lt{'xlabel'},$lt{'ylabel'},
+ $max,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
+ {xskip=>1});
+ #
+ my $table = $graph.$/.
+ &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
+ return $table;
+}
+
+sub numerical_classify_responses {
+ my ($full_row_data,$correct,$function) = @_;
+ my %submission_data;
+ my %students;
+ my %stats;
+ my $max=0;
+ foreach my $row (@$full_row_data) {
+ my %subm = &hashify_attempt($row);
+ if (ref($correct) eq 'HASH') {
+ my $s_correct = $correct->{$subm{'student'}};
+ $subm{'correct'} = $s_correct->{'answer'};
+ foreach my $item ('unit','ans_low','ans_high') {
+ $subm{$item} = $s_correct->{$item};
+ }
+ } else { # This probably never happens....
+ $subm{'correct'} = $correct->{'answer'};
+ $subm{'unit'} = $correct->{'unit'};
+ }
+ #
+ my $abs_low =abs($subm{'correct'}-$subm{'ans_low'});
+ my $abs_high=abs($subm{'correct'}-$subm{'ans_high'});
+ if (! defined($stats{'min_abs'}) ||
+ $stats{'min_abs'} > $abs_low) {
+ $stats{'min_abs'} = $abs_low;
+ }
+ if ($stats{'min_abs'} > $abs_high) {
+ $stats{'min_abs'} = $abs_high;
+ }
+ if (! defined($stats{'max_abs'}) ||
+ $stats{'max_abs'} < $abs_low) {
+ $stats{'max_abs'} = $abs_low;
+ }
+ if ($stats{'max_abs'} < $abs_high) {
+ $stats{'max_abs'} = $abs_high;
+ }
+ my $low_percent;
+ my $high_percent;
+ if (defined($subm{'correct'}) && $subm{'correct'} != 0) {
+ $low_percent = 100 * abs($abs_low / $subm{'correct'});
+ $high_percent = 100 * abs($abs_high / $subm{'correct'});
+ }
+ if (! defined($stats{'min_percent'}) ||
+ $stats{'min_percent'} > $low_percent) {
+ $stats{'min_percent'} = $low_percent;
+ }
+ if ($stats{'min_percent'} > $high_percent) {
+ $stats{'min_percent'} = $high_percent;
+ }
+ if (! defined($stats{'max_percent'}) ||
+ $stats{'max_percent'} < $low_percent) {
+ $stats{'max_percent'} = $low_percent;
+ }
+ if ($stats{'max_percent'} < $high_percent) {
+ $stats{'max_percent'} = $high_percent;
+ }
+ if (! defined($stats{'lowest_ans'}) ||
+ $stats{'lowest_ans'} > $subm{'correct'}) {
+ $stats{'lowest_ans'} = $subm{'correct'};
+ }
+ if (! defined($stats{'highest_ans'}) ||
+ $stats{'highest_ans'} < $subm{'correct'}) {
+ $stats{'highest_ans'} = $subm{'correct'};
+ }
+ #
+ $subm{'submission'} =~ s/=\d+\s*$//;
+ if (&$function(\%subm)) {
+ my $scaled = '1';
+ my ($sname,$sdom) = split(':',$subm{'student'});
+ my ($myunit,$mysub) = ($subm{'unit'},$subm{'submission'});
+ my $result =
+ &capa::caparesponse_get_real_response($myunit,
+ $mysub,
+ \$scaled);
+# &Apache::lonnet::logthis('scaled = '.$scaled.' result ='.$result);
+ next if (! defined($scaled));
+# next if ($result ne '6');
+ my $submission = $scaled;
+ $students{$subm{'student'}}++;
+ $stats{'submission_count'}++;
+ if (&numerical_submission_is_correct($subm{'award'})) {
+ $stats{'correct_count'}++;
+ $submission_data{$subm{'correct'}}->{$submission}->[0]++;
+ } elsif (&numerical_submission_is_incorrect($subm{'award'})) {
+ $stats{'incorrect_count'}++;
+ $submission_data{$subm{'correct'}}->{$submission}->[1]++;
+ }
+ }
+ }
+ $stats{'correct_count'} |= 0;
+ $stats{'incorrect_count'} |= 0;
+ $stats{'students'}=scalar(keys(%students));
+ return (\%submission_data,\%stats);
+}
+
+sub numerical_submission_is_correct {
+ my ($award) = @_;
+ if ($award =~ /^(APPROX_ANS|EXACT_ANS)$/) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub numerical_submission_is_incorrect {
+ my ($award) = @_;
+ if ($award =~ /^(INCORRECT)$/) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub numerical_bin_table {
+ my ($bins,$labels,$incorrect,$correct,$count)=@_;
+ my $table =
+ '
'.&mt('Bar').'
'.
+ '
'.&mt('Range').'
'.
+ '
'.&mt('Incorrect').'
'.
+ '
'.&mt('Correct').'
'.
+ '
'.&mt('Count').'
'.
+ '
'.$/;
+ for (my $i=0;$i[$i];
+ if ($i == 0) { $lownum = '-∞'; }
+ my $highnum = $bins->[$i+1];
+ if ($i == scalar(@{$bins})-2) { $highnum = '∞'; }
+ $table .=
+ '
'.
+ '
'.$labels->[$i].'
'.
+ '
'.$lownum.'
'.
+ '
-
'.
+ '
'.$highnum.'
'.
+ '
'.$incorrect->[$i].'
'.
+ '
'.$correct->[$i].'
'.
+ '
'.$count->[$i].'
'.
+ '
'.$/;
+ }
+ $table.= '
';
+ return $table;
+}
+
+sub numerical_determine_answers {
+ my ($r,$resource,$partid,$respid,$students)=@_;
+ my $c = $r->connection();
+ #
+ my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,scalar(@$students));
+ #
+ # Read in the cache (if it exists) before we start timing things.
+ &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'});
+ #
+ my $correct;
+ my %answers;
+ foreach my $student (@$students) {
+ last if ($c->aborted());
+ my $sname = $student->{'username'};
+ my $sdom = $student->{'domain'};
+ # analyze problem
+ my $analysis =
+ &Apache::lonstathelpers::analyze_problem_as_student($resource,
+ $sname,
+ $sdom);
+ # make the key
+ my $key = $partid.'.'.$respid;
+ # pick one of the possible answers
+ my $which = 'INTERNAL';
+ if (!exists($analysis->{$key}{$which})) {
+ $which = (sort(keys(%{ $analysis->{$key} })))[0];
+ }
+ foreach my $item ('answer','unit','ans_high','ans_low') {
+ if (ref($analysis->{$key.'.'.$item}) eq 'ARRAY') {
+ $correct->{$sname.':'.$sdom}->{$item} =
+ $analysis->{$key.'.'.$item}[0];
+ } else {
+ $correct->{$sname.':'.$sdom}->{$item} =
+ $analysis->{$key.'.'.$item}{$which}[0][0];
+ }
+ }
+ $answers{$correct->{$sname.':'.$sdom}{'answer'}}++;
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
+ 'last student');
+ }
+ &Apache::lonstathelpers::write_analysis_cache();
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ return ($correct,\%answers);
+}
+
+#
+# Inputs: $r, $width, $height, $data
+# $n = number of students
+# $data = hashref of $answer => $frequency pairs
+sub numerical_one_dimensional_plot {
+ my ($r,$width,$height,$data)=@_;
+ #
+ # Compute data -> image scaling factors
my $max_y = 0;
- foreach (@$Data) {
- $max_y = $_ if ($max_y < $_);
+ my $min_x = undef;
+ my $max_x = undef;
+ my $n = 0;
+ while (my ($answer,$count) = each(%$data)) {
+ $n+=$count;
+ $max_y = $count if ($max_y < $count);
+ if (! defined($min_x) || $answer < $min_x) {
+ $min_x = $answer;
+ }
+ if (! defined($max_x) || $answer > $max_x) {
+ $max_x = $answer;
+ }
+ }
+ #
+ my $min_max_difference = $max_x - $min_x;
+ if (! defined($min_max_difference) || $min_max_difference == 0) {
+ $min_max_difference = 1;
}
+ my $h_scale = ($width-10)/$min_max_difference;
+ #
my $ticscale = 5;
if ($max_y * $ticscale > $height/2) {
$ticscale = int($height/2/$max_y);
@@ -268,17 +723,16 @@ sub one_dimensional_plot {
# Create the plot
my $plot =
qq{};
- for (my $idx=0;$idx[$idx] - $min);
- my $top = $height/2-$Data->[$idx]*$ticscale;
- my $bottom = $height/2+$Data->[$idx]*$ticscale;
- $plot .=
- &line($xloc,$top,$xloc,$bottom,'888888',1);
+ while (my ($answer,$count) = each(%$data)) {
+ my $xloc = 5+$h_scale*($answer - $min_x);
+ my $top = $height/2-$count*$ticscale;
+ my $bottom = $height/2+$count*$ticscale;
+ $plot .= &line($xloc,$top,$xloc,$bottom,'888888',1);
}
#
# Put the scale on last to ensure it is on top of the data.
- if ($min < 0 && $max > 0) {
- my $circle_x = 5+$h_scale*abs($min); # '0' in data coordinates
+ if ($min_x < 0 && $max_x > 0) {
+ my $circle_x = 5+$h_scale*abs($min_x); # '0' in data coordinates
my $r = 4;
$plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
$plot .= &circle($circle_x,$height/2,$r+1,'000000');
@@ -288,21 +742,18 @@ sub one_dimensional_plot {
}
$plot .= '';
my $plotresult = &Apache::lonxml::xmlparse($r,'web',$plot);
-
- my $title = 'Distribution of correct answers';
my $result = '
'.
'
'.
- ''.$title.' (N='.$N.')'.
- ''.
+ ''.&mt('Distribution of correct answers').''.
+ ' '.&mt('[_1] students, [_2] distinct correct answers',
+ $n,scalar(keys(%$data))).
+ ' '.&mt('Maximum number of coinciding values: [_1]',$max_y).
'
'.
'
'.
- '
'.$min.'
'.
+ '
'.$min_x.'
'.
'
'.$plotresult.'
'.
- '
'.$max.'
'.
+ '
'.$max_x.'
'.
'
'.
- '
'.
- 'Maximum Number of Coinciding Values: '.$max_y.
- '
'.
'
';
return $result;
}
@@ -312,7 +763,7 @@ sub one_dimensional_plot {
## These should probably go somewhere more suitable soon.
sub line {
my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
- return qq{$/};
+ return qq{};
}
sub text {
@@ -341,33 +792,6 @@ sub circle {
return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
}
-sub build_student_data_worksheet {
- my ($workbook,$format) = @_;
- my $rows_output = 3;
- my $cols_output = 0;
- my $worksheet = $workbook->addworksheet('Student Data');
- $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
- my @Headers = ('full name','username','domain','section',
- "student\nnumber",'identifier');
- $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
- my @Students = @Apache::lonstatistics::Students;
- my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
- my %ids;
- foreach my $row (@$studentrows) {
- my ($mysqlid,$student) = @$row;
- $ids{$student}=$mysqlid;
- }
- foreach my $student (@Students) {
- my $name_domain = $student->{'username'}.':'.$student->{'domain'};
- $worksheet->write_row($rows_output++,0,
- [$student->{'fullname'},
- $student->{'username'},$student->{'domain'},
- $student->{'section'},$student->{'id'},
- $ids{$name_domain}]);
- }
- return $worksheet;
-}
-
#########################################################
#########################################################
##
@@ -375,53 +799,13 @@ sub build_student_data_worksheet {
##
#########################################################
#########################################################
-sub RadioResponseAnalysis {
+sub radio_response_analysis {
my ($r,$problem,$problem_analysis,$students) = @_;
- if ($ENV{'form.AnalyzeOver'} eq 'tries') {
- &RR_tries_analysis($r,$problem,$problem_analysis,$students);
- } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
- &RR_static_time_analysis($r,$problem,$problem_analysis,$students);
- } else {
+ #
+ if ($env{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
$r->print('Bad request');
}
- return;
-}
-
-sub RR_computed_tries_analysis {
- my ($r,$problem,$problem_analysis) = @_;
- my ($resource,$partid,$respid) = ($problem->{'resource'},
- $problem->{'part'},
- $problem->{'respid'});
- $r->print('The tries answer you seek must be computed');
- # Gather student data
- # for each try
- # loop through data, classifying it by
- # correct foil -> selected foil
- # if there is concept data
- # make a concept correct plot
- # for each correct foil
- # make a plot of the data
-}
-
-sub RR_computed_time_analysis {
- my ($r,$problem,$problem_analysis) = @_;
- my ($resource,$partid,$respid) = ($problem->{'resource'},
- $problem->{'part'},
- $problem->{'respid'});
- $r->print('The time answer you seek must be computed');
- # Gather student data
- # for time division
- # limit to between start time & end time
- # loop through data, classifying it by
- # correct foil -> selected foil
- # if there is concept data
- # make a concept correct plot
- # for each correct foil
- # make a plot of the data
-}
-
-sub RR_tries_analysis {
- my ($r,$problem,$problem_analysis,$students) = @_;
+ #
my ($resource,$partid,$respid) = ($problem->{'resource'},
$problem->{'part'},
$problem->{'respid'});
@@ -429,12 +813,28 @@ sub RR_tries_analysis {
my $analysis_html;
my $foildata = $problem_analysis->{'_Foils'};
my ($table,$foils,$concepts) = &build_foil_index($problem_analysis);
+ if (! defined($concepts)) {
+ $concepts = [];
+ }
+ #
+ my %true_foils;
+ my $num_true = 0;
+ if (! $problem_analysis->{'answercomputed'}) {
+ foreach my $foil (@$foils) {
+ if ($foildata->{$foil}->{'value'} eq 'true') {
+ $true_foils{$foil}++;
+ }
+ }
+ $num_true = scalar(keys(%true_foils));
+ }
+ #
$analysis_html .= $table;
# Gather student data
my $response_data = &Apache::loncoursedata::get_response_data
- (\@Apache::lonstatistics::SelectedSections,
+ ([&Apache::lonstatistics::get_selected_sections()],
+ [&Apache::lonstatistics::get_selected_groups()],
$Apache::lonstatistics::enrollment_status,
- $resource->{'symb'},$respid);
+ $resource->symb,$respid);
my $correct; # either a hash reference or a scalar
if ($problem_analysis->{'answercomputed'} || scalar(@$concepts) > 1) {
# This takes a while for large classes...
@@ -445,32 +845,79 @@ sub RR_tries_analysis {
my ($idx,@remainder) = split('&',$student->{'answer'});
my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/);
$correct->{$student->{'username'}.':'.$student->{'domain'}}=
- &Apache::lonnet::unescape($answer);
+ &unescape($answer);
}
} else {
foreach my $foil (keys(%$foildata)) {
if ($foildata->{$foil}->{'value'} eq 'true') {
$correct = $foildata->{$foil}->{'name'};
- last;
}
}
}
- if (! defined($response_data) ||
- ref($response_data) ne 'ARRAY' ) {
- $analysis_html = '
'.
- &mt('There is no submission data for this resource').
- '
';
+ #
+ if (! defined($response_data) || ref($response_data) ne 'ARRAY' ) {
+ $analysis_html = '
'
+ .&mt('There is no submission data for this resource.')
+ .'
'.$/;
}
- }
+ } # end of loop for plots
$analysis_html.='
';
$r->print($analysis_html);
}
+sub ensure_start_end_times {
+ my ($start,$end,$first,$last,$plot_num) = @_;
+ if (! defined($start) || ! defined($end)) {
+ my $sec_in_day = 86400;
+ my ($sday,$smon,$syear) =
+ (localtime($last - $sec_in_day*($plot_num-1)))[3..5];
+ $start = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
+ $end = $start + $sec_in_day;
+ if ($plot_num == $env{'form.NumPlots'}) {
+ $start = $first;
+ }
+ }
+ return ($start,$end);
+}
sub RR_concept_plot {
my ($concepts,$foil_data,$title) = @_;
@@ -532,7 +1028,6 @@ sub RR_concept_plot {
} else {
$incorrect_by_concept{$concept->{'name'}} +=
$foil_data->{$foil}->{$choice};
-
}
}
}
@@ -553,11 +1048,11 @@ sub RR_concept_plot {
for (my $i=0;$i<=$#correct;$i++) {
$correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
}
- my $xlabel = 'concept';
- $title.= ' (N='.$total.')';
+ my $xlabel = &mt('concept');
+ my $ylabel = &mt('Percent Choosing');
my $plot= &Apache::loncommon::DrawBarGraph($title,
$xlabel,
- 'Percent Choosing',
+ $ylabel,
100,
['#33ff00','#ff3300'],
undef,
@@ -565,18 +1060,21 @@ sub RR_concept_plot {
return $plot;
}
-
sub RR_create_percent_selected_plot {
- my ($foils,$foil_data,$title) = @_;
+ my ($concepts,$foils,$foil_data,$title) = @_;
#
- my %foil_selections;
- my %true;
+ if ($foil_data->{'_count'} == 0) { return ''; };
+ my %correct_selections;
+ my %incorrect_selections;
foreach my $foil (@$foils) {
- # foil_data has format $foil_data->{true_foil}->{selected foil}
+ # foil_data has format $foil_data->{true_foil}->{selected foil}=count
next if (! exists($foil_data->{$foil}));
- $true{$foil}++;
while (my ($f,$count)= each(%{$foil_data->{$foil}})) {
- $foil_selections{$f}+=$count;
+ if ($f eq $foil) {
+ $correct_selections{$foil} += $count;
+ } else {
+ $incorrect_selections{$f} += $count;
+ }
}
}
#
@@ -585,59 +1083,78 @@ sub RR_create_percent_selected_plot {
my @correct;
my @incorrect;
#
- my $total =0;
+ my $total = $foil_data->{'_count'};
for (my $i=0;$i[$i];
- if ($true{$foil}) {
- $correct[$i] = $foil_selections{$foil};
- $incorrect[$i] = 0;
- } else {
- $correct[$i] = 0;
- $incorrect[$i] = $foil_selections{$foil};
- }
- $total+=$foil_selections{$foil};
+ $correct[$i] = $correct_selections{$foil};
+ $incorrect[$i] = $incorrect_selections{$foil};
}
- if ($total == 0) { return ''; };
for (my $i=0;$i<=$#correct;$i++) {
- $correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
+ $correct[$i] = sprintf('%2f',$correct[$i]/$total*100);
}
for (my $i=0;$i<=$#incorrect;$i++) {
- $incorrect[$i] = sprintf('%0f',$incorrect[$i]/$total*100);
+ $incorrect[$i] = sprintf('%2f',$incorrect[$i]/$total*100);
}
- my $xlabel = 'foil chosen';
- $title.= ' (N='.$total.')';
+ #
+ # Put a blank in the data sets between concepts, if there are concepts
+ my @labels;
+ if (defined($concepts) && scalar(@$concepts) > 1) {
+ my @new_correct;
+ my @new_incorrect;
+ my $foil_count = 0;
+ foreach my $concept (@$concepts) {
+ foreach (@{$concept->{'foils'}}) {
+ push(@new_correct, $correct[$foil_count]);
+ push(@new_incorrect,$incorrect[$foil_count]);
+ push(@labels,++$foil_count);
+ }
+ push(@new_correct,'');
+ push(@new_incorrect,'');
+ push(@labels,'');
+ }
+ @correct = @new_correct;
+ @incorrect = @new_incorrect;
+ } else {
+ @labels = (1 .. scalar(@correct));
+ }
+ #
+ my $xlabel = &mt('foil chosen');
+ my $ylabel = &mt('Percent Choosing');
my $plot= &Apache::loncommon::DrawBarGraph($title,
$xlabel,
- 'Percent Choosing',
+ $ylabel,
100,
['#33ff00','#ff3300'],
- undef,
+ \@labels,
\@correct,
\@incorrect);
return $plot;
}
-
sub RR_create_stacked_selection_plot {
- my ($foils,$foil_data,$title)=@_;
+ my ($foils,$foil_data,$title,$true_foils)=@_;
#
- my @correct_choice; # the green row
- my @dataset; # array of array refs - multicolor rows.
- my %filled;
+ my @dataset; # array of array refs - multicolor rows $datasets[row]->[col]
my @labels;
- my $count=-1;
- my %column;
+ my $count;
+ my %column; # maps foil name to column in @datasets
for (my $i=0;$i[$i];
+ if (defined($true_foils) && scalar(keys(%$true_foils)) > 0 ) {
+ next if (! $true_foils->{$foil} );
+ push(@labels,$i+1);
+ } else {
+ next if (! exists($foil_data->{$foil}));
+ push(@labels,$i+1);
+ }
next if (! exists($foil_data->{$foils->[$i]}));
- my $correct_foil = $foils->[$i];
- push(@labels,$i+1);
- $column{$correct_foil}= ++$count;
+ $column{$foil}= $count++;
for (my $j=0;$j{$correct_foil}->{$foils->[$j]};
+ $value += $foil_data->{$foil}->{$foils->[$j]};
}
- $dataset[$j]->[$column{$correct_foil}]=$value;
+ $dataset[$j]->[$column{$foil}]=$value;
}
}
#
@@ -655,7 +1172,7 @@ sub RR_create_stacked_selection_plot {
$dataset[$j]->[$bar] =
sprintf('%2f',$dataset[$j]->[$bar]/$bar_total * 100);
}
- $count_per_foil{$foil}=' (N='.$bar_total.')';
+ $count_per_foil{$foil}=' ( '.$bar_total.' )';
$grand_total += $bar_total;
}
if ($grand_total == 0) {
@@ -666,19 +1183,30 @@ sub RR_create_stacked_selection_plot {
push(@empty_row,0);
}
#
- $title .= ' (N='.$grand_total.')';
+ my $xlabel = &mt('Correct Foil');
+ my $ylabel = &mt('foils chosen Incorrectly');
my $graph = &Apache::loncommon::DrawBarGraph
- ($title,'Correct Foil','foils chosen Incorrectly',
+ ($title,$xlabel,$ylabel,
100,$plotcolors,\@labels,\@empty_row,@dataset);
return ($graph,\%count_per_foil);
}
+#########################################################
+#########################################################
+##
+## Misc routines
+##
+#########################################################
+#########################################################
+
# if $correct is a hash ref, it is assumed to be indexed by student names.
# the values are assumed to be hash refs with a key of 'answer'.
-sub RR_classify_response_data {
+sub classify_response_data {
my ($full_row_data,$correct,$function) = @_;
my %submission_data;
+ my %students;
+ my $max=0;
foreach my $row (@$full_row_data) {
my %subm = &hashify_attempt($row);
if (ref($correct) eq 'HASH') {
@@ -688,199 +1216,22 @@ sub RR_classify_response_data {
}
$subm{'submission'} =~ s/=\d+\s*$//;
if (&$function(\%subm)) {
- $submission_data{$subm{'correct'}}->{$subm{'submission'}}++;
- }
- }
- return \%submission_data;
-}
-
-sub RR_static_time_analysis {
- my ($r,$problem,$problem_analysis) = @_;
- my ($resource,$partid,$respid) = ($problem->{'resource'},
- $problem->{'part'},
- $problem->{'respid'});
- $r->print('
The time answer you seek is static
');
- my $analysis_html;
- # Gather student data
- my $response_data = &Apache::loncoursedata::get_response_data
- (\@Apache::lonstatistics::SelectedSections,
- $Apache::lonstatistics::enrollment_status,
- $resource->{'symb'},$respid);
- if (! defined($response_data) ||
- ref($response_data) ne 'ARRAY' ) {
- $analysis_html = '
'.
- &mt('There is no submission data for this resource').
- '
';
- $r->print($analysis_html);
- return;
- }
- # for time division
-
- # limit to between start time & end time
- # loop through data, classifying it by
- # correct foil -> selected foil
- # if there is concept data
- # make a concept correct plot
- # for each correct foil
- # make a plot of the data
-
-}
-
-
-=pod
-
-
- } elsif ($ENV{'form.AnalyzeOver'} eq 'tries') {
- $analysis_html .= &RR_tries_Analysis($r,$problem->{'resource'},
- $PerformanceData,$problem_data);
- } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
- $analysis_html .= &RR_time_Analysis($r,$problem->{'resource'},
- $PerformanceData,$problem_data);
- } else {
- $analysis_html .= '
'.
- &mt('The analysis you have selected is not supported at this time').
- '
'.
- &mt('The analysis you have selected is '.
- 'not supported at this time').
- '
');
- }
+ $r->print('
'
+ );
}
}
}
@@ -941,8 +1286,11 @@ sub OptionResponseAnalysis {
sub OR_tries_analysis {
my ($r,$PerformanceData,$ORdata) = @_;
my $mintries = 1;
- my $maxtries = $ENV{'form.NumPlots'};
+ my $maxtries = $env{'form.NumPlots'};
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
+ if (! defined($Concepts)) {
+ $Concepts = [];
+ }
my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
$mintries,$maxtries);
my $analysis = '';
@@ -993,7 +1341,7 @@ sub OR_tries_analysis {
} # End of concept loops
#
# Build a table for the plots
- my $analysis_html = "
\n";
+ my $analysis_html = "
\n";
my $optionkey = &build_option_index($ORdata);
my $num_concepts = 1;
if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
@@ -1002,12 +1350,18 @@ sub OR_tries_analysis {
if (! defined($response_data{'_total'}->[$try]) ||
$response_data{'_total'}->[$try] == 0) {
if ($try > 1) {
- $analysis_html.= '
'.
- &mt('None of the selected students attempted the problem more than [_1] times.',$try-1).
- '
';
+ $analysis_html.= '
'
+ .'
'
+ .&mt('None of the selected students attempted the problem more than [quant,_1,time].'
+ ,$try-1)
+ .'
'
+ .'
';
} else {
- $analysis_html.= '
'.
- &mt('None of the selected students have attempted the problem').'
';
+ $analysis_html.= '
'
+ .'
'
+ .&mt('None of the selected students have attempted the problem.')
+ .'