');
+ }
+ #
my $analysis_html;
- my $PerformanceData =
- &Apache::loncoursedata::get_response_data
- ($Students,$resource->{'symb'},$respid);
+ 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 = '
'.
@@ -207,66 +220,125 @@ sub NumericalResponseAnalysis {
$r->print($analysis_html);
return;
}
- my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
- $r->print('Maximum = '.$max.' Minimum = '.$min);
- my $max_students = 0;
+ #
+ # 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}++;
- if ($max_students < $Data{$answer}) {
- $max_students = $Data{$answer};
- }
- }
- foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) {
- if ($max_students < $_) {
- $max_students = $_;
- last;
- }
}
my @Labels = sort {$a <=> $b } keys(%Data);
- $r->print('number of labels = '.scalar(@Labels));
my @PlotData = @Data{@Labels};
- $r->print('number of PlotData = '.scalar(@PlotData));
- my $graph =
- &Apache::loncommon::DrawXYGraph('Correct Answer Distribution',
- 'Correct Answer',
- 'Number of students',
- $max_students,
- undef,
- \@Labels,
- [\@PlotData],
- (xskip=>10));
- $r->print($graph);
+ #
+ my $width = 500;
+ my $height = 100;
+ my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students),
+ \@Labels,\@PlotData);
+ $r->print($plot);
return;
}
-sub GetStudentAnswers {
- my ($r,$problem,$Students) = @_;
- my %Answers;
- my ($resource,$partid,$respid) = ($problem->{'resource'},
- $problem->{'part'},
- $problem->{'respid'});
- # Open progress window
- my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
- ($r,'Student Answer Compilation Status',
- 'Student Answer Compilation Progress', scalar(@$Students));
- $r->print("
\n");
- $r->rflush();
- foreach my $student (@$Students) {
- my $sname = $student->{'username'};
- my $sdom = $student->{'domain'};
- my $answer = &Apache::lonstathelpers::analyze_problem_as_student
- ($resource,$sname,$sdom,$partid,$respid);
- &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
- &mt('last student'));
- $student->{'answer'} = $answer;
+sub one_dimensional_plot {
+ my ($r,$width,$height,$N,$Labels,$Data)=@_;
+ #
+ # Compute data -> image scaling factors
+ my $min = $Labels->[0];
+ my $max = $Labels->[-1];
+ if ($max == $min) {
+ $max =$min+1;
+ }
+ my $h_scale = ($width-10)/($max-$min);
+ #
+ my $max_y = 0;
+ foreach (@$Data) {
+ $max_y = $_ if ($max_y < $_);
+ }
+ my $ticscale = 5;
+ if ($max_y * $ticscale > $height/2) {
+ $ticscale = int($height/2/$max_y);
+ $ticscale = 1 if ($ticscale < 1);
}
- $r->print("
\n");
- $r->rflush();
- # close progress window
- &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
- return;
+ #
+ # 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);
+ }
+ #
+ # 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
+ my $r = 4;
+ $plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
+ $plot .= &circle($circle_x,$height/2,$r+1,'000000');
+ $plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1);
+ } else {
+ $plot .= &line(5,$height/2,$width-5,$height/2,'000000',1);
+ }
+ $plot .= '';
+ my $plotresult = &Apache::lonxml::xmlparse($r,'web',$plot);
+
+ my $title = 'Distribution of correct answers';
+ my $result = '
'.
+ '
'.
+ ''.$title.' (N='.$N.')'.
+ ''.
+ '
'.
+ '
'.
+ '
'.$min.'
'.
+ '
'.$plotresult.'
'.
+ '
'.$max.'
'.
+ '
'.
+ '
'.
+ 'Maximum Number of Coinciding Values: '.$max_y.
+ '
'.
+ '
';
+ return $result;
+}
+
+##
+## Helper subroutines for .
+## These should probably go somewhere more suitable soon.
+sub line {
+ my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
+ return qq{$/};
+}
+
+sub text {
+ my ($x,$y,$color,$text,$font,$direction) = @_;
+ if (! defined($font) || $font !~ /^(tiny|small|medium|large|giant)$/) {
+ $font = 'medium';
+ }
+ if (! defined($direction) || $direction ne 'vertical') {
+ $direction = '';
+ }
+ return qq{$text};
+}
+
+sub rectangle {
+ my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
+ return qq{};
+}
+
+sub arc {
+ my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
+ return qq{};
+}
+
+sub circle {
+ my ($x,$y,$radius,$color,$thickness,$filled)=@_;
+ return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
}
sub build_student_data_worksheet {
@@ -304,68 +376,395 @@ sub build_student_data_worksheet {
#########################################################
#########################################################
sub RadioResponseAnalysis {
- my ($r,$problem,$ProblemData,$Students) = @_;
- my ($resource,$respid) = ($problem->{'resource'},
- $problem->{'respid'});
+ 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 {
+ $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'});
+ #
my $analysis_html;
- my $PerformanceData =
- &Apache::loncoursedata::get_response_data
- ($Students,$resource->{'symb'},$respid);
- if (! defined($PerformanceData) ||
- ref($PerformanceData) ne 'ARRAY' ) {
+ my $foildata = $problem_analysis->{'_Foils'};
+ my ($table,$foils,$concepts) = &build_foil_index($problem_analysis);
+ $analysis_html .= $table;
+ # Gather student data
+ my $response_data = &Apache::loncoursedata::get_response_data
+ (\@Apache::lonstatistics::SelectedSections,
+ $Apache::lonstatistics::enrollment_status,
+ $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...
+ &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$students,
+ 'Statistics',
+ 'stats_status');
+ foreach my $student (@$students) {
+ my ($idx,@remainder) = split('&',$student->{'answer'});
+ my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/);
+ $correct->{$student->{'username'}.':'.$student->{'domain'}}=
+ &Apache::lonnet::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').
'
';
+ for (my $try = 1;$try<=$ENV{'form.NumPlots'};$try++) {
+ # classify data ->correct foil -> selected foil
+ my $attempt_restriction_function =
+ my $foil_choice_data =
+ &RR_classify_response_data($response_data,$correct,
+ sub {($_[0]->{'tries'} == $try?1:0)});
+ my $answers;
+ if (ref($correct)) {
+ my %tmp;
+ foreach my $foil (values(%$correct)) {
+ $tmp{$foil}++;
+ }
+ $answers = [keys(%tmp)];
+ } else {
+ $answers = [$correct];
+ }
+ # Concept Plot
+ my $concept_plot = '';
+ if (scalar(@$concepts) > 1) {
+ $concept_plot = &RR_concept_plot($concepts,$foil_choice_data,
+ '% choosing');
+ }
+ # % Choosing plot
+ my $choice_plot = &RR_create_percent_selected_plot
+ ($foils,$foil_choice_data,'Attempt '.$try);
+ # for each correct foil, how did they mark it? (stacked bar graph)
+ my ($stacked_plot,$count_by_foil) =
+ &RR_create_stacked_selection_plot($foils,$foil_choice_data,'');
+ #
+ if ($concept_plot ne '' ||
+ $choice_plot ne '' ||
+ $stacked_plot ne '') {
+ $analysis_html.=
+ '
'.
+ '
'.$concept_plot.'
'.
+ '
'.$choice_plot.'
';
+ if ($stacked_plot ne '') {
+ $analysis_html .=
+ '
'.$stacked_plot.'
'.
+ '
'.&build_foil_key($foils,$count_by_foil).'
';
+ } else {
+ $analysis_html .= ('
'x2);
+ }
+ $analysis_html.='
'.$/;
+ }
+ }
+ $analysis_html.='
';
+ $r->print($analysis_html);
+}
+
+
+sub RR_concept_plot {
+ my ($concepts,$foil_data,$title) = @_;
+ #
+ my %correct_by_concept;
+ my %incorrect_by_concept;
+ my %true;
+ foreach my $concept (@$concepts) {
+ foreach my $foil (@{$concept->{'foils'}}) {
+ next if (! exists($foil_data->{$foil}));
+ foreach my $choice (keys(%{$foil_data->{$foil}})) {
+ if ($choice eq $foil) {
+ $correct_by_concept{$concept->{'name'}} +=
+ $foil_data->{$foil}->{$choice};
+ } else {
+ $incorrect_by_concept{$concept->{'name'}} +=
+ $foil_data->{$foil}->{$choice};
+
+ }
+ }
+ }
+ }
+ #
+ # need arrays for incorrect and correct because we want to use different
+ # colors for them
+ my @correct;
+ #
+ my $total =0;
+ for (my $i=0;$i[$i];
+ $correct[$i] = $correct_by_concept{$concept->{'name'}};
+ $total += $correct_by_concept{$concept->{'name'}}+
+ $incorrect_by_concept{$concept->{'name'}};
+ }
+ if ($total == 0) { return ''; };
+ for (my $i=0;$i<=$#correct;$i++) {
+ $correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
+ }
+ my $xlabel = 'concept';
+ $title.= ' (N='.$total.')';
+ my $plot= &Apache::loncommon::DrawBarGraph($title,
+ $xlabel,
+ 'Percent Choosing',
+ 100,
+ ['#33ff00','#ff3300'],
+ undef,
+ \@correct);
+ return $plot;
+}
+
+
+sub RR_create_percent_selected_plot {
+ my ($foils,$foil_data,$title) = @_;
+ #
+ my %foil_selections;
+ my %true;
+ foreach my $foil (@$foils) {
+ # foil_data has format $foil_data->{true_foil}->{selected foil}
+ next if (! exists($foil_data->{$foil}));
+ $true{$foil}++;
+ while (my ($f,$count)= each(%{$foil_data->{$foil}})) {
+ $foil_selections{$f}+=$count;
+ }
+ }
+ #
+ # need arrays for incorrect and correct because we want to use different
+ # colors for them
+ my @correct;
+ my @incorrect;
+ #
+ my $total =0;
+ 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};
+ }
+ if ($total == 0) { return ''; };
+ for (my $i=0;$i<=$#correct;$i++) {
+ $correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
+ }
+ for (my $i=0;$i<=$#incorrect;$i++) {
+ $incorrect[$i] = sprintf('%0f',$incorrect[$i]/$total*100);
+ }
+ my $xlabel = 'foil chosen';
+ $title.= ' (N='.$total.')';
+ my $plot= &Apache::loncommon::DrawBarGraph($title,
+ $xlabel,
+ 'Percent Choosing',
+ 100,
+ ['#33ff00','#ff3300'],
+ undef,
+ \@correct,
+ \@incorrect);
+ return $plot;
+}
+
+
+sub RR_create_stacked_selection_plot {
+ my ($foils,$foil_data,$title)=@_;
+ #
+ my @correct_choice; # the green row
+ my @dataset; # array of array refs - multicolor rows.
+ my %filled;
+ my @labels;
+ my $count=-1;
+ my %column;
+ for (my $i=0;$i{$foils->[$i]}));
+ my $correct_foil = $foils->[$i];
+ push(@labels,$i+1);
+ $column{$correct_foil}= ++$count;
+ for (my $j=0;$j{$correct_foil}->{$foils->[$j]};
+ }
+ $dataset[$j]->[$column{$correct_foil}]=$value;
+ }
+ }
+ #
+ return '' if (! scalar(keys(%column)));
+ #
+ my $grand_total = 0;
+ my %count_per_foil;
+ while (my ($foil,$bar) = each (%column)) {
+ my $bar_total = 0;
+ for (my $j=0;$j[$bar];
+ }
+ next if ($bar_total == 0);
+ for (my $j=0;$j[$bar] =
+ sprintf('%2f',$dataset[$j]->[$bar]/$bar_total * 100);
+ }
+ $count_per_foil{$foil}=' (N='.$bar_total.')';
+ $grand_total += $bar_total;
+ }
+ if ($grand_total == 0) {
+ return ('',undef);
+ }
+ my @empty_row = ();
+ foreach (@{$dataset[0]}) {
+ push(@empty_row,0);
+ }
+ #
+ $title .= ' (N='.$grand_total.')';
+ my $graph = &Apache::loncommon::DrawBarGraph
+ ($title,'Correct Foil','foils chosen Incorrectly',
+ 100,$plotcolors,\@labels,\@empty_row,@dataset);
+ return ($graph,\%count_per_foil);
+}
+
+
+# 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 {
+ my ($full_row_data,$correct,$function) = @_;
+ my %submission_data;
+ foreach my $row (@$full_row_data) {
+ my %subm = &hashify_attempt($row);
+ if (ref($correct) eq 'HASH') {
+ $subm{'correct'} = $correct->{$subm{'student'}};
+ } else {
+ $subm{'correct'} = $correct;
+ }
+ $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').
- '
';
+ '';
}
$r->print($analysis_html);
}
sub RR_Excel_output {
- my ($r,$PerformanceData,$ProblemData) = @_;
+ my ($r,$PerformanceData,$problem_data) = @_;
return '
No!
';
}
-sub RR_Tries_Analysis {
- my ($r,$resource,$PerformanceData,$ProblemData) = @_;
+sub RR_tries_Analysis {
+ my ($r,$resource,$PerformanceData,$problem_data) = @_;
my $analysis_html;
my $mintries = 1;
my $maxtries = $ENV{'form.NumPlots'};
- my ($table,$Foils,$Concepts) = &build_foil_index($ProblemData);
- if ((! defined($Concepts)) || ((@$Concepts < 2) &&
- ($ENV{'form.AnalyzeAs'} ne 'Foils'))) {
+ my ($table,$Foils,$Concepts) = &build_foil_index($problem_data);
+ if ((! defined($Concepts)) || (@$Concepts < 2)) {
$table = '
'.
&mt('Not enough data for concept analysis. '.
'Performing Foil Analysis').
'
'.$table;
- $ENV{'form.AnalyzeAs'} = 'Foils';
}
$analysis_html .= $table;
my @TryData = &RR_tries_data_analysis($r,$PerformanceData);
-# if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
- $analysis_html .= &RR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,
- \@TryData,$ProblemData);
-# } else {
-# $analysis_html = &RR_Tries_Concept_Analysis($mintries,$maxtries,
-# $Concepts,
-# \@TryData,
-# $ProblemData);
-# }
+ $analysis_html .= &RR_tries_Foil_Analysis($mintries,$maxtries,$Foils,
+ \@TryData,$problem_data);
return $analysis_html;
}
@@ -380,14 +779,14 @@ sub RR_tries_data_analysis {
return @TryData;
}
-sub RR_Time_Analysis {
- my ($r,$PerformanceData,$ProblemData) = @_;
+sub RR_time_Analysis {
+ my ($r,$PerformanceData,$problem_data) = @_;
my $html;
return $html;
}
-sub RR_Tries_Foil_Analysis {
- my ($min,$max,$Foils,$TryData,$ProblemData) = @_;
+sub RR_tries_Foil_Analysis {
+ my ($min,$max,$Foils,$TryData,$problem_data) = @_;
my $html;
#
# Compute the data neccessary to make the plots
@@ -406,7 +805,7 @@ sub RR_Tries_Foil_Analysis {
push (@PlotData_Correct,0);
push (@PlotData_Incorrect,0);
} else {
- if ($ProblemData->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
+ if ($problem_data->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
push (@PlotData_Correct,
int(100*$DataSet{$foilid}/$total));
push (@PlotData_Incorrect,0);
@@ -417,8 +816,8 @@ sub RR_Tries_Foil_Analysis {
}
}
}
- my $title='Attempt '.$try;
- my $xlabel = $total.' Submissions';
+ my $title='Attempt '.$try.' (N='.$total.')';
+ my $xlabel = 'Foil Chosen';
$html.= &Apache::loncommon::DrawBarGraph($title,
$xlabel,
'Percent Choosing',
@@ -431,20 +830,20 @@ sub RR_Tries_Foil_Analysis {
return $html;
}
-sub RR_Tries_Concept_Analysis {
- my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
+sub RR_tries_Concept_Analysis {
+ my ($min,$max,$Concepts,$ResponseData,$problem_data) = @_;
my $html;
return $html;
}
-sub RR_Time_Foil_Analysis {
- my ($min,$max,$Foils,$ResponseData,$ProblemData) = @_;
+sub RR_time_Foil_Analysis {
+ my ($min,$max,$Foils,$ResponseData,$problem_data) = @_;
my $html;
return $html;
}
-sub RR_Time_Concept_Analysis {
- my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
+sub RR_time_Concept_Analysis {
+ my ($min,$max,$Concepts,$ResponseData,$problem_data) = @_;
my $html;
return $html;
}
@@ -481,6 +880,8 @@ sub get_Radio_problem_data {
return %Partdata;
}
+=cut
+
#########################################################
#########################################################
##
@@ -489,13 +890,14 @@ sub get_Radio_problem_data {
#########################################################
#########################################################
sub OptionResponseAnalysis {
- my ($r,$problem,$ProblemData,$Students) = @_;
+ my ($r,$problem,$problem_data,$Students) = @_;
my ($resource,$respid) = ($problem->{'resource'},
$problem->{'respid'});
# Note: part data is not needed.
- my $PerformanceData =
- &Apache::loncoursedata::get_response_data
- ($Students,$resource->{'symb'},$respid);
+ my $PerformanceData = &Apache::loncoursedata::get_response_data
+ (\@Apache::lonstatistics::SelectedSections,
+ $Apache::lonstatistics::enrollment_status,
+ $resource->{'symb'},$respid);
if (! defined($PerformanceData) ||
ref($PerformanceData) ne 'ARRAY' ) {
$r->print('
'.
@@ -506,19 +908,19 @@ sub OptionResponseAnalysis {
if (exists($ENV{'form.ExcelOutput'})) {
my $result = &OR_excel_sheet($r,$resource,
$PerformanceData,
- $ProblemData);
+ $problem_data);
$r->print($result);
$r->rflush();
} else {
- if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
+ if ($ENV{'form.AnalyzeOver'} eq 'tries') {
my $analysis_html = &OR_tries_analysis($r,
$PerformanceData,
- $ProblemData);
+ $problem_data);
$r->print($analysis_html);
$r->rflush();
- } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
+ } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
my $analysis_html = &OR_time_analysis($PerformanceData,
- $ProblemData);
+ $problem_data);
$r->print($analysis_html);
$r->rflush();
} else {
@@ -533,7 +935,7 @@ sub OptionResponseAnalysis {
#########################################################
#
-# Option Response: Tries Analysis
+# Option Response: tries Analysis
#
#########################################################
sub OR_tries_analysis {
@@ -541,77 +943,106 @@ sub OR_tries_analysis {
my $mintries = 1;
my $maxtries = $ENV{'form.NumPlots'};
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
- if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
- $table = '
'.
- &mt('Not enough data for concept analysis. '.
- 'Performing Foil Analysis').
- '
'.$table;
- $ENV{'form.AnalyzeAs'} = 'Foils';
- }
- my %ResponseData = &OR_analyze_by_tries($r,$PerformanceData,
+ my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
$mintries,$maxtries);
my $analysis = '';
- if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
- $analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Concepts,
- \%ResponseData,$ORdata);
- } else {
- $analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries,
- $Concepts,\%ResponseData,$ORdata);
- }
- $table .= $analysis;
- return $table;
-}
-
-sub OR_Tries_Foil_Analysis {
- my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
- my %ResponseData = %$respdat;
#
- # Compute the data neccessary to make the plots
- my @PlotData;
- foreach my $concept (@$Concepts) {
+ # Compute the data necessary to make the plots
+ my @foil_plot;
+ my @concept_data;
+ for (my $j=0;$j<=scalar(@$Concepts);$j++) {
+ my $concept = $Concepts->[$j];
foreach my $foilid (@{$concept->{'foils'}}) {
for (my $try=$mintries;$try<=$maxtries;$try++) {
- if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
- push(@{$PlotData[$try]->{'_correct'}},0);
+ # concept analysis data
+ $concept_data[$j]->[$try]->{'_correct'} +=
+ $response_data{$foilid}->[$try]->{'_correct'};
+ $concept_data[$j]->[$try]->{'_total'} +=
+ $response_data{$foilid}->[$try]->{'_total'};
+ #
+ # foil analysis data
+ if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
+ push(@{$foil_plot[$try]->{'_correct'}},0);
} else {
- push(@{$PlotData[$try]->{'_correct'}},
- 100*$ResponseData{$foilid}->[$try]->{'_correct'}/
- $ResponseData{$foilid}->[$try]->{'_total'});
+ push(@{$foil_plot[$try]->{'_correct'}},
+ 100*$response_data{$foilid}->[$try]->{'_correct'}/
+ $response_data{$foilid}->[$try]->{'_total'});
}
foreach my $option (@{$ORdata->{'_Options'}}) {
- push(@{$PlotData[$try]->{'_total'}},
- $ResponseData{$foilid}->[$try]->{'_total'});
- if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
- push (@{$PlotData[$try]->{$option}},0);
+ push(@{$foil_plot[$try]->{'_total'}},
+ $response_data{$foilid}->[$try]->{'_total'});
+ if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
+ push (@{$foil_plot[$try]->{$option}},0);
} else {
- if ($ResponseData{$foilid}->[$try]->{'_total'} ==
- $ResponseData{$foilid}->[$try]->{'_correct'}) {
- push(@{$PlotData[$try]->{$option}},0);
+ if ($response_data{$foilid}->[$try]->{'_total'} ==
+ $response_data{$foilid}->[$try]->{'_correct'}) {
+ push(@{$foil_plot[$try]->{$option}},0);
} else {
- push (@{$PlotData[$try]->{$option}},
+ push (@{$foil_plot[$try]->{$option}},
100 *
- $ResponseData{$foilid}->[$try]->{$option} /
- ($ResponseData{$foilid}->[$try]->{'_total'}
+ $response_data{$foilid}->[$try]->{$option} /
+ ($response_data{$foilid}->[$try]->{'_total'}
-
- $ResponseData{$foilid}->[$try]->{'_correct'}
+ $response_data{$foilid}->[$try]->{'_correct'}
));
}
}
} # End of foreach my $option
}
} # End of foreach my $foilid
- } # End of foreach my $concept
+ } # End of concept loops
#
# Build a table for the plots
my $analysis_html = "
\n";
my $optionkey = &build_option_index($ORdata);
+ my $num_concepts = 1;
+ if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
+ #
for (my $try=$mintries;$try<=$maxtries;$try++) {
- my $count = $ResponseData{'_total'}->[$try];
- my $title = 'Submission '.$try.' (N='.$count.')';
+ 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).
+ '
';
+ } else {
+ $analysis_html.= '
'.
+ &mt('None of the selected students have attempted the problem').'
';
+ }
+ last;
+ }
+ my $concept_graph='';
+ if ($num_concepts > 1) {
+ #
+ # Create concept plot
+ my @concept_plot_data;
+ for (my $j=0;$j<=$#concept_data;$j++) {
+ my $total = $concept_data[$j]->[$try]->{'_total'};
+ if ($total == 0) {
+ $concept_plot_data[$j] = 0;
+ } else {
+ $concept_plot_data[$j] = 100 *
+ sprintf('%0.3f',
+ $concept_data[$j]->[$try]->{'_correct'} /
+ $total);
+ }
+ }
+ #
+ my $title;
+ my $count = $response_data{'_total'}->[$try];
+ $title = 'Attempt '.$try.' (N='.$count.')';
+ $concept_graph = &Apache::loncommon::DrawBarGraph
+ ($title,'Concept Number','Percent Correct',
+ 100,$plotcolors,undef,\@concept_plot_data);
+ }
+ #
+ # Create Foil Plots
+ my $count = $response_data{'_total'}->[$try];
+ my $title = 'Attempt '.$try.' (N='.$count.')';
my @Datasets;
foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
- next if (! exists($PlotData[$try]->{$option}));
- push(@Datasets,$PlotData[$try]->{$option});
+ next if (! exists($foil_plot[$try]->{$option}));
+ push(@Datasets,$foil_plot[$try]->{$option});
}
#
# Put a blank in the data set between concepts
@@ -638,10 +1069,9 @@ sub OR_Tries_Foil_Analysis {
push(@Labels,'');
}
#
- my $correctgraph = &Apache::loncommon::DrawBarGraph
+ my $correct_graph = &Apache::loncommon::DrawBarGraph
($title,'Foil Number','Percent Correct',
100,$plotcolors,\@Labels,$Datasets[0]);
- $analysis_html.= '