--- loncom/interface/statistics/lonproblemanalysis.pm 2002/11/22 03:46:57 1.11
+++ loncom/interface/statistics/lonproblemanalysis.pm 2004/10/15 16:50:30 1.94
@@ -1,7 +1,6 @@
# The LearningOnline Network with CAPA
-# (Publication Handler
#
-# $Id: lonproblemanalysis.pm,v 1.11 2002/11/22 03:46:57 minaeibi Exp $
+# $Id: lonproblemanalysis.pm,v 1.94 2004/10/15 16:50:30 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,635 +24,1856 @@
#
# http://www.lon-capa.org/
#
-# (Navigate problems for statistical reports
-# YEAR=2002
-# 5/12,7/26,9/7,11/22 Behrouz Minaei
-#
-###
-
package Apache::lonproblemanalysis;
use strict;
use Apache::lonnet();
+use Apache::loncommon();
use Apache::lonhtmlcommon();
-use GDBM_File;
-
-my $jr;
+use Apache::loncoursedata();
+use Apache::lonstatistics;
+use Apache::lonlocal;
+use Apache::lonstathelpers();
+use Apache::lonstudentsubmissions();
+use HTML::Entities();
+use Time::Local();
+use Spreadsheet::WriteExcel();
+
+my $plotcolors = ['#33ff00',
+ '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
+ '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
+ ];
+
+my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
+ text => 'Previous Problem' },
+ { name => 'ProblemAnalysis',
+ text => 'Analyze Problem Again' },
+ { name => 'NextProblemAnalysis',
+ text => 'Next Problem' },
+ { name => 'break'},
+ { name => 'SelectAnother',
+ text => 'Choose a different Problem' },
+ { name => 'ExcelOutput',
+ text => 'Produce Excel Output' });
sub BuildProblemAnalysisPage {
- my ($cacheDB, $r)=@_;
+ my ($r,$c)=@_;
+ #
+ my %Saveable_Parameters = ('Status' => 'scalar',
+ 'Section' => 'array',
+ 'NumPlots' => 'scalar',
+ 'AnalyzeOver' => 'scalar',
+ );
+ &Apache::loncommon::store_course_settings('problem_analysis',
+ \%Saveable_Parameters);
+ &Apache::loncommon::restore_course_settings('problem_analysis',
+ \%Saveable_Parameters);
+ #
+ &Apache::lonstatistics::PrepareClasslist();
+ #
+ $r->print(&CreateInterface());
+ #
+ my @Students = @Apache::lonstatistics::Students;
+ #
+ if (@Students < 1 && exists($ENV{'form.firstrun'})) {
+ $r->print('
There are no students in the sections 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'})) {
+ foreach my $button (@SubmitButtons) {
+ if ($button->{'name'} eq 'break') {
+ $r->print("
\n");
+ } else {
+ $r->print('{'text'}).'" />');
+ $r->print(' 'x5);
+ }
+ }
+ foreach my $html (@CacheButtonHTML) {
+ $r->print($html.(' 'x5));
+ }
+ #
+ $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;
+ }
+ #
+ # Store the current problem choice and send it out in the form
+ $ENV{'form.problemchoice'} =
+ &Apache::lonstathelpers::make_target_id($current_problem);
+ $r->print('');
+ #
+ if (! defined($current_problem->{'resource'})) {
+ $r->print('resource is undefined');
+ } else {
+ my $resource = $current_problem->{'resource'};
+ $r->print(''.$resource->{'title'}.'
');
+ $r->print(''.$resource->{'src'}.'
');
+ if ($ENV{'form.show_prob'} eq 'true') {
+ $r->print(&Apache::lonstathelpers::render_resource($resource));
+ }
+ $r->rflush();
+ my %Data = &Apache::lonstathelpers::get_problem_data
+ ($resource->{'src'});
+ my $problem_data = $Data{$current_problem->{'part'}.
+ '.'.
+ $current_problem->{'respid'}};
+ if ($current_problem->{'resptype'} eq 'option') {
+ &OptionResponseAnalysis($r,$current_problem,
+ $problem_data,
+ \@Students);
+ } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
+ &RadioResponseAnalysis($r,$current_problem,
+ $problem_data,
+ \@Students);
+ } elsif ($current_problem->{'resptype'} eq 'numerical') {
+ ##
+ ## analyze all responses of a problem at once
+ my $res = $current_problem->{'resource'};
+ foreach my $partid (@{$res->{'parts'}}) {
+ $current_problem->{'part'} = $partid;
+ foreach my $respid (@{$res->{'partdata'}->{$partid}->{'ResponseIds'}}) {
+ $current_problem->{'respid'}=$respid;
+ &NumericalResponseAnalysis($r,$current_problem,
+ $problem_data,\@Students);
+ }
+ }
+ } else {
+ $r->print('This analysis is not supported
');
+ }
+ }
+ $r->print('
');
+ } else {
+ $r->print('');
+ $r->print(' 'x5);
+ $r->print(''.&mt('Please select a problem to analyze').'
');
+ $r->print(&Apache::lonstathelpers::ProblemSelector
+ ($problem_types));
+ }
+}
- my %cache;
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $r->print('Unable to tie database.');
+
+#########################################################
+#########################################################
+##
+## Numerical Response Routines
+##
+#########################################################
+#########################################################
+sub NumericalResponseAnalysis {
+ my ($r,$problem,$problem_data,$Students) = @_;
+ my $c = $r->connection();
+ my ($resource,$partid,$respid) = ($problem->{'resource'},
+ $problem->{'part'},
+ $problem->{'respid'});
+ #
+ if (scalar(@{$resource->{'parts'}})>1) {
+ if (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
+ $r->print(''.
+ &mt('Part [_1], response [_2].',$partid,$respid).
+ '
');
+ } else {
+ $r->print(''.
+ &mt('Part [_1]',$partid,$respid).
+ '
');
+ }
+ } elsif (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
+ $r->print(''.&mt('Response [_1]',$respid).'
');
+ }
+ #
+ 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;
}
+ #
+ # 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 $Ptr = '';
- $Ptr .= '';
- $Ptr .= 'Select Sections';
- $Ptr .= ' | '."\n";
- $Ptr .= ''."\n";
- my @sectionsSelected = split(':',$cache{'sectionsSelected'});
- my @sections = split(':',$cache{'sectionList'});
- $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
- \@sectionsSelected,
- 'Statistics');
- $Ptr .= ' |
'."\n";
- $Ptr .= 'Intervals | '."\n";
- $Ptr .= '';
- $Ptr .= &IntervalOptions($cache{'Interval'});
- $Ptr .= ' |
';
- $r->print($Ptr);
- $r->rflush();
- $r->print(&OptionResponseTable($cache{'OptionResponses'}, \%cache, $r));
+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);
+ }
+ #
+ # 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;
+}
- untie(%cache);
+##
+## Helper subroutines for .
+## These should probably go somewhere more suitable soon.
+sub line {
+ my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
+ return qq{$/};
+}
- return;
+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 BuildAnalyzePage {
- my ($cacheDB, $students, $courseID,$r)=@_;
+sub rectangle {
+ my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
+ return qq{};
+}
- $jr = $r;
- my $c = $r->connection;
+sub arc {
+ my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
+ return qq{};
+}
- my $Str = '';
- my %cache;
+sub circle {
+ my ($x,$y,$radius,$color,$thickness,$filled)=@_;
+ return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
+}
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $Str .= 'Unable to tie database.';
- $r->print($Str);
- 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;
+}
- # Remove students who don't have the proper section.
- my @sectionsSelected = split(':',$cache{'sectionsSelected'});
- for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
- $studentIndex--) {
- my $value = $cache{$students->[$studentIndex].':section'};
- my $found = 0;
- foreach (@sectionsSelected) {
- if($_ eq 'none') {
- if($value eq '' || !defined($value) || $value eq ' ') {
- $found = 1;
- last;
- }
+#########################################################
+#########################################################
+##
+## Radio Response Routines
+##
+#########################################################
+#########################################################
+sub RadioResponseAnalysis {
+ 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 $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').
+ '
';
+ $r->print($analysis_html);
+ return;
+ }
+ #
+ $analysis_html.='';
+ 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 {
- if($value eq $_) {
- $found = 1;
- last;
+ $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};
+
}
}
}
- if($found == 0) {
- splice(@$students, $studentIndex, 1);
+ }
+ #
+ # 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;
}
}
- unless(untie(%cache)) {
- $r->print('Can not untie hash.');
- $r->rflush();
+ #
+ # 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;
+}
- my $error =
- &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
- 'true',
- $cacheDB,
- 'true',
- 'true',
- $courseID,
- $r, $c);
- if($error ne 'OK') {
- $r->print($error.'
Error downloading course data
');
- return;
+
+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);
+}
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $Str .= 'Unable to tie database.';
- $r->print($Str);
- return;
+# 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;
+}
- my ($problemId, $part, $responseId)=split(':',$cache{'AnalyzeInfo'});
- my $uri = $cache{$problemId.':source'};
- my $problem = $cache{$problemId.':problem'};
- my $title = $cache{$problemId.':title'};
- my $interval = $cache{'Interval'};
-
- my %ConceptData;
- $ConceptData{"Interval"} = $interval;
-
- #Initialize the option response true answers
- my ($analyzeData) = &InitAnalysis($uri, $part, $responseId, $problem,
- $students->[0], $courseID);
- if(defined($analyzeData->{'error'})) {
- $Str .= $analyzeData->{'error'}.'
Incorrect part requested.
';
- $r->print($Str);
+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
- $r->print($Str);
- $Str = '';
- if($c->aborted()) { untie(%cache); return; }
-
- #compute the intervals
- &Interval($part, $problem, $interval, $analyzeData->{'concepts'},
- \%ConceptData);
-
- $title =~ s/\ /"_"/eg;
- $Str .= '
'.$uri.'';
-
- $r->print($Str);
- $Str = '';
- if($c->aborted()) { untie(%cache); return; }
-
- #Java script Progress window
- for(my $index=0; $index<(scalar @$students); $index++) {
- if($c->aborted()) { untie(%cache); return; }
- &OpStatus($problemId, $students->[$index], \%ConceptData,
- $analyzeData->{'foil_to_concept'}, $analyzeData,
- \%cache, $courseID);
- }
-
- $Str .= '
';
- for (my $k=0; $k<$interval; $k++ ) {
- if($c->aborted()) { untie(%cache); return $Str; }
- $Str .= &DrawGraph($k, $title, $analyzeData->{'concepts'},
- \%ConceptData);
- $r->print($Str);
- $Str = '';
- }
- for (my $k=0; $k<$interval; $k++ ) {
- if($c->aborted()) { untie(%cache); return $Str; }
- $Str .= &DrawTable($k, $analyzeData->{'concepts'}, \%ConceptData);
- $r->print($Str);
- $Str = '';
- }
- my $Answ=&Apache::lonnet::ssi($uri);
- $Str .= '
Here you can see the Problem:
'.$Answ;
- $Str .= '