');
}
-
- unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
- $Str .= 'Unable to tie database.';
- return $Str;
+ #
+ 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 ($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'};
+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;
+}
- my %ConceptData;
- $ConceptData{"Interval"} = $interval;
+##
+## Helper subroutines for .
+## These should probably go somewhere more suitable soon.
+sub line {
+ my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
+ return qq{$/};
+}
- #Initialize the option response true answers
- my ($analyzeData) = &InitAnalysis($uri, $part, $responseId, $problem,
- $students->[0], $courseID);
- if(defined($analyzeData->{'error'})) {
- $Str .= 'Incorrect part requested. ';
- return $Str;
+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};
+}
- if($c->aborted()) { untie(%cache); return $Str; }
+sub rectangle {
+ my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
+ return qq{};
+}
- #compute the intervals
- &Interval($part, $problem, $interval, $analyzeData->{'concepts'},
- \%ConceptData);
+sub arc {
+ my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
+ return qq{};
+}
- $title =~ s/\ /"_"/eg;
- $Str .= ' '.$uri.'';
+sub circle {
+ my ($x,$y,$radius,$color,$thickness,$filled)=@_;
+ return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
+}
- if($c->aborted()) { untie(%cache); return $Str; }
-
- #Java script Progress window
-# &Create_PrgWin();
-# &Update_PrgWin("Starting-to-analyze-problem");
- for(my $index=0; $index<(scalar @$students); $index++) {
- if($c->aborted()) { untie(%cache); return $Str; }
-# &Update_PrgWin($index);
-# &OpStatus($problem, $students->[$index], $courseID, \%ConceptData,
-# $analyzeData->{'foil_to_concept'}, $analyzeData, \%cache);
- &OpStatus($problem, $students->[$index], \%ConceptData,
- $analyzeData->{'foil_to_concept'}, $analyzeData, \%cache);
+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}]);
}
-# &Close_PrgWin();
+ return $worksheet;
+}
- $Str .= ' ';
- for (my $k=0; $k<$interval; $k++ ) {
- if($c->aborted()) { untie(%cache); return $Str; }
- $Str .= &DrawGraph($k, $title, $analyzeData->{'concepts'},
- \%ConceptData);
+#########################################################
+#########################################################
+##
+## Radio Response Routines
+##
+#########################################################
+#########################################################
+sub radio_response_analysis {
+ my ($r,$problem,$problem_analysis,$students) = @_;
+ #
+ if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
+ $r->print('Bad request');
+ }
+ #
+ 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);
+ #
+ my %true_foils;
+ my $num_true = 0;
+ if (! $problem_analysis->{'answercomputed'}) {
+ foreach my $foil (@$foils) {
+ if ($foildata->{$foil}->{'value'} eq 'true') {
+ $true_foils{$foil}++;
+ }
+ }
+ $num_true = scalar(keys(%true_foils));
}
- for (my $k=0; $k<$interval; $k++ ) {
- if($c->aborted()) { untie(%cache); return $Str; }
- $Str .= &DrawTable($k, $analyzeData->{'concepts'}, \%ConceptData);
+ #
+ $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'};
+ }
+ }
+ }
+ #
+ 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;
}
- my $Answ=&Apache::lonnet::ssi($uri);
- $Str .= ' Here you can see the Problem: '.$Answ;
+ #
+ $analysis_html.='
';
+ for (my $plot_num = 1;$plot_num<=$ENV{'form.NumPlots'};$plot_num++) {
+ # classify data ->correct foil -> selected foil
+ my ($restriction_function,
+ $correct_foil_title,$incorrect_foil_title,
+ $pre_graph_text,$post_graph_text,
+ $no_data_text,@extra_data);
+ if ($ENV{'form.AnalyzeOver'} eq 'tries') {
+ $restriction_function = sub {($_[0]->{'tries'} == $plot_num?1:0)};
+ $correct_foil_title = 'Attempt '.$plot_num;
+ $incorrect_foil_title = 'Attempt '.$plot_num;
+ $pre_graph_text =
+ 'Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect';
+ $post_graph_text = '';
+ $no_data_text = 'No data exists for attempt [_1]';
+ } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
+ my $starttime = &Apache::lonhtmlcommon::get_date_from_form
+ ('startdate_'.$plot_num);
+ my $endtime = &Apache::lonhtmlcommon::get_date_from_form
+ ('enddate_'.$plot_num);
+ ($starttime,$endtime) = &ensure_start_end_times
+ ($starttime,$endtime,
+ &get_time_from_row($response_data->[0]),
+ &get_time_from_row($response_data->[-1]),
+ $plot_num);
+ $pre_graph_text =
+ 'Data from [_5] to [_6], [_2] submissions, [_3] correct, [_4] incorrect';
+ $extra_data[0] = &Apache::lonlocal::locallocaltime($starttime);
+ $extra_data[1] = &Apache::lonlocal::locallocaltime($endtime);
+ #
+ $post_graph_text =
+ &mt('Start time: [_1]',
+ &Apache::lonhtmlcommon::date_setter
+ ('Statistics','startdate_'.$plot_num,$starttime)).
+ ' '.
+ &mt('End time: [_1]',
+ &Apache::lonhtmlcommon::date_setter
+ ('Statistics','enddate_'.$plot_num,$endtime));
+ $restriction_function =
+ sub {
+ my $t = $_[0]->{'timestamp'};
+ if ($t >= $starttime && $t < $endtime) {
+ return 1;
+ } else {
+ return 0;
+ }
+ };
+ $no_data_text = 'No data for [_5] to [_6]';
+ }
+ my $foil_choice_data =
+ &RR_classify_response_data($response_data,$correct,
+ $restriction_function);
+ # &Apache::lonstathelpers::log_hash_ref($foil_choice_data);
+ 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,
+ 'Correct Concepts');
+ }
+ # % Choosing plot
+ my $choice_plot = &RR_create_percent_selected_plot
+ ($concepts,$foils,$foil_choice_data,$correct_foil_title);
+ # for each correct foil, how did they mark it? (stacked bar graph)
+ my ($stacked_plot,$count_by_foil);
+ if ($problem_analysis->{'answercomputed'} || $num_true > 1) {
+ ($stacked_plot,$count_by_foil) =
+ &RR_create_stacked_selection_plot($foils,$foil_choice_data,
+ $incorrect_foil_title,
+ \%true_foils);
+ }
+ #
+ if ($concept_plot ne '' ||
+ $choice_plot ne '' ||
+ $stacked_plot ne '') {
+ my $correct = $foil_choice_data->{'_correct'};
+ if (! defined($correct) || $correct eq '') {
+ $correct = 0;
+ }
+ my $incorrect =
+ $analysis_html.= '