'
+ .&mt('There is no student data for this problem.')
+ .'
'
+ );
+ } else {
+ $r->rflush();
+ if ($env{'form.AnalyzeOver'} eq 'tries') {
+ my $analysis_html = &OR_tries_analysis($r,
+ $PerformanceData,
+ $problem_data);
+ $r->print($analysis_html);
+ $r->rflush();
+ } elsif ($env{'form.AnalyzeOver'} eq 'time') {
+ my $analysis_html = &OR_time_analysis($PerformanceData,
+ $problem_data);
+ $r->print($analysis_html);
+ $r->rflush();
+ } else {
+ $r->print(''
+ );
+ }
+ }
+}
+
+#########################################################
+#
+# 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);
+ if (! defined($Concepts)) {
+ $Concepts = [];
+ }
+ my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
+ $mintries,$maxtries);
+ my $analysis = '';
+ #
+ # 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++) {
+ # 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(@{$foil_plot[$try]->{'_correct'}},
+ 100*$response_data{$foilid}->[$try]->{'_correct'}/
+ $response_data{$foilid}->[$try]->{'_total'});
+ }
+ foreach my $option (@{$ORdata->{'_Options'}}) {
+ 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 ($response_data{$foilid}->[$try]->{'_total'} ==
+ $response_data{$foilid}->[$try]->{'_correct'}) {
+ push(@{$foil_plot[$try]->{$option}},0);
+ } else {
+ push (@{$foil_plot[$try]->{$option}},
+ 100 *
+ $response_data{$foilid}->[$try]->{$option} /
+ ($response_data{$foilid}->[$try]->{'_total'}
+ -
+ $response_data{$foilid}->[$try]->{'_correct'}
+ ));
+ }
+ }
+ } # End of foreach my $option
+ }
+ } # End of foreach my $foilid
+ } # 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++) {
+ 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 [quant,_1,time].'
+ ,$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 %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Correct Concepts',
+ 'xlabel' => 'Concept Number',
+ 'ylabel' => 'Percent Correct');
+ $concept_graph = &Apache::loncommon::DrawBarGraph
+ ($lt{'title'},$lt{'xlabel'},$lt{'ylabel'},
+ 100,$plotcolors,undef,\@concept_plot_data,{xskip=>1});
+ }
+ #
+ # Create Foil Plots
+ my $data_count = $response_data{'_total'}->[$try];
+ my $correct = $response_data{'_correct'}->[$try];
+ $correct |= 0;
+ my @Datasets;
+ foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
+ next if (! exists($foil_plot[$try]->{$option}));
+ push(@Datasets,$foil_plot[$try]->{$option});
+ }
+ #
+ # 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'}}) {
+ $Datasets[$set]->[$idx++]=shift(@Data);
+ }
+ if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
+ $Datasets[$set]->[$idx++] = 0;
+ }
+ }
+ }
+ #
+ # 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 %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Correct Statements',
+ 'xlabel' => 'Statement',
+ 'ylabel' => '% Answered Correct');
+ my $correct_graph = &Apache::loncommon::DrawBarGraph
+ ($lt{'title'},$lt{'xlabel'},$lt{'ylabel'},
+ 100,$plotcolors,\@Labels,$Datasets[0],{xskip=>1});
+
+ #
+ #
+ next if (! defined($Datasets[0]));
+ for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
+ $Datasets[0]->[$i]=0;
+ }
+ my $count = $response_data{'_total'}->[$try] -
+ $response_data{'_correct'}->[$try];
+ %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Incorrect Statements',
+ 'xlabel' => 'Statement',
+ 'ylabel' => '% Chosen Incorrectly');
+ my $incorrect_graph = &Apache::loncommon::DrawBarGraph
+ ($lt{'title'},$lt{'xlabel'},$lt{'ylabel'},
+ 100,$plotcolors,\@Labels,@Datasets,{xskip=>1});
+ $analysis_html.=
+ ''.
+ ''.
+ &mt('Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect',
+ $try,$data_count,$correct,$data_count-$correct).
+ ' '.' '.$/.
+ ''.
+ ''.$concept_graph.' '.
+ ''.$correct_graph.' '.
+ ''.$incorrect_graph.' '.
+ ''.$optionkey.' '.
+ ' '.$/;
+ }
+ $analysis_html .= "
\n";
+ $table .= $analysis_html;
+ return $table;
+}
+
+sub OR_analyze_by_tries {
+ my ($r,$PerformanceData,$mintries,$maxtries) = @_;
+ my %Trydata;
+ $mintries = 1 if (! defined($mintries) || $mintries < 1);
+ $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
+ my @students;
+ foreach my $row (@$PerformanceData) {
+ next if (! defined($row));
+ my $tries = &get_tries_from_row($row);
+ my %Row = &Process_OR_Row($row);
+ next if (! %Row);
+ my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
+ $students[$tries]->{$student_id}++;
+ while (my ($foilid,$href) = each(%Row)) {
+ if (! ref($href)) {
+ $Trydata{$foilid}->[$tries] += $href;
+ next;
+ }
+ while (my ($option,$value) = each(%$href)) {
+ $Trydata{$foilid}->[$tries]->{$option}+=$value;
+ }
+ }
+ }
+ for (my $try=$mintries;$try<=$maxtries;$try++) {
+ $Trydata{'_studentcount'}->[$try] = scalar(keys(%{$students[$try]}));
+ }
+ return %Trydata;
+}
+
+#########################################################
+#
+# Option Response: Time Analysis
+#
+#########################################################
+sub OR_time_analysis {
+ my ($performance_data,$ORdata) = @_;
+ my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
+ my $foilkey = &build_option_index($ORdata);
+ my $num_concepts = 1;
+ if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
+ #
+ if ($num_concepts < 2) {
+ $table = '
'.
+ &mt('Not enough data for concept analysis.'.
+ ' Performing Foil Analysis instead.').
+ '
'.
+ $table;
+ }
+ #
+ my $num_plots = $env{'form.NumPlots'};
+ my $num_data = scalar(@$performance_data)-1;
+ #
+ my $current_index;
+ $table .= "
\n";
+ for (my $i=0;$i<$num_plots;$i++) {
+ ##
+ my $starttime = &Apache::lonhtmlcommon::get_date_from_form
+ ('startdate_'.$i);
+ my $endtime = &Apache::lonhtmlcommon::get_date_from_form
+ ('enddate_'.$i);
+ if (! defined($starttime) || ! defined($endtime)) {
+ my $sec_in_day = 86400;
+ my $last_sub_time = &get_time_from_row($performance_data->[-1]);
+ my ($sday,$smon,$syear) =
+ (localtime($last_sub_time - $sec_in_day*$i))[3..5];
+ $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
+ $endtime = $starttime + $sec_in_day;
+ if ($i == ($num_plots -1 )) {
+ $starttime = &get_time_from_row($performance_data->[0]);
+ }
+ }
+ $table .= ''.
+ &mt('Data from [_1] to [_2]',
+ &Apache::lonlocal::locallocaltime($starttime),
+ &Apache::lonlocal::locallocaltime($endtime)).
+ ' '.$/;
+ my $startdateform = &Apache::lonhtmlcommon::date_setter
+ ('Statistics','startdate_'.$i,$starttime);
+ my $enddateform = &Apache::lonhtmlcommon::date_setter
+ ('Statistics','enddate_'.$i,$endtime);
+ #
+ my $begin_index;
+ my $end_index;
+ my $j;
+ while (++$j < scalar(@$performance_data)) {
+ last if (&get_time_from_row($performance_data->[$j])
+ > $starttime);
+ }
+ $begin_index = $j;
+ while ($j < scalar(@$performance_data)) {
+ if (&get_time_from_row($performance_data->[$j]) > $endtime) {
+ last;
+ } else {
+ $j++;
+ }
+ }
+ $end_index = $j;
+ ##
+ my ($processed_time_data,$correct,$data_count,$student_count) =
+ &OR_time_process_data($performance_data,$begin_index,$end_index);
+ $correct |= 0;
+ ##
+ $table .= ''.
+ &mt('[quant,_1,submission,submissions,No submissions] from [quant,_2,student], [_3] correct, [_4] incorrect',
+ $data_count,$student_count,$correct,$data_count-$correct).
+ ' '.$/;
+ my $concept_correct_plot = '';
+ if ($num_concepts > 1) {
+ $concept_correct_plot =
+ &OR_Concept_Time_Analysis($processed_time_data,
+ $correct,$data_count,$student_count,
+ $ORdata,$Concepts);
+ }
+ my ($foil_correct_plot,$foil_incorrect_plot) =
+ &OR_Foil_Time_Analysis($processed_time_data,
+ $correct,$data_count,$student_count,
+ $ORdata,$Foils,$Concepts);
+ $table .= ''.
+ ''.$concept_correct_plot.' '.
+ ''.$foil_correct_plot.' '.
+ ''.$foil_incorrect_plot.' '.
+ ''.$foilkey.' '.$/;
+ $table .= ''.
+ &mt('Start time: [_1]',$startdateform).' '.
+ &mt('End time: [_1]',$enddateform).' '.$/;
+ $table.= ' '.$/;
+ }
+ $table .= '
';
+ #
+ return $table;
+}
+
+sub OR_Foil_Time_Analysis {
+ my ($processed_time_data,$correct,$data_count,$student_count,
+ $ORdata,$Foils,$Concepts) = @_;
+ if ($data_count <= 0) {
+ return ('
'
+ .&mt('There is no data to plot.')
+ .'
'
+ ,''
+ );
+ }
+ my $analysis_html;
+ my @plotdata;
+ my @labels;
+ foreach my $concept (@{$Concepts}) {
+ foreach my $foil (@{$concept->{'foils'}}) {
+ push(@labels,scalar(@labels)+1);
+ my $total = $processed_time_data->{$foil}->{'_total'};
+ if ($total == 0) {
+ push(@{$plotdata[0]},0);
+ } else {
+ push(@{$plotdata[0]},
+ 100 * $processed_time_data->{$foil}->{'_correct'} / $total);
+ }
+ my $total_incorrect = $total - $processed_time_data->{$foil}->{'_correct'};
+ for (my $i=0;$i
{'_Options'}});$i++) {
+ my $option = $ORdata->{'_Options'}->[$i];
+ if ($total_incorrect == 0) {
+ push(@{$plotdata[$i+1]},0);
+ } else {
+ push(@{$plotdata[$i+1]},
+ 100 * $processed_time_data->{$foil}->{$option} / $total_incorrect);
+ }
+ }
+ }
+ # Put in a blank one
+ push(@labels,'');
+ push(@{$plotdata[0]},0);
+ for (my $i=0;$i{'_Options'}});$i++) {
+ push(@{$plotdata[$i+1]},0);
+ }
+ }
+ #
+ # Create the plot
+ my %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Correct Statements',
+ 'xlabel' => 'Statement Number',
+ 'ylabel' => 'Percent Correct');
+ my $correct_plot = &Apache::loncommon::DrawBarGraph($lt{'title'},
+ $lt{'xlabel'},
+ $lt{'ylabel'},
+ 100,
+ $plotcolors,
+ undef,
+ $plotdata[0],
+ {xskip=>1});
+ for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
+ $plotdata[0]->[$j]=0;
+ }
+ %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Incorrect Statements',
+ 'xlabel' => 'Statement Number',
+ 'ylabel' => 'Incorrect Option Choice');
+ my $incorrect_plot =
+ &Apache::loncommon::DrawBarGraph($lt{'title'},
+ $lt{'xlabel'},
+ $lt{'ylabel'},
+ 100,
+ $plotcolors,
+ undef,
+ @plotdata,{xskip=>1});
+ return ($correct_plot,$incorrect_plot);
+}
+
+sub OR_Concept_Time_Analysis {
+ my ($processed_time_data,$correct,$data_count,$student_count,
+ $ORdata,$Concepts) = @_;
+ return '' if ($data_count == 0);
+ #
+ # Put the data in plottable form
+ my @plotdata;
+ foreach my $concept (@$Concepts) {
+ my ($total,$correct);
+ foreach my $foil (@{$concept->{'foils'}}) {
+ $total += $processed_time_data->{$foil}->{'_total'};
+ $correct += $processed_time_data->{$foil}->{'_correct'};
+ }
+ if ($total == 0) {
+ push(@plotdata,0);
+ } else {
+ push(@plotdata,100 * $correct / $total);
+ }
+ }
+ #
+ # Create the plot
+ my %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Correct Concepts',
+ 'xlabel' => 'Concept Number',
+ 'ylabel' => 'Percent Correct');
+ return &Apache::loncommon::DrawBarGraph($lt{'title'},
+ $lt{'xlabel'},
+ $lt{'ylabel'},
+ 100,
+ $plotcolors,
+ undef,
+ \@plotdata,{xskip=>1});
+}
+
+sub OR_time_process_data {
+ my ($performance_data,$begin_index,$end_index)=@_;
+ my %processed_time_data;
+ my %distinct_students;
+ my ($correct,$data_count);
+ if (($begin_index == $end_index) &&
+ ($end_index != scalar(@$performance_data)-1)) {
+ return undef;
+ }
+ # Be sure we include the last one if we are asked for it.
+ # That we have to correct here (and not when $end_index is
+ # given a value) should probably be considered a bug.
+ if ($end_index == scalar(@$performance_data)-1) {
+ $end_index++;
+ }
+ my $count;
+ for (my $i=$begin_index;$i<$end_index;$i++) {
+ my $attempt = $performance_data->[$i];
+ $count++;
+ next if (! defined($attempt));
+ my %attempt = &Process_OR_Row($attempt);
+ $data_count++;
+ $correct += $attempt{'_correct'};
+ $distinct_students{$attempt->[&Apache::loncoursedata::RD_student_id()]}++;
+ while (my ($foilid,$href) = each(%attempt)) {
+ if (! ref($href)) {
+ $processed_time_data{$foilid} += $href;
+ next;
+ }
+ while (my ($option,$value) = each(%$href)) {
+ $processed_time_data{$foilid}->{$option}+=$value;
+ }
+ }
+ }
+ return (\%processed_time_data,$correct,$data_count,
+ scalar(keys(%distinct_students)));
+}
+
sub build_foil_index {
my ($ORdata) = @_;
- return if (! exists($ORdata->{'Foils'}));
- my %Foildata = %{$ORdata->{'Foils'}};
+ return if (! exists($ORdata->{'_Foils'}));
+ my %Foildata = %{$ORdata->{'_Foils'}};
my @Foils = sort(keys(%Foildata));
my %Concepts;
foreach my $foilid (@Foils) {
- push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}},
+ push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
$foilid);
}
undef(@Foils);
@@ -174,41 +1768,49 @@ sub build_foil_index {
eight => 8,
nine => 9,
ten => 10,);
- my $a1 = $a;
- my $b1 = $b;
- if (exists($Numbers{lc($a)})) {
- $a1 = $Numbers{lc($a)};
+ my $a1 = lc($a);
+ my $b1 = lc($b);
+ if (exists($Numbers{$a1})) {
+ $a1 = $Numbers{$a1};
+ }
+ if (exists($Numbers{$b1})) {
+ $b1 = $Numbers{$b1};
}
- if (exists($Numbers{lc($b)})) {
- $b1 = $Numbers{lc($b)};
+ if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
+ return $a1 <=> $b1;
+ } else {
+ return $a1 cmp $b1;
}
- $a1 cmp $b1;
};
my @Concepts;
foreach my $concept (sort $sortfunction (keys(%Concepts))) {
+ if (! defined($Concepts{$concept})) {
+ $Concepts{$concept}=[];
+# next;
+ }
push(@Concepts,{ name => $concept,
foils => [@{$Concepts{$concept}}]});
push(@Foils,(@{$Concepts{$concept}}));
}
#
# Build up the table of row labels.
- my $table = ''."\n";
+ my $table = &Apache::loncommon::start_data_table();
if (@Concepts > 1) {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_header_row().
''.&mt('Concept Number').' '.
''.&mt('Concept').' '.
''.&mt('Foil Number').' '.
''.&mt('Foil Name').' '.
''.&mt('Foil Text').' '.
''.&mt('Correct Value').' '.
- " \n";
+ &Apache::loncommon::end_data_table_header_row();
} else {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_header_row().
''.&mt('Foil Number').' '.
''.&mt('Foil Name').' '.
''.&mt('Foil Text').' '.
''.&mt('Correct Value').' '.
- " \n";
+ &Apache::loncommon::end_data_table_header_row();
}
my $conceptindex = 1;
my $foilindex = 1;
@@ -216,39 +1818,39 @@ sub build_foil_index {
my @FoilsInConcept = @{$concept->{'foils'}};
my $firstfoil = shift(@FoilsInConcept);
if (@Concepts > 1) {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_row().
''.$conceptindex.' '.
- ''.$concept->{'name'}.' '.
+ ''.&HTML::Entities::encode($concept->{'name'},'<>&"').' '.
''.$foilindex++.' '.
- ''.$Foildata{$firstfoil}->{'name'}.' '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' '.
''.$Foildata{$firstfoil}->{'text'}.' '.
- ''.$Foildata{$firstfoil}->{'value'}.' '.
- " \n";
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' '.
+ &Apache::loncommon::end_data_table_row();
} else {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_row().
''.$foilindex++.' '.
- ''.$Foildata{$firstfoil}->{'name'}.' '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' '.
''.$Foildata{$firstfoil}->{'text'}.' '.
- ''.$Foildata{$firstfoil}->{'value'}.' '.
- " \n";
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' '.
+ &Apache::loncommon::end_data_table_row();
}
foreach my $foilid (@FoilsInConcept) {
if (@Concepts > 1) {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_row().
' '.
' '.
''.$foilindex.' '.
- ''.$Foildata{$foilid}->{'name'}.' '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' '.
''.$Foildata{$foilid}->{'text'}.' '.
- ''.$Foildata{$foilid}->{'value'}.' '.
- " \n";
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' '.
+ &Apache::loncommon::end_data_table_row();
} else {
- $table .= ''.
+ $table .= &Apache::loncommon::start_data_table_row().
''.$foilindex.' '.
- ''.$Foildata{$foilid}->{'name'}.' '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' '.
''.$Foildata{$foilid}->{'text'}.' '.
- ''.$Foildata{$foilid}->{'value'}.' '.
- " \n";
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' '.
+ &Apache::loncommon::end_data_table_row();
}
} continue {
$foilindex++;
@@ -256,7 +1858,7 @@ sub build_foil_index {
} continue {
$conceptindex++;
}
- $table .= "
\n";
+ $table .= &Apache::loncommon::end_data_table();
#
# Build option index with color stuff
return ($table,\@Foils,\@Concepts);
@@ -267,529 +1869,213 @@ sub build_option_index {
my $table = "\n";
my $optionindex = 0;
my @Rows;
- foreach my $option (&mt('correct option chosen'),@{$ORdata->{'Options'}}) {
+ foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
+ my $color = $plotcolors->[$optionindex++];
push (@Rows,
''.
- ''.
- (' 'x4).' '.
- ''.$option.' '.
+ ''.
+ ''.('*'x3).' '.' '.
+ ''.&HTML::Entities::encode($option,'<>&"').' '.
" \n");
}
+ shift(@Rows); # Throw away 'correct option chosen' color
$table .= join('',reverse(@Rows));
$table .= "
\n";
}
-#########################################################
-#########################################################
-##
-## Tries Analysis
-##
-#########################################################
-#########################################################
-sub tries_analysis {
- my ($PerformanceData,$ORdata) = @_;
- 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 = &analyze_option_data_by_tries($PerformanceData,
- $mintries,$maxtries);
- #
- # 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 = 'Percent Choosing Option';
- 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);
- } else {
- push (@{$PlotData[$i]->{$option}},
- 100 * $ResponseData{$foilid}->[$i]->{$option} /
- $ResponseData{$foilid}->[$i]->{'_total'});
- }
- }
- }
- }
- } 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];
- 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'});
- }
- }
- }
- } # End of work to fill @PlotData
- #
- # 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];
- foreach my $count (@{$PlotData[$i]->{'_total'}}) {
- if ($minstu > $count) {
- $minstu = $count;
- }
- if ($maxstu < $count) {
- $maxstu = $count;
- }
- }
- $maxstu = 0 if (! defined($maxstu));
- $minstu = 0 if (! defined($minstu));
- my $title;
- if ($maxstu == $minstu) {
- $title = 'Attempt '.$i.', '.$maxstu.' students';
- } else {
- $title = 'Attempt '.$i.', '.$minstu.'-'.$maxstu.' students';
- }
- 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 .= ''.$plotlink.' '.$extrakey." \n";
+sub build_foil_key {
+ my ($foils,$extra_data)= @_;
+ if (! defined($extra_data)) { $extra_data = {}; }
+ my $table = "\n";
+ my $foil_index = 0;
+ my @rows;
+ foreach my $foil (&mt('correct foil chosen'),@{$foils}) {
+ my $color = $plotcolors->[$foil_index++];
+ push (@rows,
+ ''.
+ ''.
+ ''.('*'x4).' '.
+ ''.&HTML::Entities::encode($foil,'<>&"').
+ (' 'x2).$extra_data->{$foil}.' '.
+ " \n");
}
+ shift(@rows); # Throw away 'correct foil chosen' color
+ $table .= join('',reverse(@rows));
$table .= "
\n";
- return ($table);
-}
-
-sub analyze_option_data_by_tries {
- my ($PerformanceData,$mintries,$maxtries) = @_;
- my %Trydata;
- $mintries = 1 if (! defined($mintries) || $mintries < 1);
- $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
- foreach my $row (@$PerformanceData) {
- next if (! defined($row));
- my ($grading,$submission,$time,$tries) = @$row;
- next if ($grading eq 'MISSING_ANSWER');
- my @Foilgrades = split('&',$grading);
- my @Foilsubs = split('&',$submission);
- for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
- if ($tries == $numtries) {
- for (my $i=0;$i<=$#Foilgrades;$i++) {
- my ($foilid,$correct) = split('=',$Foilgrades[$i]);
- my (undef,$submission) = split('=',$Foilsubs[$i]);
- $submission = &Apache::lonnet::unescape($submission);
- if ($correct) {
- $Trydata{$foilid}->[$numtries]->{'_correct'}++;
- } else {
- $Trydata{$foilid}->[$numtries]->{$submission}++;
- }
- $Trydata{$foilid}->[$numtries]->{'_total'}++;
- }
- }
- }
- }
- return %Trydata;
}
#########################################################
#########################################################
##
-## Time Analysis
-##
-#########################################################
-#########################################################
-sub time_analysis {
- my ($PerformanceData,$ORdata) = @_;
- my $num_plots = $ENV{'form.NumPlots'};
- my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
- my $num_data = scalar(@$PerformanceData)-1;
- my $percent = sprintf('%2f',100/$num_plots);
- my $extratable = '';
- if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
- $extratable = &build_option_index($ORdata);
- }
- $table .= "\n";
- for (my $i=0;$i<$num_plots;$i++) {
- my $starttime = &Apache::lonhtmlcommon::get_date_from_form
- ('startdate_'.$i);
- my $endtime = &Apache::lonhtmlcommon::get_date_from_form
- ('enddate_'.$i);
- my ($begin_index,$end_index,$plottitle,$plothtml,$data);
- if (! defined($starttime) || ! defined($endtime)) {
- $begin_index = $i*int($num_data/$num_plots);
- $end_index = ($i+1)*int($num_data/$num_plots);
- my $lownum = sprintf('%2.1f',$i*$percent);
- $lownum =~ s/(\.0)$//;
- my $highnum = sprintf('%2.1f',($i+1)*$percent);
- $highnum =~ s/(\.0)$//;
- $plottitle = $lownum.'% to '.$highnum.'% of submissions';
- } else {
- my $j;
- while (++$j < scalar(@$PerformanceData)) {
- last if ($PerformanceData->[$j]->[2] > $starttime);
- }
- $begin_index = $j;
- while (++$j < scalar(@$PerformanceData)) {
- last if ($PerformanceData->[$j]->[2] > $endtime);
- }
- $end_index = $j;
- $plottitle = $ENV{'form.plottitle_'.$i};
- }
- ($plothtml,$starttime,$endtime,$data) =
- &analyze_option_data_by_time($PerformanceData,
- $begin_index,$end_index,
- $plottitle,$Foils,
- $Concepts,$ORdata);
- my $startdateform = &Apache::lonhtmlcommon::date_setter
- ('Statistics','startdate_'.$i,$starttime);
- my $enddateform = &Apache::lonhtmlcommon::date_setter
- ('Statistics','enddate_'.$i,$endtime);
- $table.="".$plothtml.' '.
- "Start Time : ".$startdateform." ".
- "End Time : "." ".$enddateform." ".
- 'Plot Title :'.(" "x3).
- ' '.$extratable.
- " \n";
- }
- $table .="
\n";
- return $table;
-}
-
-sub analyze_option_data_by_time {
- my ($PerformanceData,$begin_index,
- $end_index,$description,$Foils,$Concepts,$ORdata) = @_;
- my %TimeData;
- #
- # Get the start and end times for this segment of the plot
- my $starttime = $PerformanceData->[$begin_index]->[2];
- my $endtime = $PerformanceData->[$end_index ]->[2];
- #
- # Compute the number getting the foils correct or incorrects
- for (my $i=$begin_index;$i<=$end_index;$i++) {
- my $row = $PerformanceData->[$i];
- next if (! defined($row));
- my ($grading,$submission,$time,$tries) = @$row;
- next if ($grading eq 'MISSING_ANSWER');
- my @Foilgrades = split('&',$grading);
- my @Foilsubs = split('&',$submission);
- for (my $j=0;$j<=$#Foilgrades;$j++) {
- my ($foilid,$correct) = split('=',$Foilgrades[$j]);
- my (undef,$submission) = split('=',$Foilsubs[$j]);
- if ($correct) {
- $TimeData{$foilid}->{'_correct'}++;
- } else {
- $submission = &HTML::Entities::decode($submission);
- $submission =~ s/\%20/ /g;
- $TimeData{$foilid}->{$submission}++;
- }
- $TimeData{$foilid}->{'_total'}++;
- }
- }
- #
- # Compute the total and percent correct
- my @Plotdata;
- my ($xlabel,$ylabel);
- if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
- $xlabel = 'Foil Number';
- $ylabel = 'Option Chosen';
- foreach my $foil (@$Foils) {
- my $total = $TimeData{$foil}->{'_total'};
- my $optionidx = 0;
- foreach my $option ('_correct',@{$ORdata->{'Options'}}) {
- if ($total > 0) {
- push(@{$Plotdata[$optionidx]},
- 100 * $TimeData{$foil}->{$option} / $total);
- } else {
- push(@{$Plotdata[$optionidx]},0);
- }
- } continue {
- $optionidx++;
- }
- }
- } else {
- $xlabel = 'Concept Number';
- $ylabel = 'Percent Correct';
- foreach my $concept (@$Concepts) {
- my $correct;
- my $total;
- foreach my $foil (@{$concept->{'foils'}}) {
- $correct+=$TimeData{$foil}->{'_correct'};
- $total +=$TimeData{$foil}->{'_total'};
- }
- if ($total > 0) {
- push(@{$Plotdata[0]},100 * $correct / $total);
- } else {
- push(@{$Plotdata[0]},0);
- }
- }
- }
- #
- # Create the plot
- my $graphlink = &Apache::loncommon::DrawGraph
- ($description,#'Time Interval Analysis',
- $xlabel,
- $ylabel,
- 100,
- $plotcolors,
- @Plotdata);
- #
- return ($graphlink,$starttime,$endtime,\%TimeData);
-}
-
-#########################################################
-#########################################################
-##
-## Interface
+## Generic Interface Routines
##
#########################################################
#########################################################
sub CreateInterface {
##
## Environment variable initialization
- if (! exists$ENV{'form.AnalyzeOver'}) {
- $ENV{'form.AnalyzeOver'} = 'Tries';
+ if (! exists($env{'form.AnalyzeOver'})) {
+ $env{'form.AnalyzeOver'} = 'tries';
}
##
## Build the menu
my $Str = '';
- $Str .= ''."\n";
- $Str .= '';
- $Str .= ''.&mt('Sections').' ';
- $Str .= ''.&mt('Enrollment Status').' ';
-# $Str .= ''.&mt('Sequences and Folders').' ';
- $Str .= ' ';
- $Str .= ' '."\n";
+ $Str .= '';
+ $Str .= &Apache::loncommon::start_data_table();
+ $Str .= &Apache::loncommon::start_data_table_header_row();
+ $Str .= '
'.&mt('Sections').' ';
+ $Str .= ''.&mt('Groups').' ';
+ $Str .= ''.&mt('Access Status').' ';
+ $Str .= ''.&mt('Options').' ';
+ $Str .= &Apache::loncommon::end_data_table_header_row();
##
##
- $Str .= ''."\n";
+ $Str .= &Apache::loncommon::start_data_table_row();
+ $Str .= ' '."\n";
$Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
$Str .= ' ';
#
+ $Str .= ''."\n";
+ $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
+ $Str .= ' ';
+ #
$Str .= '';
$Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
$Str .= ' ';
#
-# $Str .= '';
- my $only_seq_with_assessments = sub {
- my $s=shift;
- if ($s->{'num_assess'} < 1) {
- return 0;
- } else {
- return 1;
- }
- };
- &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
- $only_seq_with_assessments);
##
##
- $Str .= ' ';
- { # These braces are here to organize the code, not scope it.
- {
- $Str .= ''.&mt('Analyze Over ');
- $Str .='';
- $Str .= '';
- $Str .= ' ';
- $Str .= ' ';
- }
- {
- $Str .= ''.&mt('Analyze as ');
- $Str .='';
- $Str .= '';
- $Str .= ' ';
- $Str .= ' ';
- }
- {
- $Str .= ''.&mt('Number of Plots:');
- $Str .= '';
- if (! exists($ENV{'form.NumPlots'})
- || $ENV{'form.NumPlots'} < 1
- || $ENV{'form.NumPlots'} > 20) {
- $ENV{'form.NumPlots'} = 5;
- }
- foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
- $Str .= '';
- }
- $Str .= ' ';
- }
+ $Str .= ' ';
+ ##
+ my $showprob_checkbox =
+ ' ';
+ $Str.= ''.
+ $showprob_checkbox.' '.&mt('Show problem').
+ ' ';
##
+ my $analyze_selector = '';
+ $analyze_selector .= '';
+ $analyze_selector .= ' ';
+ $analyze_selector .= ' ';
+ $Str .= ''.
+ &mt('Analyze Over [_1] [_2]',
+ $analyze_selector,
+ &Apache::loncommon::help_open_topic('Analysis_Analyze_Over')).
+ ' '.$/;
##
- $Str .= ' '."\n";
- $Str .= '
'."\n";
- return ($Str);
-}
-
-sub OptionResponseProblemSelector {
- my $Str;
- $Str = "\n\n";
+ foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
+ $numplots_selector .= '';
+ }
+ $numplots_selector .= '';
+ $Str .= ''.&mt('Number of Plots [_1]',$numplots_selector).
+ ' ';
+ ##
+ $Str .= '';
+ ##
+ ##
+ $Str .= &Apache::loncommon::end_data_table_row();
+ $Str .= &Apache::loncommon::end_data_table();
+ $Str .= ''
+ .&mt('Status: [_1]',
+ ' ')
+ .'
';
+ $Str .= '';
return $Str;
}
#########################################################
#########################################################
##
-## Misc functions
+## Misc Option Response functions
##
#########################################################
#########################################################
-sub get_problem_symb {
- my $problemstring = shift();
- my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
- return ($symb,$partid,$resid);
+sub get_time_from_row {
+ my ($row) = @_;
+ if (ref($row)) {
+ return $row->[&Apache::loncoursedata::RD_timestamp()];
+ }
+ return undef;
}
-sub get_resource_from_symb {
- my ($symb) = @_;
- foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
- foreach my $res (@{$seq->{'contents'}}) {
- if ($res->{'symb'} eq $symb) {
- return $res;
- }
- }
+sub get_tries_from_row {
+ my ($row) = @_;
+ if (ref($row)) {
+ return $row->[&Apache::loncoursedata::RD_tries()];
}
return undef;
}
-##
-## get problem data and put it into a useful data structure.
-## note: we must force each foil and option to not begin or end with
-## spaces as they are stored without such data.
-##
-sub get_problem_data {
- my ($url) = @_;
- my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
- (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
- my %Answer;
- %Answer=&Apache::lonnet::str2hash($Answ);
- my %Partdata;
- foreach my $part (@{$Answer{'parts'}}) {
- while (my($key,$value) = each(%Answer)) {
- next if ($key !~ /^$part/);
- $key =~ s/^$part\.//;
- if (ref($value) eq 'ARRAY') {
- if ($key eq 'options') {
- $Partdata{$part}->{'Options'}=$value;
- } elsif ($key eq 'concepts') {
- $Partdata{$part}->{'Concepts'}=$value;
- } elsif ($key =~ /^concept\.(.*)$/) {
- my $concept = $1;
- foreach my $foil (@$value) {
- $Partdata{$part}->{'Foils'}->{$foil}->{'Concept'}=
- $concept;
- }
- }
- } else {
- if ($key=~ /^foil\.text\.(.*)$/) {
- my $foil = $1;
- $Partdata{$part}->{'Foils'}->{$foil}->{'name'}=$foil;
- $Partdata{$part}->{'Foils'}->{$foil}->{'text'}=$value;
- } elsif ($key =~ /^foil\.value\.(.*)$/) {
- my $foil = $1;
- $Partdata{$part}->{'Foils'}->{$foil}->{'value'}=$value;
- }
- }
+sub hashify_attempt {
+ my ($row) = @_;
+ my %attempt;
+ $attempt{'student'} = $row->[&Apache::loncoursedata::RD_sname()];
+ $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
+ $attempt{'submission'} = &unescape($row->[&Apache::loncoursedata::RD_submission()]);
+ $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
+ $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
+ return %attempt;
+}
+
+sub Process_OR_Row {
+ my ($row) = @_;
+ my %RowData;
+# my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
+ my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
+ my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
+ my $submission = $row->[&Apache::loncoursedata::RD_submission()];
+ my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
+# my $tries = $row->[&Apache::loncoursedata::RD_tries()];
+ return undef if ($award eq 'MISSING_ANSWER');
+ if (&submission_is_correct($award)) {
+ $RowData{'_correct'} = 1;
+ }
+ $RowData{'_total'} = 1;
+ my @Foilgrades = split('&',$grading);
+ my @Foilsubs = split('&',$submission);
+ for (my $j=0;$j<=$#Foilgrades;$j++) {
+ my ($foilid,$correct) = split('=',$Foilgrades[$j]);
+ $foilid = &unescape($foilid);
+ my (undef,$submission) = split('=',$Foilsubs[$j]);
+ if ($correct) {
+ $RowData{$foilid}->{'_correct'}++;
+ } else {
+ $submission = &unescape($submission);
+ $RowData{$foilid}->{$submission}++;
}
+ $RowData{$foilid}->{'_total'}++;
+ }
+ return %RowData;
+}
+
+sub submission_is_correct {
+ my ($award) = @_;
+ if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
+ return 1;
+ } else {
+ return 0;
}
- return %Partdata;
}
1;