');
- $r->print(&OptionResponseProblemSelector());
+ $r->print(&Apache::lonstathelpers::ProblemSelector
+ ($problem_types));
}
}
@@ -145,148 +186,358 @@ sub BuildProblemAnalysisPage {
#########################################################
#########################################################
##
-## Misc interface routines use by analysis code
+## Numerical Response Routines
##
#########################################################
#########################################################
-sub build_foil_index {
- my ($ORdata) = @_;
- my %Foildata = %{$ORdata->{'Foils'}};
- my @Foils = sort(keys(%Foildata));
- my %Concepts;
- foreach my $foilid (@Foils) {
- push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}},
- $foilid);
+sub NumericalResponseAnalysis {
+ my ($r,$problem,$ProblemData,$Students) = @_;
+ $r->print('
This analysis is not yet supported
');
+ my ($resource,$respid) = ($problem->{'resource'},
+ $problem->{'respid'});
+ my $analysis_html;
+ my $PerformanceData =
+ &Apache::loncoursedata::get_response_data
+ ($Students,$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;
}
- undef(@Foils);
- # Having gathered the concept information in a hash, we now translate it
- # into an array because we need to be consistent about order.
- # Also put the foils in order, too.
- my $sortfunction = sub {
- my %Numbers = (one => 1,
- two => 2,
- three => 3,
- four => 4,
- five => 5,
- six => 6,
- seven => 7,
- eight => 8,
- nine => 9,
- ten => 10,);
- my $a1 = $a;
- my $b1 = $b;
- if (exists($Numbers{lc($a)})) {
- $a1 = $Numbers{lc($a)};
+ my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
+ $r->print('Maximum = '.$max.' Minimum = '.$min);
+ my $max_students = 0;
+ my %Data;
+ foreach my $student (@$Students) {
+ my $answer = $student->{'answer'};
+ $Data{$answer}++;
+ if ($max_students < $Data{$answer}) {
+ $max_students = $Data{$answer};
}
- if (exists($Numbers{lc($b)})) {
- $b1 = $Numbers{lc($b)};
+ }
+ foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) {
+ if ($max_students < $_) {
+ $max_students = $_;
+ last;
}
- $a1 cmp $b1;
- };
- my @Concepts;
- foreach my $concept (sort $sortfunction (keys(%Concepts))) {
- push(@Concepts,{ name => $concept,
- foils => [@{$Concepts{$concept}}]});
- push(@Foils,(@{$Concepts{$concept}}));
}
- #
- # Build up the table of row labels.
- my $table = '
'."\n";
- if (@Concepts > 1) {
- $table .= '
'.
- '
'.&mt('Concept Number').'
'.
- '
'.&mt('Concept').'
'.
- '
'.&mt('Foil Number').'
'.
- '
'.&mt('Foil Name').'
'.
- '
'.&mt('Foil Text').'
'.
- '
'.&mt('Correct Value').'
'.
- "
\n";
+ 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);
+ 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;
+ }
+ $r->print("
\n");
+ $r->rflush();
+ # close progress window
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ return;
+}
+
+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;
+}
+
+#########################################################
+#########################################################
+##
+## Radio Response Routines
+##
+#########################################################
+#########################################################
+sub RadioResponseAnalysis {
+ my ($r,$problem,$ProblemData,$Students) = @_;
+ my ($resource,$respid) = ($problem->{'resource'},
+ $problem->{'respid'});
+ my $analysis_html;
+ my $PerformanceData =
+ &Apache::loncoursedata::get_response_data
+ ($Students,$resource->{'symb'},$respid);
+ if (! defined($PerformanceData) ||
+ ref($PerformanceData) ne 'ARRAY' ) {
+ $analysis_html = '
'.
+ &mt('There is no submission data for this resource').
+ '
'.
+ &mt('The analysis you have selected is '.
+ 'not supported at this time').
+ '
');
+ }
+ }
+ }
+}
+
+#########################################################
+#
+# Option Response: Tries Analysis
+#
+#########################################################
+sub OR_tries_analysis {
+ my ($r,$PerformanceData,$ORdata) = @_;
my $mintries = 1;
my $maxtries = $ENV{'form.NumPlots'};
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
@@ -297,69 +548,168 @@ sub tries_analysis {
''.$table;
$ENV{'form.AnalyzeAs'} = 'Foils';
}
- my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
+ my %ResponseData = &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; # Array which holds the data for each plot
- # @{$PlotData[$try]->{'datasetname'}} holds the data for
- # try $try with respect to 'datasetname'. The array is
- # filled either with per-foil or per-concept data.
- my ($extrakey,$xlabel,$ylabel);
- if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
- $extrakey = &build_option_index($ORdata);
- $xlabel = 'Foil Number';
- $ylabel = 'Option Chosen';
- foreach my $foilid (@$Foils) {
- for (my $i=$mintries;$i<=$maxtries;$i++) {
- foreach my $option ('_correct',@{$ORdata->{'Options'}}) {
- push(@{$PlotData[$i]->{'_total'}},
- $ResponseData{$foilid}->[$i]->{'_total'});
- if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {
- push (@{$PlotData[$i]->{$option}},0);
+ my @PlotData;
+ foreach my $concept (@$Concepts) {
+ foreach my $foilid (@{$concept->{'foils'}}) {
+ for (my $try=$mintries;$try<=$maxtries;$try++) {
+ if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
+ push(@{$PlotData[$try]->{'_correct'}},0);
+ } else {
+ push(@{$PlotData[$try]->{'_correct'}},
+ 100*$ResponseData{$foilid}->[$try]->{'_correct'}/
+ $ResponseData{$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);
} else {
- push (@{$PlotData[$i]->{$option}},
- 100 * $ResponseData{$foilid}->[$i]->{$option} /
- $ResponseData{$foilid}->[$i]->{'_total'});
+ if ($ResponseData{$foilid}->[$try]->{'_total'} ==
+ $ResponseData{$foilid}->[$try]->{'_correct'}) {
+ push(@{$PlotData[$try]->{$option}},0);
+ } else {
+ push (@{$PlotData[$try]->{$option}},
+ 100 *
+ $ResponseData{$foilid}->[$try]->{$option} /
+ ($ResponseData{$foilid}->[$try]->{'_total'}
+ -
+ $ResponseData{$foilid}->[$try]->{'_correct'}
+ ));
+ }
}
- }
+ } # End of foreach my $option
}
+ } # End of foreach my $foilid
+ } # End of foreach my $concept
+ #
+ # Build a table for the plots
+ my $analysis_html = "
\n";
+ my $optionkey = &build_option_index($ORdata);
+ for (my $try=$mintries;$try<=$maxtries;$try++) {
+ my $count = $ResponseData{'_total'}->[$try];
+ if ($count == 0) {
+ $count = 'no submissions';
+ } elsif ($count == 1) {
+ $count = '1 submission';
+ } else {
+ $count = $count.' submissions';
+ }
+ my $title = 'Attempt '.$try.', '.$count;
+ my @Datasets;
+ foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
+ next if (! exists($PlotData[$try]->{$option}));
+ push(@Datasets,$PlotData[$try]->{$option});
}
- } else {
- # Concept analysis
#
- # Note: we do not bother with characterizing the students incorrect
- # answers at the concept level because an incorrect answer for one foil
- # may be a correct answer for another foil.
- $extrakey = '';
- $xlabel = 'Concept Number';
- $ylabel = 'Percent Correct';
- my %ConceptData;
- foreach my $concept (@{$Concepts}) {
- for (my $i=$mintries;$i<=$maxtries;$i++) {
- #
- # Gather the per-attempt data
- my $cdata = $ConceptData{$concept}->[$i];
+ # Put a blank in the data set between concepts
+ for (my $set =0;$set<=$#Datasets;$set++) {
+ my @Data = @{$Datasets[$set]};
+ my $idx = 0;
+ foreach my $concept (@{$Concepts}) {
foreach my $foilid (@{$concept->{'foils'}}) {
- $cdata->{'_correct'} +=
- $ResponseData{$foilid}->[$i]->{'_correct'};
- $cdata->{'_total'} +=
- $ResponseData{$foilid}->[$i]->{'_total'};
+ $Datasets[$set]->[$idx++]=shift(@Data);
}
- push (@{$PlotData[$i]->{'_total'}},$cdata->{'_total'});
- if ($cdata->{'_total'} == 0) {
- push (@{$PlotData[$i]->{'_correct'}},0);
- } else {
- push (@{$PlotData[$i]->{'_correct'}},
- 100*$cdata->{'_correct'}/$cdata->{'_total'});
+ if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
+ $Datasets[$set]->[$idx++] = 0;
}
}
}
- } # End of work to fill @PlotData
- #
+ #
+ # Set up the labels needed for the bar graph
+ my @Labels;
+ my $idx = 1;
+ foreach my $concept (@{$Concepts}) {
+ foreach my $foilid (@{$concept->{'foils'}}) {
+ push(@Labels,$idx++);
+ }
+ push(@Labels,'');
+ }
+ #
+ my $correctgraph = &Apache::loncommon::DrawBarGraph
+ ($title,'Foil Number','Percent Correct',
+ 100,$plotcolors,\@Labels,$Datasets[0]);
+ $analysis_html.= '
\n";
+ return $analysis_html;
+}
+
+sub OR_Tries_Concept_Analysis {
+ my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
+ my %ResponseData = %$respdat;
+ my $analysis_html = "
\n";
+ #
+ # Compute the data neccessary to make the plots
+ my @PlotData;
+ # Concept analysis
+ #
+ # Note: we do not bother with characterizing the students incorrect
+ # answers at the concept level because an incorrect answer for one foil
+ # may be a correct answer for another foil.
+ my %ConceptData;
+ foreach my $concept (@{$Concepts}) {
+ for (my $i=$mintries;$i<=$maxtries;$i++) {
+ #
+ # Gather the per-attempt data
+ my $cdata = $ConceptData{$concept}->[$i];
+ foreach my $foilid (@{$concept->{'foils'}}) {
+ $cdata->{'_correct'} +=
+ $ResponseData{$foilid}->[$i]->{'_correct'};
+ $cdata->{'_total'} +=
+ $ResponseData{$foilid}->[$i]->{'_total'};
+ }
+ push (@{$PlotData[$i]->{'_total'}},$cdata->{'_total'});
+ if ($cdata->{'_total'} == 0) {
+ push (@{$PlotData[$i]->{'_correct'}},0);
+ } else {
+ push (@{$PlotData[$i]->{'_correct'}},
+ 100*$cdata->{'_correct'}/$cdata->{'_total'});
+ }
+ }
+ }
# Build a table for the plots
- $table .= "
\n";
- my @Plots;
for (my $i=$mintries;$i<=$maxtries;$i++) {
my $minstu = $PlotData[$i]->{'_total'}->[0];
my $maxstu = $PlotData[$i]->{'_total'}->[0];
@@ -374,58 +724,41 @@ sub tries_analysis {
$maxstu = 0 if (! defined($maxstu));
$minstu = 0 if (! defined($minstu));
my $title;
- if ($maxstu == $minstu) {
- $title = 'Attempt '.$i.', '.$maxstu.' students';
+ my $count = $ResponseData{'_total'}->[$i];
+ if ($count == 0) {
+ $count = 'no submissions';
+ } elsif ($count == 1) {
+ $count = '1 submission';
} else {
- $title = 'Attempt '.$i.', '.$minstu.'-'.$maxstu.' students';
+ $count = $count.' submissions';
}
- my @Datasets;
- foreach my $option ('_correct',@{$ORdata->{'Options'}}) {
- next if (! exists($PlotData[$i]->{$option}));
- push(@Datasets,$PlotData[$i]->{$option});
- }
- my $graphlink = &Apache::loncommon::DrawGraph($title,
- $xlabel,
- $ylabel,
- 100,
- $plotcolors,
- @Datasets);
- push(@Plots,$graphlink);
- }
- #
- # Should this be something the user can set? Too many dialogs!
- while (my $plotlink = shift(@Plots)) {
- $table .= '